7.3 KiB
Portal Architecture
This document outlines the new feature-driven architecture implemented for the customer portal.
Folder Structure
apps/portal/src/
├── app/ # Next.js App Router entry points (route groups only)
│ ├── (public)/ # Marketing + auth routes, pages import feature views
│ ├── (authenticated)/ # Signed-in portal routes, thin wrappers around features
│ ├── api/ # App Router API routes
│ ├── favicon.ico / globals.css # Global assets
│ └── layout.tsx # Root layout/providers
├── components/ # Shared UI components (design system atoms/molecules)
│ ├── ui/
│ ├── layout/
│ └── common/
├── core/ # App-wide configuration (env, logger, providers)
├── features/ # Feature-specific modules composed by routes
│ ├── account/
│ ├── auth/
│ ├── billing/
│ ├── catalog/
│ ├── dashboard/
│ ├── marketing/
│ ├── orders/
│ ├── service-management/
│ ├── subscriptions/
│ └── support/
├── shared/ # Cross-feature helpers (e.g., constants, locale data)
├── styles/ # Global styles and design tokens
└── types/ # Portal-specific TypeScript types
Design Principles
1. Feature-First Organization
Related functionality is grouped together in feature modules, making it easier to understand and maintain code.
2. Atomic Design
UI components are organized hierarchically:
- Atoms: Basic building blocks (Button, Input, etc.)
- Molecules: Combinations of atoms (SearchBar, DataTable, etc.)
- Organisms: Complex components (Layout, Header, etc.)
3. Separation of Concerns
Each feature module contains:
components/: UI components specific to the featurehooks/: React hooks for state and operationsservices/: Business logic and API callstypes/: TypeScript type definitionsutils/: Utility functions
4. Centralized Shared Resources
Common utilities, types, and components are centralized in the core/, shared/, and components/ directories.
Feature Module Structure
Each feature follows a consistent internal structure:
features/[feature-name]/
├── components/ # Feature-specific components
│ ├── [Component]/
│ │ ├── Component.tsx
│ │ ├── Component.test.tsx
│ │ └── index.ts
│ └── index.ts
├── hooks/ # Feature-specific hooks
│ ├── use[Feature].ts
│ └── index.ts
├── services/ # Feature business logic
│ ├── [feature].service.ts
│ └── index.ts
├── types/ # Feature-specific types
│ ├── [feature].types.ts
│ └── index.ts
├── utils/ # Feature utilities
└── index.ts # Feature public API
Design System
The design system is built with:
Design Tokens
- CSS custom properties for consistent theming
- TypeScript constants for type safety
- Semantic color and spacing systems
Component Library
- Reusable UI components following atomic design
- Consistent styling and behavior patterns
- Accessibility-first approach
Responsive Design
- Mobile-first responsive utilities
- Consistent breakpoint system
- Container queries for component-level responsiveness
TypeScript Configuration
Enhanced TypeScript configuration with:
- Strict type checking enabled
- Path mappings for clean imports
- Enhanced error detection
- Import/export validation
Import Patterns
Recommended Import Patterns
// Feature imports
import { LoginForm, useAuth } from "@/features/auth";
// Component imports
import { Button, Input } from "@/components/ui";
import { DataTable } from "@/components/common";
// Type imports
import type { User, ApiResponse } from "@/types";
// Utility imports
import { QueryProvider } from "@/core/providers";
// Prefer feature services/hooks over direct api usage in pages
import { logger } from "@/core/config";
Path Mappings
@/*- Root src directory@/components/*- Component library@/core/*- App-wide configuration and providers@/features/*- Feature modules@/shared/*- Shared helpers/constants@/styles/*- Style files@/types/*- Portal-specific types@shared/*- Shared package exports
Migration Strategy
The migration to this new architecture will be done incrementally:
- Foundation (Current): Set up folder structure and design system
- Core Components: Migrate base UI components
- Feature Modules: Migrate features one by one
- Optimization: Performance and bundle optimization
- Cleanup: Remove old code and dependencies
Benefits
Developer Experience
- Predictable code organization
- Easy to find and modify code
- Consistent patterns across features
- Better IntelliSense and type safety
Maintainability
- Clear separation of concerns
- Reusable components and utilities
- Centralized design system
- Easier testing and debugging
Performance
- Tree-shakeable exports
- Code splitting by feature
- Optimized bundle size
- Better caching strategies
Scalability
- Easy to add new features
- Consistent architecture patterns
- Modular and composable design
- Clear boundaries between features
Pages vs Features
- Route pages under
src/app/**are thin shells and do not call APIs directly. - Data fetching and business logic live in
src/features/**:services/: centralized feature services built on the sharedapiClienthooks/: React Query hooks that wrap services and expose typed operationscomponents/: feature UI composed from shared atoms/molecules/organisms
This ensures pages remain declarative and the feature layer encapsulates logic.
Route Layering
(public): marketing landing and authentication flows. These routes render feature views such asmarketing/PublicLandingViewandauthscreens while remaining server components by default.(authenticated): signed-in portal experience. Pages import dashboard, billing, subscriptions, etc. from the feature layer and rely on the shared route-group layout to provide navigation.api/: App Router API endpoints remain colocated undersrc/app/apiand can reuse feature services for data access.
Only layout.tsx, page.tsx, and loading.tsx files live inside the route groups. All reusable UI, hooks, and services live under src/features/** to keep routing concerns thin.
Current Feature Hooks/Services
- Catalog
- Hooks:
useInternetCatalog,useSimCatalog,useVpnCatalog,useProducts*,useCalculateOrder,useSubmitOrder - Service:
catalogService(internet/sim/vpn endpoints consolidated)
- Hooks:
- Billing
- Hooks:
useInvoices,usePaymentMethods,usePaymentGateways,usePaymentRefresh - Service:
BillingService
- Hooks:
- Orders
- Service:
ordersService(list/detail/create)
- Service:
- Account
- Service:
accountService(/me/address)
- Service:
- Support
- Views:
SupportCasesView,NewSupportCaseView(mock data, ready for API wiring)
- Views:
- Marketing
- Views:
PublicLandingView,PublicLandingLoadingView
- Views: