Frontend Architecture
The SGIVU frontend follows modern Angular best practices with a feature-based architecture, reactive state management using signals, and modular component design.Architectural Principles
1. Feature-Based Organization
The application is organized by features rather than technical layers:- Clear domain boundaries
- Easy to locate code
- Facilitates lazy loading
- Supports team scalability
2. Standalone Components
All components are standalone (no NgModule required):- Simplified module management
- Better tree-shaking
- More explicit dependencies
- Easier to understand component requirements
3. Signal-Based State Management
The application uses Angular Signals for reactive state:- Reactive by default
- Fine-grained reactivity
- Computed values
- Effects for side effects
- Better performance than observables for local state
4. Dependency Injection
Services use Angular’s dependency injection withinject() function:
- Cleaner constructor
- Testability
- Singleton services
- Lazy initialization
Application Structure
Core Configuration
app.config.ts
Central application configuration:- Zone.js change detection (prepared for zoneless)
- Router with lazy loading
- HTTP client with OAuth interceptor
- Chart.js integration
- Locale configuration (es-CO)
- App initializers for theme and authentication
app.routes.ts
Route-based lazy loading:- Lazy loading for code splitting
- Route guards for authentication and authorization
- Child routes for feature modules
- Redirect for default route
Feature Module Structure
Each feature follows a consistent structure:Shared Module
Shared code used across features:Components
Reusable UI components:- navbar - Top navigation bar
- sidebar - Side navigation menu
- data-table - Generic data table with sorting/filtering
- pager - Pagination component
- kpi-card - Dashboard KPI display
- page-header - Consistent page headers
- form-shell - Form wrapper with common functionality
- loading-overlay - Loading state indicator
- not-found - 404 page
- forbidden - 403 access denied page
- settings - User settings
- configuration - App configuration
Services
Shared business logic:- theme.service - Theme management (light/dark mode)
- confirm-action.service - Confirmation dialogs
- demand-prediction.service - ML-based demand predictions
- client-ui-helper.service - Client UI utilities
- user-ui-helper.service - User UI utilities
- vehicle-ui-helper.service - Vehicle UI utilities
Utilities
Helper functions:- form.utils - Form validation and manipulation
- date.utils - Date formatting and conversion
- currency.utils - Currency formatting (COP)
- error-handler.utils - Error handling and display
- filter-query.utils - URL query parameter building
- crud-operations.factory - Generic CRUD operations
- swal-alert.utils - SweetAlert2 wrappers
- address-form.utils - Address form management
- list-page-manager - List page state management
- vehicle-status-labels.utils - Vehicle status display
Directives
- has-permission - Conditional rendering based on permissions
- row-navigate - Navigate on table row click
Pipes
- cop-currency - Format numbers as Colombian Peso
- utc-to-gmt-minus5 - Convert UTC to Colombian timezone (GMT-5)
Models
Shared data models:- paginated-response - API pagination wrapper
- role.model - User role
- permission.model - User permission
- address.model - Address information
- demand-prediction.model - Prediction data
- form-config.model - Dynamic form configuration
Authentication Architecture
OAuth2/OIDC Flow
Authentication is delegated tosgivu-gateway:
Authentication Service
Key Responsibilities:- Initialize authentication state on app load
- Check session via
/auth/sessionendpoint - Store user and authentication state in signals
- Provide computed properties (e.g.,
isAdmin) - Handle login and logout flows
Route Guards
authGuard
Protects routes requiring authentication:permissionGuard
Protects routes requiring specific permissions:HTTP Interceptor
defaultOAuthInterceptor adds authentication to all API requests:State Management Patterns
Service-Based State
Features manage state in services using signals:Component State
Components use signals for local state:Change Detection Strategy
OnPush Strategy
All components useOnPush for optimal performance:
- Reduces change detection cycles
- Better performance
- Works seamlessly with signals
- Prepares for zoneless migration
Zoneless Migration Path
The app is prepared for zoneless change detection: Current State:- Most components use signals
- OnPush strategy everywhere
- ~20 mutable properties remaining
- Replace
provideZoneChangeDetection()withprovideZonelessChangeDetection() - Remove
zone.jsfromangular.jsonpolyfills - Uninstall zone.js:
npm uninstall zone.js - Convert remaining mutable properties to signals
HTTP Communication
Service Pattern
HTTP calls encapsulated in services:Error Handling
Centralized error handling:Form Management
Reactive Forms
All forms use reactive forms with validation:Form Utilities
Shared form helpers inshared/utils/form.utils.ts:
markFormGroupTouched()- Mark all fields as touchedgetFormValidationErrors()- Extract validation errorsresetForm()- Reset form statepatchFormValue()- Safe form patching
Performance Optimizations
Lazy Loading
Feature modules loaded on demand:- Reduces initial bundle size
- Faster initial page load
- Better user experience
Code Splitting
Automatic chunking by route:TrackBy Functions
Optimized list rendering:Image Optimization
Presigned URL uploads to S3:- Request presigned URL from backend
- Upload directly to S3
- Confirm upload with backend
- Display uploaded image
- No image data through backend
- Faster uploads
- Reduced server load
Next Steps
Features
Explore feature modules in detail
Setup
Setup development environment