How mohanedzekry/angular-clean-architecture works
Project Type and Purpose
• This is a single-page Angular application implementing Clean Architecture principles.
• It uses NgRx for state management, PrimeNG for UI, and fp-ts for functional programming.
• Its primary domain revolves around “Test Takers”: adding, retrieving all, and retrieving by banner ID.
File Structure
• Top-level Angular files: angular.json, package.json, src/.
• src/app: Presentation layer (components, routing, NgModule).
• src/core: Shared base classes and error handling.
• src/domain: Business logic (entities, repository interfaces, use-cases).
• src/data: Data layer (DTO models, repository implementations, mappers).
• src/environments: Configuration for dev/prod.
• Tests and config files (karma.conf.js, tsconfigs).
Main Components
a. Presentation Layer
• Angular Components (e.g., AppComponent, feature components).
• NgRx Store: Actions, Reducers, Selectors, Effects.
• PrimeNG UI modules.
b. Domain Layer
• Entities (TestTaker).
• Repository Interfaces (ITestTakerRepository).
• Use-Cases (AddNewTestTaker, GetAllTestTakers, GetTestTakerByBannerId).
c. Data Layer
• Data Models (TestTakerModel).
• Repository Implementations (TestTakerRepositoryImpl).
• BaseMapper (maps between domain entities and data models).
• Angular HttpClient (calls to external REST API).
d. Core Layer
• BaseUseCase, BaseMapper, error classes and failure handling.
e. External Systems
• Remote REST API (backend service).
• Browser Storage or other external services, if any.
Relationships and Data Flow
• UI dispatches NgRx Actions → Effects intercept → call Domain Use-Cases.
• Use-Cases invoke methods on Domain Repository Interfaces.
• Data Layer provides concrete implementations:
• RepositoryImpl uses BaseMapper to convert Domain ↔ Data model.
• RepositoryImpl uses HttpClient to fetch/persist data in remote API.
• Responses propagate back: HttpClient → Model → Entity → Effect → NgRx Store → UI.
• Errors propagate via Core’s Failure/Exception classes.
Architectural Patterns and Design Principles
• Layered (Hexagonal/Clean) Architecture: Presentation → Domain → Data → Infrastructure.
• Dependency Inversion: Domain defines interfaces, Data layer implements them.
• Single Responsibility: Each folder/module has clear responsibility.
• Functional Programming for error handling via fp-ts.
Elements
• Notes on technologies: Angular CLI, PrimeNG, fp-ts, NgRx, HttpClient.
• Error handling path via Core’s Failure/Exception classes.