# vapor/template-fluent-postgres architecture

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

- Interactive diagram: https://gitdiagram.com/vapor/template-fluent-postgres
- Repository: https://github.com/vapor/template-fluent-postgres

## Overview

##### Project type and purpose
- This is a backend-only web service built in Swift using the Vapor framework, with FluentORM to persist “Todo” items in a PostgreSQL database. It’s packaged as a Dockerized microservice (docker-compose.yml + Dockerfile) that exposes a RESTful API.

##### File structure
- Top-level:
- Dockerfile / docker-compose.yml / .dockerignore → containerization & multi-service orchestration (app + postgres)
- Package.swift → Swift Package Manager manifest
- Sources/TemplateFluentPostgres → main application module
– Controllers/TodoController.swift → HTTP route handlers (CRUD)
– DTOs/TodoDTO.swift → data transfer object for request/response payloads
– Migrations/CreateTodo.swift → Fluent migration for the “todos” table
– Models/Todo.swift → ORM model mapping to the “todos” table
– configure.swift → bootstraps middleware, database config, migrations
– routes.swift → attaches HTTP routes to controllers
– entrypoint.swift → application entry point, starts Vapor server
- Public → static files (empty here)
- Tests → unit/integration tests for the module

##### README for additional insights
- Confirms it’s a Vapor web service template. No frontend, no external third-party integrations beyond Vapor and Postgres.

##### Elements
- Labels: “API Client”, “Vapor App”, “Postgres DB”
- HTTP request/response flow (Client ↔ Vapor)
- ORM-to-DB queries (Vapor → Postgres)
- Migration at startup (Vapor —> DB schema)
- Containers (Docker) as large rectangles

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    APIClient["API Client\n(HTTP Client)"]:::external

    %% Docker Orchestrator Container
    subgraph "Docker Orchestrator" 
        direction TB
        DockerOrchestrator["Docker Orchestrator"]:::compute
        subgraph "Containers" 
            direction TB
            VaporApp["Vapor App Container"]:::compute
            PostgresDB["PostgreSQL DB"]:::storage
        end
    end

    %% Application Internal Layers
    subgraph "TemplateFluentPostgres App" 
        direction TB
        EntryPoint["entrypoint.swift"]:::code
        Configure["configure.swift"]:::code
        subgraph "Routing Layer"
            direction TB
            Routes["routes.swift"]:::code
        end
        subgraph "Controller Layer"
            direction TB
            TodoController["TodoController.swift"]:::code
        end
        subgraph "DTO Layer"
            direction TB
            TodoDTO["TodoDTO.swift"]:::code
        end
        subgraph "Model Layer"
            direction TB
            TodoModel["Todo.swift"]:::code
        end
        subgraph "Migration Layer"
            direction TB
            CreateTodo["CreateTodo.swift"]:::code
        end
        PublicStatic["Public/.gitkeep\n(Static Files)"]:::code
    end

    %% Orchestration & Flow
    APIClient -->|"HTTP Request"| VaporApp
    DockerOrchestrator --> VaporApp
    DockerOrchestrator --> PostgresDB

    VaporApp --> EntryPoint
    EntryPoint --> Configure
    Configure --> CreateTodo
    CreateTodo -->|Runs Migration| PostgresDB

    VaporApp --> Routes
    Routes --> TodoController
    TodoController --> TodoDTO
    TodoController --> TodoModel
    TodoModel -->|ORM Queries| PostgresDB

    APIClient -->|Fetch Static| PublicStatic

    %% Click Events
    click DockerOrchestrator "https://github.com/vapor/template-fluent-postgres/blob/main/docker-compose.yml"
    click DockerOrchestrator "https://github.com/vapor/template-fluent-postgres/blob/main/.dockerignore"
    click DockerOrchestrator "https://github.com/vapor/template-fluent-postgres/tree/main/Dockerfile"
    click PackageSwift "https://github.com/vapor/template-fluent-postgres/blob/main/Package.swift"
    click VaporApp "https://github.com/vapor/template-fluent-postgres/tree/main/Sources/TemplateFluentPostgres"
    click Routes "https://github.com/vapor/template-fluent-postgres/blob/main/Sources/TemplateFluentPostgres/routes.swift"
    click TodoController "https://github.com/vapor/template-fluent-postgres/blob/main/Sources/TemplateFluentPostgres/Controllers/TodoController.swift"
    click TodoDTO "https://github.com/vapor/template-fluent-postgres/blob/main/Sources/TemplateFluentPostgres/DTOs/TodoDTO.swift"
    click TodoModel "https://github.com/vapor/template-fluent-postgres/blob/main/Sources/TemplateFluentPostgres/Models/Todo.swift"
    click CreateTodo "https://github.com/vapor/template-fluent-postgres/blob/main/Sources/TemplateFluentPostgres/Migrations/CreateTodo.swift"
    click Configure "https://github.com/vapor/template-fluent-postgres/blob/main/Sources/TemplateFluentPostgres/configure.swift"
    click EntryPoint "https://github.com/vapor/template-fluent-postgres/blob/main/Sources/TemplateFluentPostgres/entrypoint.swift"
    click PublicStatic "https://github.com/vapor/template-fluent-postgres/blob/main/Public/.gitkeep"
    %% Tests folder mapping not included as node

    %% Styles
    classDef compute fill:#E3F2FD,stroke:#42A5F5;
    classDef storage fill:#FFF3E0,stroke:#FB8C00;
    classDef code fill:#F3E5F5,stroke:#AB47BC;
    classDef external fill:#E8F5E9,stroke:#43A047;
```
