# peakvoyage/fastapi-starter-template architecture

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

- Interactive diagram: https://gitdiagram.com/peakvoyage/fastapi-starter-template
- Repository: https://github.com/peakvoyage/fastapi-starter-template

## Overview

##### Main Components Identification
The system should be represented with these key components:

a) API Layer:
- Authentication middleware
- Route handlers for users and authentication

b) Service Layer:
- Authentication Service
- JWT Service
- Security Service

c) Data Layer:
- PostgreSQL Database
- Repository Layer
- Query Layer

##### Component Organization

**Client Layer (External)**
- ↓
**API Gateway Layer**
- ↓
**Service Layer**
- ↓
**Data Access Layer**
- ↓
**Database Layer**

##### Specific Components and Relationships

API Gateway Layer:
- Main FastAPI application connecting to route handlers (/api/routes)
- Authentication dependencies
- To error handlers

Service Layer:
- Authentication Service (authentication.py)
- JWT Service (jwt.py)
- Security Service (security.py)

Data Access Layer:
- Repository pattern implementation (repositories/)
- Database queries (queries/)
- Alembic migrations

Database Layer:
- PostgreSQL instance
- User tables and related schemas

##### Additional Elements

Supporting components:
- Configuration management (core/settings)
- Domain models (models/domain)
- Schema definitions (models/schemas)
- Error handling components (api/errors)

##### Specific Implementation Details

Key interactions:
- JWT token flow for authentication
- User registration and login paths
- Database connection pool management
- Error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Application]
    end

    subgraph API_Gateway
        FAS["FastAPI Application Server"]:::api
        AM["Authentication Middleware"]:::api
        RH["Route Handlers"]:::api
        EH["Error Handlers"]:::api
    end

    subgraph Services
        AS["Authentication Service"]:::service
        JS["JWT Service"]:::service
        SS["Security Service"]:::service
    end

    subgraph Data_Access
        RP["Repository Layer"]:::data
        QL["Query Layer"]:::data
        DT["Database Tables"]:::data
        DM["Database Migrations"]:::data
    end

    subgraph Domain
        UDM["User Domain Model"]:::domain
        BDM["Base Domain Model"]:::domain
    end

    subgraph Schemas
        JWS["JWT Schemas"]:::schema
        USS["User Schemas"]:::schema
    end

    subgraph Configuration
        BS["Base Settings"]:::config
        DS["Development Settings"]:::config
        PS["Production Settings"]:::config
        SC["Security Config"]:::config
    end

    subgraph Database
        PG[("PostgreSQL")]:::db
        DBC["Database Connection"]:::db
        DBE["Database Events"]:::db
    end

    subgraph Error_Handling
        HE["HTTP Errors"]:::error
        VE["Validation Errors"]:::error
    end

    %% Relationships
    C --> FAS
    FAS --> AM
    FAS --> RH
    FAS --> EH
    
    AM --> AS
    AM --> JS
    AM --> SS
    
    RH --> RP
    RP --> QL
    QL --> DT
    DT --> PG
    
    AS --> UDM
    AS --> JWS
    AS --> USS
    
    DBC --> PG
    DBE --> PG
    
    EH --> HE
    EH --> VE

    %% Click Events
    click FAS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/main.py"
    click AM "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/api/dependencies/authentication.py"
    click RH "https://github.com/peakvoyage/fastapi-starter-template/tree/main/app/api/routes"
    click AS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/services/authentication.py"
    click JS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/services/jwt.py"
    click SS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/services/security.py"
    click RP "https://github.com/peakvoyage/fastapi-starter-template/tree/main/app/db/repositories"
    click QL "https://github.com/peakvoyage/fastapi-starter-template/tree/main/app/db/queries"
    click DT "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/db/tables.py"
    click DM "https://github.com/peakvoyage/fastapi-starter-template/tree/main/app/db/migrations"
    click UDM "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/models/domain/users.py"
    click BDM "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/models/domain/rwmodel.py"
    click JWS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/models/schemas/jwt.py"
    click USS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/models/schemas/users.py"
    click HE "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/api/errors/http_error.py"
    click VE "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/api/errors/validation_error.py"
    click BS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/core/settings/base.py"
    click DS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/core/settings/development.py"
    click PS "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/core/settings/production.py"
    click SC "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/core/security.py"
    click DBC "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/api/dependencies/database.py"
    click DBE "https://github.com/peakvoyage/fastapi-starter-template/blob/main/app/db/events.py"

    %% Styling
    classDef api fill:#2374f7,stroke:#000,stroke-width:2px,color:#fff
    classDef service fill:#48a868,stroke:#000,stroke-width:2px,color:#fff
    classDef data fill:#d4b43c,stroke:#000,stroke-width:2px,color:#000
    classDef domain fill:#9c4ea1,stroke:#000,stroke-width:2px,color:#fff
    classDef schema fill:#3cabd4,stroke:#000,stroke-width:2px,color:#fff
    classDef config fill:#d45c3c,stroke:#000,stroke-width:2px,color:#fff
    classDef db fill:#d43c3c,stroke:#000,stroke-width:2px,color:#fff
    classDef error fill:#ff6b6b,stroke:#000,stroke-width:2px,color:#fff
```
