# buguno/fastapi-template architecture

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

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

## Overview

This is a reusable FastAPI template with a working async user-management and JWT-authentication slice. The main workflow is HTTP request → router → service → user persistence, with schemas shaping inputs and outputs; authentication adds password hashing, token creation, and current-user resolution. The excerpts show the core calls and dependencies. PostgreSQL is documented as the database target, but the runtime database interaction is through SQLAlchemy sessions. Other unsampled capabilities are not inferred beyond the README and file tree.

Main entry points: [`app/routers/users.py`](https://github.com/buguno/fastapi-template/blob/master/app/routers/users.py) (User Routes), [`app/security.py`](https://github.com/buguno/fastapi-template/blob/master/app/security.py) (Password And JWT), [`app/main.py`](https://github.com/buguno/fastapi-template/blob/master/app/main.py) (FastAPI Application), [`app/services/user.py`](https://github.com/buguno/fastapi-template/blob/master/app/services/user.py) (User Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_application["FastAPI Application<br/>[main.py]"]
  node_user_routes["User Routes<br/>[users.py]"]
  node_auth_routes["Auth Routes<br/>[auth.py]"]
end

subgraph group_domain["Domain Services"]
  node_user_service["User Service<br/>[user.py]"]
  node_auth_service["Auth Service<br/>[auth.py]"]
  node_domain_errors["Domain Exceptions<br/>[exceptions.py]"]
end

subgraph group_security["Identity And Persistence"]
  node_user_entity["User Entity<br/>[user.py]"]
  node_model_registry["Model Registry<br/>[base.py]"]
  node_database_session["Async Database Session<br/>[database.py]"]
  node_security_logic["Password And JWT<br/>[security.py]"]
end

subgraph group_contracts["Contracts And Configuration"]
  node_user_contracts["User Schemas<br/>[user.py]"]
  node_token_contract["Token Schema<br/>[token.py]"]
  node_pagination["Pagination Filter<br/>[filters.py]"]
  node_message_contract["Message Schema<br/>[message.py]"]
  node_settings["Application Settings<br/>[settings.py]"]
end

node_client(("API Client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_application
node_application -->|"mounts routes"| node_user_routes
node_application -->|"mounts routes"| node_auth_routes
node_application -->|"translates errors"| node_domain_errors
node_application -->|"uses response"| node_message_contract
node_application -->|"configures docs"| node_settings
node_user_routes -->|"calls"| node_user_service
node_auth_routes -->|"calls"| node_auth_service
node_user_routes -->|"injects session"| node_database_session
node_auth_routes -->|"injects session"| node_database_session
node_user_routes -->|"resolves current user"| node_security_logic
node_auth_routes -->|"resolves current user"| node_security_logic
node_user_routes -->|"accepts and returns"| node_user_contracts
node_user_routes -->|"accepts filters"| node_pagination
node_user_routes -->|"returns message"| node_message_contract
node_auth_routes -->|"returns token"| node_token_contract
node_user_service -->|"queries and updates"| node_user_entity
node_user_service -->|"hashes passwords"| node_security_logic
node_user_service -->|"raises domain errors"| node_domain_errors
node_user_service -->|"uses input schema"| node_user_contracts
node_user_service -->|"uses filters"| node_pagination
node_auth_service -->|"queries user"| node_user_entity
node_auth_service -->|"verifies and issues tokens"| node_security_logic
node_auth_service -->|"raises credential error"| node_domain_errors
node_security_logic -->|"injects session"| node_database_session
node_security_logic -->|"loads current user"| node_user_entity
node_security_logic -->|"uses token settings"| node_settings
node_database_session -->|"reads database URL"| node_settings
node_model_registry -->|"registers mapping"| node_user_entity
node_database_session -.->|"connects asynchronously"| node_postgres

click node_application "https://github.com/buguno/fastapi-template/blob/master/app/main.py"
click node_user_routes "https://github.com/buguno/fastapi-template/blob/master/app/routers/users.py"
click node_auth_routes "https://github.com/buguno/fastapi-template/blob/master/app/routers/auth.py"
click node_user_service "https://github.com/buguno/fastapi-template/blob/master/app/services/user.py"
click node_auth_service "https://github.com/buguno/fastapi-template/blob/master/app/services/auth.py"
click node_user_entity "https://github.com/buguno/fastapi-template/blob/master/app/models/user.py"
click node_model_registry "https://github.com/buguno/fastapi-template/blob/master/app/models/base.py"
click node_database_session "https://github.com/buguno/fastapi-template/blob/master/app/database.py"
click node_security_logic "https://github.com/buguno/fastapi-template/blob/master/app/security.py"
click node_user_contracts "https://github.com/buguno/fastapi-template/blob/master/app/schemas/user.py"
click node_token_contract "https://github.com/buguno/fastapi-template/blob/master/app/schemas/token.py"
click node_pagination "https://github.com/buguno/fastapi-template/blob/master/app/schemas/filters.py"
click node_message_contract "https://github.com/buguno/fastapi-template/blob/master/app/schemas/message.py"
click node_domain_errors "https://github.com/buguno/fastapi-template/blob/master/app/exceptions.py"
click node_settings "https://github.com/buguno/fastapi-template/blob/master/app/settings.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_application,node_user_routes,node_auth_routes,node_client toneBlue
class node_user_service,node_auth_service,node_domain_errors,node_postgres toneAmber
class node_user_entity,node_model_registry,node_database_session,node_security_logic toneMint
class node_user_contracts,node_token_contract,node_pagination,node_message_contract,node_settings toneRose
```

## Components

### HTTP API

- [FastAPI Application](https://github.com/buguno/fastapi-template/blob/master/app/main.py): `app/main.py`
- [User Routes](https://github.com/buguno/fastapi-template/blob/master/app/routers/users.py): `app/routers/users.py`
- [Auth Routes](https://github.com/buguno/fastapi-template/blob/master/app/routers/auth.py): `app/routers/auth.py`

### Domain Services

- [User Service](https://github.com/buguno/fastapi-template/blob/master/app/services/user.py): `app/services/user.py`
- [Auth Service](https://github.com/buguno/fastapi-template/blob/master/app/services/auth.py): `app/services/auth.py`
- [Domain Exceptions](https://github.com/buguno/fastapi-template/blob/master/app/exceptions.py): `app/exceptions.py`

### Identity And Persistence

- [User Entity](https://github.com/buguno/fastapi-template/blob/master/app/models/user.py): `app/models/user.py`
- [Model Registry](https://github.com/buguno/fastapi-template/blob/master/app/models/base.py): `app/models/base.py`
- [Async Database Session](https://github.com/buguno/fastapi-template/blob/master/app/database.py): `app/database.py`
- [Password And JWT](https://github.com/buguno/fastapi-template/blob/master/app/security.py): `app/security.py`

### Contracts And Configuration

- [User Schemas](https://github.com/buguno/fastapi-template/blob/master/app/schemas/user.py): `app/schemas/user.py`
- [Token Schema](https://github.com/buguno/fastapi-template/blob/master/app/schemas/token.py): `app/schemas/token.py`
- [Pagination Filter](https://github.com/buguno/fastapi-template/blob/master/app/schemas/filters.py): `app/schemas/filters.py`
- [Message Schema](https://github.com/buguno/fastapi-template/blob/master/app/schemas/message.py): `app/schemas/message.py`
- [Application Settings](https://github.com/buguno/fastapi-template/blob/master/app/settings.py): `app/settings.py`

### Other components

- **API Client**
- **PostgreSQL**

## Connections

- API Client → FastAPI Application: sends requests (evidence: `README.md`)
- FastAPI Application → User Routes: mounts routes (evidence: `app/main.py`)
- FastAPI Application → Auth Routes: mounts routes (evidence: `app/main.py`)
- FastAPI Application → Domain Exceptions: translates errors (evidence: `app/main.py`)
- FastAPI Application → Message Schema: uses response (evidence: `app/main.py`)
- FastAPI Application → Application Settings: configures docs (evidence: `app/main.py`)
- User Routes → User Service: calls (evidence: `app/routers/users.py`)
- Auth Routes → Auth Service: calls (evidence: `app/routers/auth.py`)
- User Routes → Async Database Session: injects session (evidence: `app/routers/users.py`)
- Auth Routes → Async Database Session: injects session (evidence: `app/routers/auth.py`)
- User Routes → Password And JWT: resolves current user (evidence: `app/routers/users.py`)
- Auth Routes → Password And JWT: resolves current user (evidence: `app/routers/auth.py`)
- User Routes → User Schemas: accepts and returns (evidence: `app/routers/users.py`)
- User Routes → Pagination Filter: accepts filters (evidence: `app/routers/users.py`)
- User Routes → Message Schema: returns message (evidence: `app/routers/users.py`)
- Auth Routes → Token Schema: returns token (evidence: `app/routers/auth.py`)
- User Service → User Entity: queries and updates (evidence: `app/services/user.py`)
- User Service → Password And JWT: hashes passwords (evidence: `app/services/user.py`)
- User Service → Domain Exceptions: raises domain errors (evidence: `app/services/user.py`)
- User Service → User Schemas: uses input schema (evidence: `app/services/user.py`)
- User Service → Pagination Filter: uses filters (evidence: `app/services/user.py`)
- Auth Service → User Entity: queries user (evidence: `app/services/auth.py`)
- Auth Service → Password And JWT: verifies and issues tokens (evidence: `app/services/auth.py`)
- Auth Service → Domain Exceptions: raises credential error (evidence: `app/services/auth.py`)
- Password And JWT → Async Database Session: injects session (evidence: `app/security.py`)
- Password And JWT → User Entity: loads current user (evidence: `app/security.py`)
- Password And JWT → Application Settings: uses token settings (evidence: `app/security.py`)
- Async Database Session → Application Settings: reads database URL (evidence: `app/database.py`)
- Model Registry → User Entity: registers mapping (evidence: `app/models/__init__.py`)
- Async Database Session → PostgreSQL: connects asynchronously
