# tyri0n11/web-app-car-rental-service architecture

> Architecture diagram of the GitHub repository tyri0n11/web-app-car-rental-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tyri0n11/web-app-car-rental-service
- Repository: https://github.com/tyri0n11/web-app-car-rental-service

## Overview

##### Project Type and Purpose
- This is a full-stack Car Rental Service web application.
- Frontend: a React (TypeScript) SPA built with Vite, React Router, Tailwind CSS, Material UI, Context API, Axios.
- Backend: a monolithic NestJS service structured into modules (Auth, User, Car, Booking, Payment, Review, etc.), using Prisma ORM over PostgreSQL, Redis caching, BullMQ job queues, Cloudinary file storage, Nodemailer email service, Swagger API docs, and Winston logging.

##### Main Components
a. Frontend Client
- Browser application (SPA)
- Context providers (AuthContext, BookingContext, CarContext, etc.)
- API layer (services under client/src/apis) communicating via Axios to backend REST endpoints
- UI components (buttons, cards, modals, pages, filters, layouts) organized per feature (home, car, booking, admin dashboard, profile, auth)
- Routing (PublicRoutes, ProtectedRoutes, AdminRoutes)

b. Backend API
- NestJS application (`server/src`)
- Modules: Auth, User, Car, Category, Booking, Payment, Review, Transaction, Activity, Dashboard, Image, Email, Database
- Controllers (handling HTTP routes) → Services (business logic) → Prisma (data persistence)
- Guards (JWT, roles, resource ownership) for authentication & authorization
- Interceptors & Filters for response formatting & exception handling
- Middleware (e.g., logger)

c. Data Stores & Infrastructure
- PostgreSQL (primary relational database)
- Redis (cache for sessions, rate-limiting, job queue backend)
- BullMQ job queue (workers: processTransaction, unlockCar)
- Cloudinary (file storage for images)
- SMTP email service (Nodemailer)
- Docker & Docker Compose (containerization)

##### Component Relationships & Data Flow
1. The browser issues HTTP(S) requests to the NestJS API (e.g., user sign-in, fetch car list, create booking).
2. API Controllers receive requests → apply Guards → pass to Services.
3. Services interact with Prisma to read/write PostgreSQL data.
4. For heavy-lifting tasks (e.g., transaction processing, unlocking cars), Services enqueue jobs into BullMQ (backed by Redis).
5. Dedicated Worker processes pick up jobs from the queue, execute business logic, update DB, and may call external services (email, Cloudinary).
6. Services use Redis for caching frequently accessed data (e.g., categories, car lists) and session state.
7. File uploads go from client → Cloudinary (via backend proxy).
8. Email notifications (verification, booking confirmation) go via Nodemailer/SMTP.

