# larabeatrizms/backend-vuttr architecture

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

- Interactive diagram: https://gitdiagram.com/larabeatrizms/backend-vuttr
- Repository: https://github.com/larabeatrizms/backend-vuttr

## Overview

##### Project type and purpose
- This is a backend RESTful API (Node.js + TypeScript + Express) that implements DDD, SOLID and TDD principles. It manages a collection of “tools” with CRUD operations, backed by PostgreSQL via TypeORM and exposed via Swagger for documentation.

##### File structure
- Top-level folders:
- src/modules/tools – domain-specific code for the “tools” aggregate
- src/shared – cross-cutting concerns (DI container, HTTP server, TypeORM setup, error handling)
- Under modules/tools:
- dtos – data transfer object definitions
- infra/http – controllers and route definitions
- infra/typeorm – persistence entities and TypeORM repositories
- repositories – interface + fake implementation for testing
- services – business-logic “use-case” classes and their tests
- Under shared/infra:
- http/app.ts & server.ts – Express app initialization
- http/routes – root router aggregator and Swagger JSON
- typeorm – connection setup and migrations

##### README for additional insights
- Confirms tech stack: Node.js, TypeScript, Express, TypeORM, PostgreSQL, Swagger
- Emphasizes DDD layers (domain/services/repositories), SOLID, TDD with Jest

##### Main components & relationships
a. **Client (Postman/Frontend)** → hits
b. **HTTP Server (Express)** in `shared/infra/http/server.ts`
c. **Router Layer**
- Global router (`shared/infra/http/routes/index.ts`)
- Tools router (`modules/tools/infra/http/routes/toolsRouter.routes.ts`)
d. **Controller Layer**
- `ToolsController.ts` receives HTTP, calls services
e. **Service (Use-Case) Layer**
- `CreateToolService`, `ListToolService`, `DeleteToolService`… encapsulate business rules
f. **Repository Layer**
- Interface `IToolsRepository`
- Concrete: `ToolsRepository` using TypeORM
- Fake: `FakeToolsRepository` for unit tests
g. **Persistence & DB**
- Entity `Tool.ts` maps to PostgreSQL table
- TypeORM connection/migrations in `shared/infra/typeorm`
h. **Dependency Injection**
- Container bindings in `shared/container/index.ts`
i. **External Services**
- PostgreSQL database
- Swagger UI for API docs

