# maxmillernunes/rentx architecture

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

- Interactive diagram: https://gitdiagram.com/maxmillernunes/rentx
- Repository: https://github.com/maxmillernunes/rentx

## Overview

##### Project type and purpose
- This is a backend-only REST API service for car rentals, built with Express, TypeORM, and a set of “modules” (accounts, cars, rentals).
- It follows Clean/Hexagonal principles: each module has domain DTOs, Use Cases, Repositories (interfaces and Infra implementations), Controllers, and Entities.

##### File structure
- Top-level “src/shared/infra/http” contains the Express server (`server.ts`), middleware, and route definitions.
- Each feature lives under `src/modules/<feature>` with subfolders for DTOs, useCases, infra (TypeORM entities & repos), etc.
- `src/shared/container` holds dependency-injection bindings for providers (Mail, Storage, Date).
- Config files show external dependencies: `ormconfig*.json` (PostgreSQL via TypeORM), Redis config, upload (multer), mail providers, Docker and docker-compose.

##### Key README insights
- Business rules for user authentication, car management, rental lifecycle, password reset.
- No frontend here; this service exposes endpoints for these features.

##### Main components
A. Clients
– Mobile App or Web SPA (HTTP/JSON over REST)
B. API Service (monolithic)
1. HTTP Layer
- Express server (`shared/infra/server.ts`)
- Middlewares: rateLimiter, ensureAuthenticated, ensureAdmin, error handlers
2. Routing Layer
- Route files: authenticate.routes, cars.routes, categories.routes, rental.routes, users.routes, etc.
3. Controllers
- One controller per Use Case (e.g. CreateCarController)
4. Application/Domain Layer
- Use Cases: each implements business logic (e.g. CreateRentalUseCase)
- DTOs & Mappers (e.g. ICreateUserDTO, UserMap)
5. Infrastructure Adapters
a. Repositories
– Interfaces (`IUsersRepository`, `ICarsRepository`, etc.)
– TypeORM implementations (entities + `*Repository` classes)
– In-Memory implementations (for tests)
b. Providers
– MailProvider (Ethereal, SES, SendGrid)
– StorageProvider (Local, S3)
– DateProvider (DayJs)
c. External Services
– PostgreSQL (via TypeORM)
– Redis (for rate-limiting or token blacklisting)
– SMTP/SES/SendGrid
– S3 (for car images)
C. Data stores & external systems
– PostgreSQL database
– Redis cache
– S3 bucket (object storage)
– Email service (SES/SendGrid/Ethereal)

##### Relationships and data flows
- Client → HTTP Layer (Express) → Routing → Controller → Use Case
- Use Case → Repository interface → TypeORM Repository → PostgreSQL
- Use Case → Provider interface → Provider implementation → External system (e.g. S3, Mail API, Redis)
- Middleware intercepts Client→Server calls for auth, rate-limiting, error handling.

##### Architectural patterns & design principles
- Clean (Hexagonal) Architecture: separation of concerns between layers (HTTP adapters, controllers, use cases, repositories, providers)
- Dependency Injection: all external services (DB, mail, storage, date) injected at runtime via `shared/container`
- Repository Pattern: domain-agnostic interfaces with multiple implementations (TypeORM vs InMemory)
- Provider Pattern / Strategy Pattern for mail, storage, date.

##### Final checklist
[ ] All major components and layers represented
[ ] External systems and protocols shown
[ ] Note Clean Architecture boundaries (hexagon or ring view if desired)
[ ] Highlight dependency injection bindings (`shared/container`)

## Diagram (Mermaid)