##### Architectural Patterns & Design Principles
- Frontend: Component-based architecture, Single Responsibility (each component handles one UI concern), Context API for shared state, service layer (API wrappers).
- Backend: Modular monolith (one NestJS app split into feature modules), Controller–Service–Repository pattern, DTOs for input validation, Guards for cross-cutting security, Interceptors/Filters for response and error management, Decorators for code reuse.
- Infrastructure: Twelve-factor app (config via env vars), containerization, job queue for asynchronous processing, caching layer, centralized logging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend: React SPA (Vite)" 
        direction TB
        Contexts["Context Providers"]:::frontend
        APIs["API Service Layer"]:::frontend
        UI["UI Components"]:::frontend
        Router["Routing"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend: NestJS API"
        direction TB
        Modules["Feature Modules"]:::backend
        CrossCut["Guards, Interceptors, Middleware"]:::backend
    end

    subgraph "Feature Modules"
        direction TB
        AuthModule["Auth Module"]:::backend
        UserModule["User Module"]:::backend
        CarModule["Car Module"]:::backend
        CategoryModule["Category Module"]:::backend
        BookingModule["Booking Module"]:::backend
        PaymentModule["Payment Module"]:::backend
        ReviewModule["Review Module"]:::backend
        TransactionModule["Transaction Module"]:::backend
        ActivityModule["Activity Module"]:::backend
        DashboardModule["Dashboard Module"]:::backend
        ImageModule["Image Module"]:::backend
        EmailModule["Email Module"]:::backend
        DatabaseModule["Database Module"]:::backend
    end

    %% Workers Layer
    subgraph "Workers"
        direction TB
        ProcessTxn["processTransaction.worker"]:::backend
        UnlockCar["unlockCar.worker"]:::backend
    end

    %% Data & Infra Layer
    subgraph "Data Stores & Infra"
        direction TB
        Postgres["PostgreSQL\n(Prisma ORM)"]:::datastore
        Redis["Redis\n(Cache & BullMQ Backend)"]:::datastore
        Bull["BullMQ Queue"]:::datastore
        Cloudinary["Cloudinary\n(Image Storage)"]:::external
        SMTP["SMTP Email Service"]:::external
    end

    %% DevOps Layer
    subgraph "DevOps: Docker Compose"
        direction TB
        APIContainer["API Container"]:::infra
        PGContainer["Postgres Container"]:::infra
        RedisContainer["Redis Container"]:::infra
        WorkerContainer["Worker Container"]:::infra
    end

    %% Connections
    Contexts -->|uses| APIs
    UI -->|calls| APIs
    Router -->|routes to| UI
    APIs -->|HTTP/HTTPS| AuthModule
    APIs -->|HTTP/HTTPS| UserModule
    APIs -->|HTTP/HTTPS| CarModule
    APIs -->|HTTP/HTTPS| BookingModule
    APIs -->|HTTP/HTTPS| PaymentModule
    APIs -->|HTTP/HTTPS| ReviewModule

    AuthModule -->|calls| Services[(Services)]:::backend
    UserModule -->|calls| Services
    CarModule -->|calls| Services
    BookingModule -->|calls| Services
    PaymentModule -->|calls| Services
    ReviewModule -->|calls| Services

    Services -->|uses| DatabaseModule
    Services -->|caches| Redis
    Services -->|enqueues| Bull
    Bull -->|processed by| ProcessTxn
    Bull -->|processed by| UnlockCar
    ProcessTxn -->|updates| Postgres
    UnlockCar -->|updates| Postgres

    Services -->|uploads| Cloudinary
    Services -->|sends| SMTP

    DatabaseModule -->|manages| Postgres

    CrossCut -->|applies to| AuthModule
    CrossCut -->|applies to| UserModule
    CrossCut -->|applies to| CarModule
    CrossCut -->|applies to| BookingModule

    %% DevOps connections
    APIContainer -->|hosts| AuthModule
    APIContainer -->|hosts| UserModule
    APIContainer -->|hosts| CarModule
    PGContainer -->|runs| Postgres
    RedisContainer -->|runs| Redis
    WorkerContainer -->|runs| ProcessTxn
    WorkerContainer -->|runs| UnlockCar

    %% Click Events - Frontend
    click Contexts "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/contexts/AuthContext.tsx"
    click Contexts "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/contexts/BookingContext.tsx"
    click Contexts "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/contexts/CarContext.tsx"
    click Contexts "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/contexts/CategoryContext.tsx"
    click Contexts "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/contexts/NotificationContext.tsx"
    click Contexts "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/contexts/ReviewContext.tsx"
    click Contexts "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/contexts/UserContext.tsx"
    click APIs "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/apis/auth.ts"
    click APIs "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/apis/booking.ts"
    click APIs "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/apis/car.ts"
    click APIs "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/apis/category.ts"
    click APIs "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/apis/dashboard.ts"
    click APIs "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/apis/review.ts"
    click APIs "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/apis/user.ts"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/buttons"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/cards"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/filters"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/layout"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/modals"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/pages"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/menu"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/paginations"
    click UI "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/client/src/components/common"
    click Router "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/routes/PublicRoutes.tsx"
    click Router "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/routes/ProtectedRoutes.tsx"
    click Router "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/routes/AdminRoutes.tsx"
    click Router "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/routes/AuthRoutes.tsx"
    click Router "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/routes/AdminRoute.tsx"
    click Router "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/client/src/routes/ProtectedRoute.tsx"

    %% Click Events - Backend
    click AuthModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/auth"
    click UserModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/user"
    click CarModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/car"
    click CategoryModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/category"
    click BookingModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/booking"
    click PaymentModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/payment"
    click ReviewModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/review"
    click TransactionModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/transaction"
    click ActivityModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/activity"
    click DashboardModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/dashboard"
    click ImageModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/image"
    click EmailModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/email"
    click DatabaseModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/src/modules/database"
    click ProcessTxn "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/server/src/modules/booking/workers/processTransaction.worker.ts"
    click UnlockCar "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/server/src/modules/booking/workers/unlockCar.worker.ts"

    click DatabaseModule "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/server/prisma/schema/schema.prisma"
    click DatabaseModule "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/prisma/migrations/"

    click APIContainer "https://github.com/tyri0n11/web-app-car-rental-service/blob/main/server/docker-compose.yml"
    click APIContainer "https://github.com/tyri0n11/web-app-car-rental-service/tree/main/server/Dockerfile"

    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef datastore fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef infra fill:#f8d7da,stroke:#721c24,color:#721c24
```
