# yasblha/cleancode architecture

> Architecture diagram of the GitHub repository yasblha/cleancode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yasblha/cleancode
- Repository: https://github.com/yasblha/cleancode

## Overview

##### Project Type & Purpose
- This is a full-stack fleet-management application (“CleanCode”) for motorcycles.
- Backend follows Clean Architecture (Domain, Application, Infrastructure) with two interchangeable platforms (Express.js and NestJS) exposing RESTful APIs.
- Frontend is built in React/Next.js; it consumes the backend APIs to manage bikes, maintenance, parts, incidents, and driver trials.
- Data stores: PostgreSQL (via Sequelize) and MongoDB (via Mongoose) under Infrastructure.

##### Key Layers & Directories
- Domain: core entities (Bikes, Incidents, Parts, Users, Company, Alerts), value-objects (e.g. VIN), repository interfaces, domain errors.
- Application: business logic encapsulated in UseCases and Services (AuthenticationService, PasswordService). UseCases implement CRUD and search flows per aggregate.
- Infrastructure:
- Repositories & adapters to MongoDB and Sequelize (Postgres).
- Platform folders under `infrastructure/plateforms/Backend/express` and `/nest` containing controllers, routes, adapters (bcrypt, JWT), modules, Dtos.
- Frontend under `infrastructure/plateforms/frontend/front-react`.
- DevOps: Dockerfiles, docker-compose for multi-container orchestration, environment configs.

##### Main Components
- Frontend (Next.js/React SPA)
- API Gateways (Express server OR NestJS server)
- Application Layer (UseCases & Services)
- Domain Layer (Entities, Value Objects, Domain Interfaces)
- Infrastructure Layer:
- Persistence adapters (Sequelize → PostgreSQL; Mongoose → MongoDB)
- External service adapters (bcrypt, JWT)
- Datastores: PostgreSQL instance, MongoDB instance
- DevOps: Docker (containers), Docker-Compose network

##### Relationships & Data Flow
- User → Frontend (UI components, pages)
- Frontend → REST API (Express/NestJS controllers & routes)
- Controllers invoke Application UseCases → Domain entities & rules
- UseCases call Repository interfaces → concrete Infrastructure adapters
- Repositories → read/write to PostgreSQL or MongoDB
- Authentication flow: User submits credentials → AuthController → AuthVerifyUseCase → AuthenticationService → JWT adapter → signed token
- Error flows: DomainErrors propagate up to controllers via HTTP-error interceptors/middleware.

