# guid-dev/nestjs-fastify-typeorm architecture

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

- Interactive diagram: https://gitdiagram.com/guid-dev/nestjs-fastify-typeorm
- Repository: https://github.com/guid-dev/nestjs-fastify-typeorm

## Overview

##### Project Type and Purpose
- Full-stack backend service (no distinct “frontend” here).
- Uses NestJS as the framework with Fastify as HTTP adapter, TypeORM for persistence, and PostgreSQL via Docker.
- Layered architecture (Presentation → Application → Infrastructure).

##### File Structure
- Top-level: configuration files (Dockerfiles, Nest CLI, ESLint, tsconfig), source folder (`src/`), tests, Makefile.
- `src/` subdivided into:
- `presentation/` – HTTP controllers (entry points).
- `application/` – business logic services.
- `infra/` – data layer, TypeORM entities, database config.
- Cross-cutting: `logger.middleware.ts`, `constants.ts`.
- `docker/` holds Dockerfiles for development and PostgreSQL.

##### README
- Confirms purpose: exercise and validate knowledge of NestJS + Fastify + TypeORM stack.
- No pre-drawn architecture, so we must derive from code structure.

##### Main Components & Interactions
a. Components
- Fastify HTTP Server (NestJS adapter)
- NestJS Application Module (wires components)
- Presentation Layer: `HotelController`
- Application Layer: `HotelService`
- Infrastructure Layer: TypeORM Repository wrapping `HotelEntity`
- PostgreSQL Database (Docker container)
- Cross-cutting Middleware: Logger
- External: Docker environment, test harness.

b. Relationships/Data Flow
1. Client → HTTP Request → Fastify Server
2. Fastify → NestJS Router → HotelController
3. Controller calls HotelService (application logic)
4. HotelService uses TypeORM Repository (in infra layer)
5. Repository → PostgreSQL via database driver
6. Response travels back up to controller → client
7. LoggerMiddleware intercepts incoming requests

c. Architectural Patterns/Principles
- Layered (Separation of concerns)
- Dependency Injection (NestJS modules)
- Domain-Driven Structure (entities in infra, services in application)
- Containerization (Docker).

d. Key Technologies/Libraries
- NestJS (app framework)
- Fastify (HTTP adapter)
- TypeORM (ORM)
- PostgreSQL
- Docker & Docker-compose/Makefile orchestration

##### Detail
- Port mappings (e.g., 3000:80 on Docker).

## Diagram (Mermaid)

```mermaid
flowchart TB
    client["Client"]:::external
    e2e["E2E Test Suite"]:::external

    subgraph "App Container (Docker)" 
        direction TB
        fastify["Fastify HTTP Server"]:::stack
        middleware["LoggerMiddleware"]:::cross
        appmodule["AppModule"]:::stack
        applicationModule["Application Module"]:::application
        presentationModule["Presentation Module"]:::presentation
        infraModule["Infrastructure Module"]:::infrastructure
        controller["HotelController"]:::presentation
        service["HotelService"]:::application
        repo["HotelRepository / HotelEntity"]:::infrastructure
        dbconfig["Database Configuration"]:::infrastructure
    end

    subgraph "PostgreSQL Container (Docker)"
        direction TB
        postgres["PostgreSQL Database"]:::database
    end

    client -->|"HTTP Request"| fastify
    e2e -.->|"HTTP Test"| fastify
    fastify --> middleware
    middleware --> controller
    controller -->|"calls service"| service
    service -->|"uses repository"| repo
    repo -->|"queries"| postgres

    appmodule --> presentationModule
    appmodule --> applicationModule
    appmodule --> infraModule

    presentationModule --> controller
    applicationModule --> service
    infraModule --> repo
    infraModule --> dbconfig
    dbconfig --> postgres

    classDef external fill:#cccccc,stroke:#000,stroke-width:1px
    classDef stack fill:#e0e0e0,stroke:#444,stroke-width:1px
    classDef presentation fill:#cce5ff,stroke:#004085,stroke-width:1px
    classDef application fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef infrastructure fill:#ffe5b4,stroke:#e09c00,stroke-width:1px
    classDef database fill:#e2d1f9,stroke:#5e35b1,stroke-width:1px
    classDef cross fill:#f5f5f5,stroke:#6c757d,stroke-width:1px

    click fastify "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/main.ts"
    click appmodule "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/app.module.ts"
    click controller "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/presentation/hotel.controller.ts"
    click service "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/application/services/hotel.service.ts"
    click repo "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/infra/entities/hotel.entity.ts"
    click dbconfig "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/infra/database-config.ts"
    click infraModule "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/infra/infra.module.ts"
    click applicationModule "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/application/application.module.ts"
    click middleware "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/src/logger.middleware.ts"
    click e2e "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/test/app.e2e-spec.ts"
    click fastify "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/docker/development.dockerfile"
    click postgres "https://github.com/guid-dev/nestjs-fastify-typeorm/blob/master/docker/postgres.dockerfile"
```
