# mohanedzekry/angular-clean-architecture architecture

> Architecture diagram of the GitHub repository mohanedzekry/angular-clean-architecture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohanedzekry/angular-clean-architecture
- Repository: https://github.com/mohanedzekry/angular-clean-architecture

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        AM["AppModule"]:::presentation
        AC["AppComponent"]:::presentation
        HTML["AppComponent Template"]:::presentation
        AR["AppRoutingModule"]:::presentation
        NgRxActions["NgRx Actions"]:::presentation
        NgRxReducers["NgRx Reducers"]:::presentation
        NgRxSelectors["NgRx Selectors"]:::presentation
        NgRxEffects["NgRx Effects"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Entity["TestTaker Entity"]:::domain
        Interface["ITestTakerRepository Interface"]:::domain
        AddUC["AddNewTestTaker Use-Case"]:::domain
        GetAllUC["GetAllTestTakers Use-Case"]:::domain
        GetByIdUC["GetTestTakerByBannerId Use-Case"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Model["TestTakerModel"]:::data
        RepoImpl["TestTakerRepositoryImpl"]:::data
        HttpClient["Angular HttpClient"]:::data
        EnvDev["environment.ts"]:::data
        EnvProd["environment.prod.ts"]:::data
    end

    %% Core Utilities
    subgraph "Core Utilities"
        direction TB
        BaseMapper["BaseMapper"]:::core
        BaseUseCase["BaseUseCase"]:::core
        Exceptions["Exceptions"]:::core
        Failure["Failure"]:::core
    end

    %% External Systems
    ExternalAPI["Remote REST API"]:::external

    %% Presentation Connections
    AM --> AC
    AC --> HTML
    AC --> NgRxActions
    AC --> NgRxReducers
    AC --> NgRxSelectors
    NgRxActions --> NgRxEffects

    %% Flow from UI to Domain
    NgRxEffects --> AddUC
    NgRxEffects --> GetAllUC
    NgRxEffects --> GetByIdUC

    %% Domain to Data
    AddUC --> Interface
    GetAllUC --> Interface
    GetByIdUC --> Interface

    Interface --> RepoImpl
    RepoImpl --> BaseMapper
    BaseMapper --> Model
    RepoImpl --> HttpClient
    HttpClient --> EnvDev
    HttpClient --> EnvProd
    HttpClient --> ExternalAPI

    %% Response Flow
    ExternalAPI -- "Response" --> HttpClient
    HttpClient -- "Data" --> RepoImpl
    RepoImpl -- "Entity" --> AddUC
    RepoImpl -- "EntityList" --> GetAllUC
    RepoImpl -- "Entity" --> GetByIdUC

    %% Error Handling
    HttpClient -- "Error" --> Exceptions
    Exceptions --> Failure
    Failure --> NgRxEffects

    %% Click Events
    click AM "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/app/app.module.ts"
    click AC "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/app/app.component.ts"
    click HTML "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/app/app.component.html"
    click AR "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/app/app-routing.module.ts"
    click Entity "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/domain/entities/test-taker.ts"
    click Interface "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/domain/repositories/test-taker-repositories.ts"
    click AddUC "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/domain/use-cases/add-new-test-taker-use-case.ts"
    click GetAllUC "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/domain/use-cases/get-all-test-takers-use-case.ts"
    click GetByIdUC "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/domain/use-cases/get-test-taker-by-banner-id-use-case.ts"
    click Model "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/data/models/test-taker-model.ts"
    click RepoImpl "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/data/repositories/test-taker-repository-impl.ts"
    click BaseMapper "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/core/base-mapper.ts"
    click BaseUseCase "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/core/base-use-case.ts"
    click Exceptions "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/core/error/exceptions.ts"
    click Failure "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/core/error/failure.ts"
    click EnvDev "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/environments/environment.ts"
    click EnvProd "https://github.com/mohanedzekry/angular-clean-architecture/blob/master/src/environments/environment.prod.ts"

    %% Styles
    classDef presentation fill:#D0E6FF,stroke:#0366D6,color:#0366D6,stroke-width:1px
    classDef domain fill:#E6F4EA,stroke:#1B7A1B,color:#1B7A1B,stroke-width:1px
    classDef data fill:#FFF4E6,stroke:#D97706,color:#D97706,stroke-width:1px
    classDef core fill:#F0F0F0,stroke:#6B7280,color:#6B7280,stroke-width:1px
    classDef external fill:#FFE6E6,stroke:#DC2626,color:#DC2626,stroke-width:1px
```