```mermaid
graph TB
    Clients["Mobile App / Web SPA"]:::external

    subgraph "HTTP Adapters"
        Server["Express Server"]:::adapter
        App["Express App"]:::adapter
        ML["rateLimiter"]:::adapter
        AuthG["ensureAuthenticated"]:::adapter
        AdminG["ensureAdmin"]:::adapter
        ErrH["verifyError"]:::adapter
        subgraph "Routes"
            AuthR["authenticate.routes"]:::adapter
            UsersR["users.routes"]:::adapter
            CategoriesR["categories.routes"]:::adapter
            SpecsR["specification.routes"]:::adapter
            CarsR["cars.routes"]:::adapter
            RentalR["rental.routes"]:::adapter
            PasswordR["password.routes"]:::adapter
            IndexR["index.ts"]:::adapter
        end
    end

    subgraph "API Core"
        Controllers["Controllers"]:::adapter
        UseCases["Use Cases"]:::domain
        DTOs["DTOs & Mappers"]:::domain
    end

    subgraph "Infrastructure Adapters"
        subgraph "Repositories"
            UsersRepo["UsersRepository (TypeORM)"]:::infrastructure
            CarsRepo["CarsRepository (TypeORM)"]:::infrastructure
            RentalsRepo["RentalsRepository (TypeORM)"]:::infrastructure
        end
        subgraph "Providers"
            DateProv["DayJsDateProvider"]:::infrastructure
            MailProv["EtherealMailProvider"]:::infrastructure
            StorageProv["LocalStorageProvider"]:::infrastructure
        end
        Container["DI Container"]:::infrastructure
    end

    subgraph "External Systems"
        Postgres["PostgreSQL"]:::external
        Redis["Redis"]:::external
        S3["S3 Bucket"]:::external
        EmailSvc["Email Service"]:::external
    end

    Clients -->|"HTTP/JSON"| Server
    Server --> App
    App --> ML
    App --> AuthG
    App --> AdminG
    App --> ErrH
    App --> IndexR

    IndexR --> AuthR
    IndexR --> UsersR
    IndexR --> CategoriesR
    IndexR --> SpecsR
    IndexR --> CarsR
    IndexR --> RentalR
    IndexR --> PasswordR

    AuthR --> Controllers
    UsersR --> Controllers
    CategoriesR --> Controllers
    SpecsR --> Controllers
    CarsR --> Controllers
    RentalR --> Controllers
    PasswordR --> Controllers

    Controllers --> UseCases
    UseCases --> UsersRepo
    UseCases --> CarsRepo
    UseCases --> RentalsRepo
    UseCases --> DateProv
    UseCases --> MailProv
    UseCases --> StorageProv

    UsersRepo --> Postgres
    CarsRepo --> Postgres
    RentalsRepo --> Postgres

    MailProv --> EmailSvc
    StorageProv --> S3

    Container --> UseCases
    Container --> UsersRepo
    Container --> CarsRepo
    Container --> RentalsRepo
    Container --> DateProv
    Container --> MailProv
    Container --> StorageProv

    click Server "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/server.ts"
    click App "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/app.ts"
    click ML "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/middlewares/rateLimiter.ts"
    click AuthG "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/middlewares/ensureAuthenticated.ts"
    click AdminG "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/middlewares/ensureAdmin.ts"
    click ErrH "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/middlewares/verifyError.ts"
    click AuthR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/authenticate.routes.ts"
    click UsersR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/users.routes.ts"
    click CategoriesR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/categories.routes.ts"
    click SpecsR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/specification.routes.ts"
    click CarsR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/cars.routes.ts"
    click RentalR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/rental.routes.ts"
    click PasswordR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/password.routes.ts"
    click IndexR "https://github.com/maxmillernunes/rentx/blob/main/src/shared/infra/http/routes/index.ts"
    click Container "https://github.com/maxmillernunes/rentx/blob/main/src/shared/container/index.ts"
    click DateProv "https://github.com/maxmillernunes/rentx/blob/main/src/shared/container/providers/DateProvider/implementations/DayJsDateProvider.ts"
    click MailProv "https://github.com/maxmillernunes/rentx/blob/main/src/shared/container/providers/MailProvider/implementations/EtherealMailProvider.ts"
    click StorageProv "https://github.com/maxmillernunes/rentx/blob/main/src/shared/container/providers/StorageProvider/implementations/LocalStorageProvider.ts"
    click UsersRepo "https://github.com/maxmillernunes/rentx/blob/main/src/modules/accounts/infra/typeorm/repositories/UsersRepository.ts"
    click CarsRepo "https://github.com/maxmillernunes/rentx/blob/main/src/modules/cars/infra/typeorm/repositories/CarsRepository.ts"
    click RentalsRepo "https://github.com/maxmillernunes/rentx/blob/main/src/modules/rentals/infra/typeorm/repositories/RentalsRepository.ts"

    classDef external fill:#BBE1FA,stroke:#000;
    classDef infrastructure fill:#B2F2BB,stroke:#000;
    classDef adapter fill:#FFD8A8,stroke:#000;
    classDef domain fill:#FFC9DE,stroke:#000;
```
