How yasblha/cleancode works
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.