# ivan-borovets/fastapi-clean-example architecture

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

- Interactive diagram: https://gitdiagram.com/ivan-borovets/fastapi-clean-example
- Repository: https://github.com/ivan-borovets/fastapi-clean-example

## Overview

This is a FastAPI user and account management service with role-based administration and cookie-backed authentication. The principal flow enters through HTTP account or user routes, delegates into authentication handlers or core user operations, and uses outbound adapters for sessions and persistence. The graph preserves distinct account, user-command/query, authorization, and session stages. The README is currently sparse, so some feature coverage comes from the source tree and SOURCE INDEX; unsampled implementation links are omitted where caller evidence is unavailable.

Main entry points: [`src/app/outbound/auth_ctx/handlers`](https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/outbound/auth_ctx/handlers) (Sign-up and session handlers), [`src/app/main/ioc/outbound.py`](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/main/ioc/outbound.py) (Application wiring), [`src/app/inbound/http/root_router.py`](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/root_router.py) (Root router), [`src/app/inbound/http/api_v1_router.py`](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/api_v1_router.py) (API v1 router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP interface"]
  node_root["Root router<br/>[root_router.py]"]
  node_v1["API v1 router<br/>[api_v1_router.py]"]
  node_account_routes["Account routes<br/>[router.py]"]
  node_user_routes["User routes<br/>[router.py]"]
  node_health["Health routes<br/>[router.py]"]
  node_user_endpoints["User endpoints"]
end

subgraph group_core["Core user domain"]
  node_user_commands["User commands"]
  node_user_queries["User listing query<br/>[list_users.py]"]
  node_user_domain["User domain services<br/>[user.py]"]
  node_user_entity["User entity and types<br/>[user.py]"]
  node_authorization["Current-user authorization"]
end

subgraph group_auth["Authentication"]
  node_account_handlers["Sign-up and session handlers"]
  node_auth_service["Session service<br/>[service.py]"]
  node_jwt["JWT processing<br/>[jwt_processor.py]"]
end

subgraph group_outbound["Persistence and adapters"]
  node_storage_adapters["SQLAlchemy adapters"]
  node_auth_storage["Session persistence<br/>[sqla_tx_storage.py]"]
  node_auth_user_storage["Authentication user storage"]
  node_composition["Application wiring<br/>[outbound.py]"]
end

node_client(("API client"))
node_database[("SQL database")]

node_client -->|"sends requests"| node_root
node_root -->|"mounts"| node_v1
node_root -->|"mounts"| node_health
node_v1 -->|"mounts"| node_account_routes
node_v1 -->|"mounts"| node_user_routes
node_account_routes -->|"routes account actions"| node_account_handlers
node_user_routes -->|"mounts endpoints"| node_user_endpoints
node_account_handlers -->|"uses user services"| node_user_domain
node_account_handlers -->|"checks current user"| node_authorization
node_account_handlers -->|"uses user storage"| node_auth_user_storage
node_user_domain -->|"builds users"| node_user_entity
node_authorization -->|"returns user"| node_user_entity
node_authorization -.->|"revokes access"| node_storage_adapters
node_auth_service -->|"processes tokens"| node_jwt
node_auth_service -->|"uses session storage"| node_auth_storage
node_auth_storage -->|"reads and writes"| node_database
node_auth_user_storage -->|"reads and writes"| node_database
node_storage_adapters -.->|"persists domain data"| node_database
node_composition -->|"configures"| node_auth_service
node_composition -->|"configures"| node_auth_storage
node_composition -->|"configures"| node_auth_user_storage

click node_root "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/root_router.py"
click node_v1 "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/api_v1_router.py"
click node_account_routes "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/account/router.py"
click node_user_routes "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/users/router.py"
click node_health "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/health/router.py"
click node_account_handlers "https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/outbound/auth_ctx/handlers"
click node_user_endpoints "https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/inbound/http/users"
click node_user_commands "https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/core/commands"
click node_user_queries "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/queries/list_users.py"
click node_user_domain "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/common/services/user.py"
click node_user_entity "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/common/entities/user.py"
click node_authorization "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/common/authorization/current_user_service.py"
click node_auth_service "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/service.py"
click node_jwt "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/jwt_processor.py"
click node_storage_adapters "https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/outbound/adapters"
click node_auth_storage "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/sqla_tx_storage.py"
click node_auth_user_storage "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/sqla_user_tx_storage.py"
click node_composition "https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/main/ioc/outbound.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_root,node_v1,node_account_routes,node_user_routes,node_health,node_user_endpoints,node_client toneBlue
class node_user_commands,node_user_queries,node_user_domain,node_user_entity,node_authorization,node_database toneAmber
class node_account_handlers,node_auth_service,node_jwt toneMint
class node_storage_adapters,node_auth_storage,node_auth_user_storage,node_composition toneRose
```

## Components

### HTTP interface

- [Root router](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/root_router.py): `src/app/inbound/http/root_router.py`
- [API v1 router](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/api_v1_router.py): `src/app/inbound/http/api_v1_router.py`
- [Account routes](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/account/router.py): `src/app/inbound/http/account/router.py`
- [User routes](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/users/router.py): `src/app/inbound/http/users/router.py`
- [Health routes](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/inbound/http/health/router.py): `src/app/inbound/http/health/router.py`
- [User endpoints](https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/inbound/http/users): `src/app/inbound/http/users`

### Core user domain

- [User commands](https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/core/commands): `src/app/core/commands`
- [User listing query](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/queries/list_users.py): `src/app/core/queries/list_users.py`
- [User domain services](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/common/services/user.py): `src/app/core/common/services/user.py`
- [User entity and types](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/common/entities/user.py): `src/app/core/common/entities/user.py`
- [Current-user authorization](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/core/common/authorization/current_user_service.py): `src/app/core/common/authorization/current_user_service.py`

### Authentication

- [Sign-up and session handlers](https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/outbound/auth_ctx/handlers): `src/app/outbound/auth_ctx/handlers`
- [Session service](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/service.py): `src/app/outbound/auth_ctx/service.py`
- [JWT processing](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/jwt_processor.py): `src/app/outbound/auth_ctx/jwt_processor.py`

### Persistence and adapters

- [SQLAlchemy adapters](https://github.com/ivan-borovets/fastapi-clean-example/tree/master/src/app/outbound/adapters): `src/app/outbound/adapters`
- [Session persistence](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/sqla_tx_storage.py): `src/app/outbound/auth_ctx/sqla_tx_storage.py`
- [Authentication user storage](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/outbound/auth_ctx/sqla_user_tx_storage.py): `src/app/outbound/auth_ctx/sqla_user_tx_storage.py`
- [Application wiring](https://github.com/ivan-borovets/fastapi-clean-example/blob/master/src/app/main/ioc/outbound.py): `src/app/main/ioc/outbound.py`

### Other components

- **API client**
- **SQL database**

## Connections

- API client → Root router: sends requests
- Root router → API v1 router: mounts (evidence: `src/app/inbound/http/root_router.py`)
- Root router → Health routes: mounts (evidence: `src/app/inbound/http/root_router.py`)
- API v1 router → Account routes: mounts (evidence: `src/app/inbound/http/api_v1_router.py`)
- API v1 router → User routes: mounts (evidence: `src/app/inbound/http/api_v1_router.py`)
- Account routes → Sign-up and session handlers: routes account actions (evidence: `src/app/inbound/http/account/router.py`)
- User routes → User endpoints: mounts endpoints (evidence: `src/app/inbound/http/users/router.py`)
- Sign-up and session handlers → User domain services: uses user services (evidence: `src/app/outbound/auth_ctx/handlers/sign_up.py`)
- Sign-up and session handlers → Current-user authorization: checks current user (evidence: `src/app/outbound/auth_ctx/handlers/sign_up.py`)
- Sign-up and session handlers → Authentication user storage: uses user storage (evidence: `src/app/outbound/auth_ctx/handlers/sign_up.py`)
- User domain services → User entity and types: builds users (evidence: `src/app/core/common/services/user.py`)
- Current-user authorization → User entity and types: returns user (evidence: `src/app/core/common/authorization/current_user_service.py`)
- Current-user authorization → SQLAlchemy adapters: revokes access
- Session service → JWT processing: processes tokens (evidence: `src/app/outbound/auth_ctx/service.py`)
- Session service → Session persistence: uses session storage (evidence: `src/app/outbound/auth_ctx/service.py`)
- Session persistence → SQL database: reads and writes (evidence: `src/app/outbound/auth_ctx/sqla_tx_storage.py`)
- Authentication user storage → SQL database: reads and writes (evidence: `src/app/outbound/auth_ctx/sqla_user_tx_storage.py`)
- SQLAlchemy adapters → SQL database: persists domain data
- Application wiring → Session service: configures (evidence: `src/app/main/ioc/outbound.py`)
- Application wiring → Session persistence: configures (evidence: `src/app/main/ioc/outbound.py`)
- Application wiring → Authentication user storage: configures (evidence: `src/app/main/ioc/outbound.py`)
