# ahrmy/car-reviews-clase architecture

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

- Interactive diagram: https://gitdiagram.com/ahrmy/car-reviews-clase
- Repository: https://github.com/ahrmy/car-reviews-clase

## Overview

##### Project type and purpose
- From the README title (“car-reviews-clase”) and the file tree (index.js, app/controllers, app/routes, repositories, docs/data/cars_reviews.sql), this is a Node.js/Express REST API microservice for managing cars (and by extension, car reviews). There is no frontend code here, so it’s primarily a backend service exposing CRUD endpoints for cars.

##### File structure
- index.js: the Express server entry point
- app/routes/cars-routes.js: defines HTTP routes for car endpoints
- app/controllers/cars: controller functions (get-cars, get-car-by-id, create-car, delete-car-by-id)
- app/repositories: data-access layer, with both a STATIC mock (cars-repository-STATIC.js) and a real implementation (cars-repository.js)
- app/middlewares: placeholder for request-level logic (e.g., auth, validation)
- app/infrastructure: placeholder for infra concerns (e.g., logger, DB connection)
- docs/data/cars_reviews.sql: database schema or seed data
- docs/postman: Postman collection folder

##### Essential details to capture
- Entry point (index.js) spinning up Express
- Middleware chain before routes
- Route definitions linking to controller methods
- Controller → Repository calls, and the ability to swap between STATIC and SQL repositories
- Database schema source (docs/data/cars_reviews.sql) feeding into the persistence layer
- HTTP clients as external actors invoking the service

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Client["HTTP Client<br/>(Postman, Frontend)"]:::client
    %% API Layer
    subgraph "API Layer"
        APIServer["API Gateway<br/>(index.js)"]:::api
    end
    %% Middleware Layer
    subgraph "Middleware Layer"
        Middlewares["app/middlewares/"]:::middleware
    end
    %% Routing Layer
    subgraph "Routing Layer"
        Routes["cars-routes.js"]:::router
    end
    %% Controller Layer
    subgraph "Controller Layer"
        GetCars["get-cars.js"]:::controller
        GetCarById["get-car-by-id.js"]:::controller
        CreateCar["create-car.js"]:::controller
        DeleteCar["delete-car-by-id.js"]:::controller
    end
    %% Repository Layer
    subgraph "Repository Layer"
        RepoSQL["cars-repository.js"]:::repository
        RepoStatic["cars-repository-STATIC.js"]:::repository
    end
    %% Infrastructure & Config
    subgraph "Infrastructure"
        Infra["app/infrastructure/"]:::infra
        Env[".env.template"]:::infra
    end
    %% Database & Documentation
    DB["SQL Database<br/>(cars_reviews.sql)"]:::database
    Docs["Postman Collection<br/>(docs/postman/)"]:::documentation

    %% Flow
    Client -->|"HTTP Request"| APIServer
    APIServer -->|"invoke middlewares"| Middlewares
    Middlewares -->|"route to endpoints"| Routes
    Routes -->|"calls controller"| GetCars
    Routes -->|"calls controller"| GetCarById
    Routes -->|"calls controller"| CreateCar
    Routes -->|"calls controller"| DeleteCar
    GetCars -->|"uses repo abstraction"| RepoSQL
    GetCars -->|"uses repo abstraction"| RepoStatic
    GetCarById -->|"uses repo abstraction"| RepoSQL
    GetCarById -->|"uses repo abstraction"| RepoStatic
    CreateCar -->|"uses repo abstraction"| RepoSQL
    CreateCar -->|"uses repo abstraction"| RepoStatic
    DeleteCar -->|"uses repo abstraction"| RepoSQL
    DeleteCar -->|"uses repo abstraction"| RepoStatic
    RepoSQL -->|"executes SQL"| DB
    RepoStatic -->|"returns mock data"| DB
    APIServer -->|"loads config & logger"| Infra
    RepoSQL -->|"uses DB connection"| Infra
    Client -->|"view docs"| Docs

    %% Click Events
    click APIServer "https://github.com/ahrmy/car-reviews-clase/blob/master/index.js"
    click Middlewares "https://github.com/ahrmy/car-reviews-clase/tree/master/app/middlewares/"
    click Routes "https://github.com/ahrmy/car-reviews-clase/blob/master/app/routes/cars-routes.js"
    click GetCars "https://github.com/ahrmy/car-reviews-clase/blob/master/app/controllers/cars/get-cars.js"
    click GetCarById "https://github.com/ahrmy/car-reviews-clase/blob/master/app/controllers/cars/get-car-by-id.js"
    click CreateCar "https://github.com/ahrmy/car-reviews-clase/blob/master/app/controllers/cars/create-car.js"
    click DeleteCar "https://github.com/ahrmy/car-reviews-clase/blob/master/app/controllers/cars/delete-car-by-id.js"
    click RepoSQL "https://github.com/ahrmy/car-reviews-clase/blob/master/app/repositories/cars-repository.js"
    click RepoStatic "https://github.com/ahrmy/car-reviews-clase/blob/master/app/repositories/cars-repository-STATIC.js"
    click Infra "https://github.com/ahrmy/car-reviews-clase/tree/master/app/infrastructure/"
    click Env "https://github.com/ahrmy/car-reviews-clase/blob/master/.env.template"
    click DB "https://github.com/ahrmy/car-reviews-clase/blob/master/docs/data/cars_reviews.sql"
    click Docs "https://github.com/ahrmy/car-reviews-clase/tree/master/docs/postman/"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
    classDef api fill:#A9DFBF,stroke:#196F3D,color:#145A32;
    classDef middleware fill:#F9E79F,stroke:#B9770E,color:#7D6608;
    classDef router fill:#F5B041,stroke:#B9770E,color:#7D6608;
    classDef controller fill:#EB984E,stroke:#A04000,color:#512E5F;
    classDef repository fill:#BB8FCE,stroke:#6C3483,color:#4A235A;
    classDef database fill:#EC7063,stroke:#922B21,color:#641E16;
    classDef infra fill:#D5D8DC,stroke:#85929E,color:#1B2631;
    classDef documentation fill:#85C1E9,stroke:#1A5276,color:#1B1B1B;
```