##### Architectural Patterns & Principles
- Clean Architecture: clear dependency rule—outer layers depend on inner layers only via interfaces.
- Layered hexagonal style: inbound adapters (HTTP controllers), outbound adapters (DB, auth providers), application core isolated.
- Modular feature branches (auth, bikes, maintenance, parts, trials).
- DI (Dependency Injection) in NestJS; hand-wired factories in Express.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    Frontend["Next.js/React SPA"]:::frontend
    click Frontend "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/frontend/front-react"

    %% API Gateways
    subgraph "API Gateways"
        subgraph "Express Platform"
            ExpressServer["Express Server"]:::api
            Controllers["Controllers"]:::api
            Routes["Routes"]:::api
            IndexExpress["index.ts"]:::api
        end
        subgraph "NestJS Platform"
            NestServer["NestJS Server"]:::api
            ModulesControllers["Modules & Controllers"]:::api
            MainNest["main.ts"]:::api
        end
    end
    click Controllers "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/Backend/express/src/controllers"
    click Routes "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/Backend/express/src/routes"
    click IndexExpress "https://github.com/yasblha/cleancode/blob/Develop-ys/infrastructure/plateforms/Backend/express/src/index.ts"
    click ModulesControllers "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/Backend/nest/src"
    click MainNest "https://github.com/yasblha/cleancode/blob/Develop-ys/infrastructure/plateforms/Backend/nest/src/main.ts"

    %% Application Layer
    subgraph "Application Layer"
        UseCases["UseCases (CRUD & Search)"]:::app
        Services["AuthenticationService & PasswordService"]:::app
    end
    click UseCases "https://github.com/yasblha/cleancode/tree/Develop-ys/application/useCases"
    click Services "https://github.com/yasblha/cleancode/blob/Develop-ys/application/services/AuthenticationService.ts"
    click Services "https://github.com/yasblha/cleancode/blob/Develop-ys/application/services/PasswordService.ts"

    %% Domain Layer
    subgraph "Domain Layer"
        Entities["Entities"]:::domain
        ValueObjects["Value Objects"]:::domain
        RepoInterfaces["Repository Interfaces"]:::domain
        DomainErrors["Domain Errors"]:::domain
    end
    click Entities "https://github.com/yasblha/cleancode/tree/Develop-ys/domain/entities"
    click ValueObjects "https://github.com/yasblha/cleancode/blob/Develop-ys/domain/value-objects/Vinidentifier.ts"
    click RepoInterfaces "https://github.com/yasblha/cleancode/tree/Develop-ys/domain/repositories"
    click DomainErrors "https://github.com/yasblha/cleancode/tree/Develop-ys/domain/errors"

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        subgraph "Persistence Adapters"
            SequelizeAdapter["Sequelize Adapter"]:::infra
            MongooseAdapter["Mongoose Adapter"]:::infra
        end
        subgraph "External Auth Adapters"
            BcryptAdapter["Bcrypt Adapter"]:::infra
            JWTAdapter["JWT Adapter"]:::infra
        end
    end
    click SequelizeAdapter "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/sequelize/models"
    click SequelizeAdapter "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/sequelize/repositories"
    click MongooseAdapter "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/mongo/models"
    click MongooseAdapter "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/mongo/repositories"
    click BcryptAdapter "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/Backend/express/src/adapters"
    click JWTAdapter "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/Backend/nest/src/adapters"

    %% Datastores
    Postgres["PostgreSQL"]:::db
    Mongo["MongoDB"]:::db

    %% DevOps / Containerization
    subgraph "DevOps"
        DockerCompose["docker-compose.yml"]:::devops
        DockerfileExpress["Express Dockerfile"]:::devops
        DockerfileNest["NestJS Dockerfile"]:::devops
        DockerfileFrontend["Frontend Dockerfile"]:::devops
    end
    click DockerCompose "https://github.com/yasblha/cleancode/blob/Develop-ys/docker-compose.yml"
    click DockerfileExpress "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/Backend/express/dockerfile"
    click DockerfileNest "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/Backend/nest/dockerfile"
    click DockerfileFrontend "https://github.com/yasblha/cleancode/tree/Develop-ys/infrastructure/plateforms/frontend/front-react/dockerfile"

    %% Relationships
    Frontend -->|REST API| ExpressServer
    Frontend -->|REST API| NestServer
    ExpressServer --> Controllers
    ExpressServer --> Routes
    Routes --> UseCases
    Controllers --> UseCases
    NestServer --> ModulesControllers
    ModulesControllers --> UseCases
    UseCases --> Services
    UseCases --> RepoInterfaces
    RepoInterfaces --> SequelizeAdapter
    RepoInterfaces --> MongooseAdapter
    SequelizeAdapter --> Postgres
    MongooseAdapter --> Mongo
    Services --> BcryptAdapter
    Services --> JWTAdapter

    classDef frontend fill:#D0E7FF,stroke:#333,stroke-width:1px
    classDef api fill:#D0FFD8,stroke:#333,stroke-width:1px
    classDef app fill:#FFF4C2,stroke:#333,stroke-width:1px
    classDef domain fill:#FFE4B3,stroke:#333,stroke-width:1px
    classDef infra fill:#E5D3FF,stroke:#333,stroke-width:1px
    classDef db fill:#B0B0B0,stroke:#333,stroke-width:1px
    classDef devops fill:#BDE5E7,stroke:#333,stroke-width:1px
```
