# nexarobs/first-fastapi-project architecture

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

- Interactive diagram: https://gitdiagram.com/nexarobs/first-fastapi-project
- Repository: https://github.com/nexarobs/first-fastapi-project

## Overview

This is a small FastAPI CRUD backend for user records. An API client reaches the registered `/users` routes, which validate and format requests and responses with Pydantic schemas, obtain a database session, and call controller functions for listing, reading, creating, updating, or deleting users. The controller queries or changes the SQLAlchemy User model; the model is mapped to the users table, and the database engine is configured from environment settings for MySQL. The README documents MySQL setup and the API entry point; the graph focuses on the user workflow and its persistence dependencies.

Main entry points: [`app/api/routes/user_route.py`](https://github.com/nexarobs/first-fastapi-project/blob/main/app/api/routes/user_route.py) (User routes), [`app/db/db.py`](https://github.com/nexarobs/first-fastapi-project/blob/main/app/db/db.py) (DB engine setup), [`app/controllers/user_controller.py`](https://github.com/nexarobs/first-fastapi-project/blob/main/app/controllers/user_controller.py) (User controller), [`app/models/user_model.py`](https://github.com/nexarobs/first-fastapi-project/blob/main/app/models/user_model.py) (User model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API layer"]
  node_app["FastAPI app<br/>[main.py]"]
  node_user_routes["User routes<br/>[user_route.py]"]
  node_schemas["User schemas<br/>[user_schema.py]"]
end

subgraph group_domain["User domain"]
  node_controller["User controller<br/>[user_controller.py]"]
  node_user_model["User model<br/>[user_model.py]"]
end

subgraph group_persistence["Persistence"]
  node_sessions["DB sessions<br/>[sessions.py]"]
  node_db_setup["DB engine setup<br/>[db.py]"]
  node_config["DB settings<br/>[config.py]"]
end

node_client(("API client"))
node_mysql[("MySQL database")]

node_client -->|"calls endpoints"| node_user_routes
node_app -->|"registers router"| node_user_routes
node_user_routes -->|"calls CRUD"| node_controller
node_user_routes -->|"validates and formats"| node_schemas
node_user_routes -->|"injects session"| node_sessions
node_controller -->|"queries and changes"| node_user_model
node_user_model -->|"uses declarative base"| node_db_setup
node_sessions -->|"creates sessions"| node_db_setup
node_db_setup -->|"reads settings"| node_config
node_db_setup -->|"connects to"| node_mysql

click node_app "https://github.com/nexarobs/first-fastapi-project/blob/main/app/main.py"
click node_user_routes "https://github.com/nexarobs/first-fastapi-project/blob/main/app/api/routes/user_route.py"
click node_schemas "https://github.com/nexarobs/first-fastapi-project/blob/main/app/schemas/user_schema.py"
click node_controller "https://github.com/nexarobs/first-fastapi-project/blob/main/app/controllers/user_controller.py"
click node_user_model "https://github.com/nexarobs/first-fastapi-project/blob/main/app/models/user_model.py"
click node_sessions "https://github.com/nexarobs/first-fastapi-project/blob/main/app/dependencies/sessions.py"
click node_db_setup "https://github.com/nexarobs/first-fastapi-project/blob/main/app/db/db.py"
click node_config "https://github.com/nexarobs/first-fastapi-project/blob/main/app/core/config.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_app,node_user_routes,node_schemas,node_client toneBlue
class node_controller,node_user_model,node_mysql toneAmber
class node_sessions,node_db_setup,node_config toneMint
```

## Components

### API layer

- [FastAPI app](https://github.com/nexarobs/first-fastapi-project/blob/main/app/main.py): `app/main.py`
- [User routes](https://github.com/nexarobs/first-fastapi-project/blob/main/app/api/routes/user_route.py): `app/api/routes/user_route.py`
- [User schemas](https://github.com/nexarobs/first-fastapi-project/blob/main/app/schemas/user_schema.py): `app/schemas/user_schema.py`

### User domain

- [User controller](https://github.com/nexarobs/first-fastapi-project/blob/main/app/controllers/user_controller.py): `app/controllers/user_controller.py`
- [User model](https://github.com/nexarobs/first-fastapi-project/blob/main/app/models/user_model.py): `app/models/user_model.py`

### Persistence

- [DB sessions](https://github.com/nexarobs/first-fastapi-project/blob/main/app/dependencies/sessions.py): `app/dependencies/sessions.py`
- [DB engine setup](https://github.com/nexarobs/first-fastapi-project/blob/main/app/db/db.py): `app/db/db.py`
- [DB settings](https://github.com/nexarobs/first-fastapi-project/blob/main/app/core/config.py): `app/core/config.py`

### Other components

- **API client**
- **MySQL database**

## Connections

- API client → User routes: calls endpoints (evidence: `Readme.md`)
- FastAPI app → User routes: registers router (evidence: `app/main.py`)
- User routes → User controller: calls CRUD (evidence: `app/api/routes/user_route.py`)
- User routes → User schemas: validates and formats (evidence: `app/api/routes/user_route.py`)
- User routes → DB sessions: injects session (evidence: `app/api/routes/user_route.py`)
- User controller → User model: queries and changes (evidence: `app/controllers/user_controller.py`)
- User model → DB engine setup: uses declarative base (evidence: `app/models/user_model.py`)
- DB sessions → DB engine setup: creates sessions (evidence: `app/dependencies/sessions.py`)
- DB engine setup → DB settings: reads settings (evidence: `app/db/db.py`)
- DB engine setup → MySQL database: connects to (evidence: `Readme.md`)