##### Architectural patterns & design principles
- **Layered Architecture / Onion Architecture**: HTTP → Controllers → Services → Repositories → Database
- **Domain Driven Design (DDD)**: modules organize by domain
- **SOLID Principles**: SRP in controllers/services/repos, DIP via interfaces & DI container
- **TDD**: presence of Jest specs for each service

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Layer
    subgraph "Client & Documentation"
        direction TB
        Client["Client (Postman/Frontend)"]:::external
        SwaggerJSON["Swagger JSON"]:::external
        SwaggerUI["Swagger UI"]:::external
    end

    %% HTTP Layer
    subgraph "HTTP Layer"
        direction TB
        App["Express App<br/>(src/shared/infra/http/app.ts)"]:::http
        Server["HTTP Server<br/>(src/shared/infra/http/server.ts)"]:::http
        GlobalRouter["Global Router<br/>(src/shared/infra/http/routes/index.ts)"]:::http
        ToolsRouter["Tools Router<br/>(src/modules/tools/infra/http/routes/toolsRouter.routes.ts)"]:::http
    end

    %% Controller Layer
    subgraph "Controller Layer"
        direction TB
        ToolsController["ToolsController<br/>(src/modules/tools/infra/http/controllers/ToolsController.ts)"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        CreateToolService["CreateToolService<br/>(src/modules/tools/services/CreateToolService.ts)"]:::service
        ListToolService["ListToolService<br/>(src/modules/tools/services/ListToolService.ts)"]:::service
        DeleteToolService["DeleteToolService<br/>(src/modules/tools/services/DeleteToolService.ts)"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        direction TB
        IToolsRepo["IToolsRepository Interface<br/>(src/modules/tools/repositories/IToolsRepository.ts)"]:::repo
        ToolsRepo["ToolsRepository<br/>(src/modules/tools/infra/typeorm/repositories/ToolsRepository.ts)"]:::repo
        FakeToolsRepo["FakeToolsRepository<br/>(src/modules/tools/repositories/fakes/FakeToolsRepository.ts)"]:::repo
    end

    %% Persistence & Infrastructure
    subgraph "Persistence & Infrastructure"
        direction TB
        ToolEntity["Tool Entity<br/>(src/modules/tools/infra/typeorm/entities/Tool.ts)"]:::entity
        TypeORMConn["TypeORM Connection<br/>(src/shared/infra/typeorm/index.ts)"]:::infra
        Migration["CreateTools Migration<br/>(src/shared/infra/typeorm/migrations/1589420212344-CreateTools.ts)"]:::infra
        PostgresDB["PostgreSQL Database"]:::database
        DIContainer["DI Container Bindings<br/>(src/shared/container/index.ts)"]:::infra
    end

    %% Test Harness
    subgraph "Test Harness (TDD)"
        direction TB
        TestServices["Services Tests<br/>(Jest)"]:::test
    end

    %% Connections
    Client -->|requests| Server
    Server --> App
    App --> SwaggerJSON
    App --> SwaggerUI
    App --> GlobalRouter
    SwaggerUI <-->|docs from| SwaggerJSON
    GlobalRouter --> ToolsRouter
    ToolsRouter --> ToolsController
    ToolsController --> CreateToolService
    ToolsController --> ListToolService
    ToolsController --> DeleteToolService
    CreateToolService --> IToolsRepo
    ListToolService --> IToolsRepo
    DeleteToolService --> IToolsRepo
    IToolsRepo --> ToolsRepo
    IToolsRepo --> FakeToolsRepo
    ToolsRepo --> ToolEntity
    ToolEntity --> PostgresDB
    TypeORMConn --> PostgresDB
    Migration --> PostgresDB
    DIContainer --> ToolsRepo
    DIContainer --> FakeToolsRepo
    TestServices --> CreateToolService
    TestServices --> ListToolService
    TestServices --> DeleteToolService
    TestServices --> FakeToolsRepo

    %% Click Events
    click Server "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/shared/infra/http/server.ts"
    click App "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/shared/infra/http/app.ts"
    click GlobalRouter "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/shared/infra/http/routes/index.ts"
    click SwaggerJSON "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/shared/infra/http/swagger.json"
    click ToolsRouter "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/infra/http/routes/toolsRouter.routes.ts"
    click ToolsController "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/infra/http/controllers/ToolsController.ts"
    click CreateToolService "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/services/CreateToolService.ts"
    click ListToolService "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/services/ListToolService.ts"
    click DeleteToolService "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/services/DeleteToolService.ts"
    click IToolsRepo "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/repositories/IToolsRepository.ts"
    click ToolsRepo "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/infra/typeorm/repositories/ToolsRepository.ts"
    click FakeToolsRepo "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/repositories/fakes/FakeToolsRepository.ts"
    click ToolEntity "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/modules/tools/infra/typeorm/entities/Tool.ts"
    click DIContainer "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/shared/container/index.ts"
    click TypeORMConn "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/shared/infra/typeorm/index.ts"
    click Migration "https://github.com/larabeatrizms/backend-vuttr/blob/master/src/shared/infra/typeorm/migrations/1589420212344-CreateTools.ts"

    %% Styles
    classDef external fill:#D3D3F9,stroke:#666,stroke-width:1px
    classDef http fill:#B3D1FF,stroke:#0366d6,stroke-width:1px
    classDef controller fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef service fill:#A5D6A7,stroke:#1B5E20,stroke-width:1px
    classDef repo fill:#FFE082,stroke:#FF8F00,stroke-width:1px
    classDef entity fill:#FFF59D,stroke:#F9A825,stroke-width:1px
    classDef infra fill:#CFD8DC,stroke:#455A64,stroke-width:1px
    classDef database fill:#B2DFDB,stroke:#00796B,stroke-width:1px
    classDef test fill:#FFCDD2,stroke:#C62828,stroke-width:1px
```
