# matheusmattos7/project-car-shop architecture

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

- Interactive diagram: https://gitdiagram.com/matheusmattos7/project-car-shop
- Repository: https://github.com/matheusmattos7/project-car-shop

## Overview

##### Project type and purpose
- This is a TypeScript‐based backend RESTful API for a car dealership (“Car Shop”) built with Node.js.
- It implements a CRUD API for “cars” (create, read, update, delete) using MongoDB as its datastore.
- It follows the MSC (Model-Service-Controller) pattern and is Dockerized for local development or containerized deployment.

##### File structure
- Top‐level config files: Dockerfile, docker‐compose.yml, tsconfig.json, lint/test configs.
- src/
├ controllers/ ⇨ HTTP endpoint handlers (CarsController.ts)
├ services/    ⇨ business logic (CarsService.ts)
├ models/      ⇨ data access layer (CarsModel.ts, MongoModel.ts, connection.ts)
├ routes/      ⇨ Express route definitions (route.ts)
├ middleware/  ⇨ error‐handling middleware
├ interfaces/  ⇨ TypeScript interfaces for domain models and services
└ Util/        ⇨ utilities (e.g., HTTP status codes)
- Entry points: src/app.ts (Express app setup), src/index.ts (server start).

##### README for additional insights
- Confirms MSC architecture.
- Technologies: Node.js, TypeScript, Express, MongoDB, Docker.
- Endpoints: POST/GET/PUT/DELETE on /cars, as detailed in the EndPoints section.

##### Elements
- Clear labels for each component (e.g., “CarsController”, “CarsService”, “CarsModel”).
- Blue rectangles for API layer (Routes, Controllers)
- Green rectangles for Business layer (Services)

##### Final advice
- A note about error middleware intercepting unhandled exceptions.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External client and gateway
    Client["Client (e.g., Postman)"]:::external
    LB["Load Balancer / API Gateway"]:::external

    %% Docker container boundary
    subgraph "Docker Container" 
        direction TB
        subgraph "Express App (port 3001)"
            direction TB
            SE["Server Entry Point\nindex.ts"]:::infrastructure
            AA["App Setup\napp.ts"]:::infrastructure

            %% Route layer
            RT["Express Routes\nroute.ts"]:::routeLayer

            %% Controller layer
            CC["CarsController"]:::controller

            %% Service layer
            CS["CarsService"]:::service

            %% Model layer
            CM["CarsModel"]:::model
            MM["MongoModel"]:::model
            DBConn["Database Connection\nconnection.ts"]:::model

            %% Interfaces & Utilities
            ICAR["ICar Interface\nICar.ts"]:::interface
            IMDL["IModel Interface\nIModel.ts"]:::interface
            ISRV["IService Interface\nIService.ts"]:::interface
            IVH["IVehicle Interface\nIVehicle.ts"]:::interface
            SC["HTTP Status Codes Util\nStatusCode.ts"]:::util

            %% Error handling
            EC["Error Catalogs\nerrorCatalogs.ts"]:::middleware
            EMW["Error Handling Middleware\nerror.ts"]:::middleware
        end

        subgraph "MongoDB Instance"
            direction TB
            MONGO["MongoDB"]:::database
        end
    end

    %% Data flow
    Client -->|HTTP Request| LB
    LB -->|forwards to port 3001| AA
    AA --> RT
    RT -->|matches route| CC
    CC -->|calls create/read/update/delete| CS
    CS -->|invokes| CM
    CM -->|extends| MM
    CM -->|uses| DBConn
    DBConn -->|connects to| MONGO
    MONGO -->|returns data| DBConn
    DBConn --> CM
    CM --> CS
    CS --> CC
    CC -->|sends HTTP Response| Client

    %% Error flow
    CC -->|throws error| EMW
    CS -->|throws error| EMW
    CM -->|throws error| EMW
    EMW -->|handles and responds| Client

    %% Interfaces & Utils relations
    CC -->|implements IService| ISRV
    CS -->|implements IModel| IMDL
    CC -->|uses ICar| ICAR
    CC -->|uses HttpStatus| SC
    CS -->|uses HttpStatus| SC
    EC -->|used by| EMW

    %% Entry point to app
    SE --> AA

    %% Click events
    click CC "https://github.com/matheusmattos7/project-car-shop/blob/main/src/controllers/CarsController.ts"
    click CS "https://github.com/matheusmattos7/project-car-shop/blob/main/src/services/CarsService.ts"
    click CM "https://github.com/matheusmattos7/project-car-shop/blob/main/src/models/CarsModel.ts"
    click MM "https://github.com/matheusmattos7/project-car-shop/blob/main/src/models/MongoModel.ts"
    click DBConn "https://github.com/matheusmattos7/project-car-shop/blob/main/src/models/connection.ts"
    click RT "https://github.com/matheusmattos7/project-car-shop/blob/main/src/routes/route.ts"
    click EMW "https://github.com/matheusmattos7/project-car-shop/blob/main/src/middleware/Error/error.ts"
    click EC "https://github.com/matheusmattos7/project-car-shop/blob/main/src/middleware/Error/errorCatalogs.ts"
    click SC "https://github.com/matheusmattos7/project-car-shop/blob/main/src/Util/StatusCode.ts"
    click ICAR "https://github.com/matheusmattos7/project-car-shop/blob/main/src/interfaces/ICar.ts"
    click IMDL "https://github.com/matheusmattos7/project-car-shop/blob/main/src/interfaces/IModel.ts"
    click ISRV "https://github.com/matheusmattos7/project-car-shop/blob/main/src/interfaces/IService.ts"
    click IVH "https://github.com/matheusmattos7/project-car-shop/blob/main/src/interfaces/IVehicle.ts"
    click AA "https://github.com/matheusmattos7/project-car-shop/blob/main/src/app.ts"
    click SE "https://github.com/matheusmattos7/project-car-shop/blob/main/src/index.ts"
    click Dockerfile "https://github.com/matheusmattos7/project-car-shop/tree/main/Dockerfile"
    click docker-compose.yml "https://github.com/matheusmattos7/project-car-shop/blob/main/docker-compose.yml"

    %% Styles
    classDef external fill:#ABB2B9,stroke:#566573,color:#1B2631
    classDef routeLayer fill:#D6EAF8,stroke:#21618C,color:#1B2631
    classDef controller fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef service fill:#A9DFBF,stroke:#196F3D,color:#1B2631
    classDef model fill:#F9E79F,stroke:#B9770E,color:#1B2631
    classDef database fill:#E59866,stroke:#B03A2E,color:#1B2631
    classDef middleware fill:#D5D8DC,stroke:#5D6D7E,color:#1B2631
    classDef util fill:#F5CBA7,stroke:#B9770E,color:#1B2631
    classDef interface fill:#D2B4DE,stroke:#6C3483,color:#1B2631
    classDef infrastructure fill:#CCD1D1,stroke:#566573,color:#1B2631
```
