# samanwaya938/fastapi_tutorial architecture

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

- Interactive diagram: https://gitdiagram.com/samanwaya938/fastapi_tutorial
- Repository: https://github.com/samanwaya938/fastapi_tutorial
- Video tour (about a minute): https://gitdiagram.com/samanwaya938/fastapi_tutorial/video

## Overview

This repository is a collection of small FastAPI tutorial examples rather than one integrated service: a greeting/student API, two book APIs, and an authentication API. The user-facing workflows are HTTP requests handled by each example; book operations either mutate an in-memory catalog or use SQLAlchemy, while authentication supports signup, login, bearer-token validation, and role-restricted routes. The graph keeps these examples separate. Source excerpts show the principal calls and persistence setup; the README provides no additional capability detail.

Main entry points: [`auth/main.py`](https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/main.py) (Auth and access routes), [`project.py`](https://github.com/samanwaya938/fastapi_tutorial/blob/main/project.py) (SQL book API), [`crud.py`](https://github.com/samanwaya938/fastapi_tutorial/blob/main/crud.py) (Book CRUD API), [`auth/auth_database.py`](https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/auth_database.py) (Auth database setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_basic["Basic API"]
  node_greeting_api["Greeting and student API<br/>[main.py]"]
end

subgraph group_books["Book APIs"]
  node_book_crud_api["Book CRUD API<br/>[crud.py]"]
  node_memory_catalog[("In-memory catalog<br/>[crud.py]")]
  node_sql_book_api["SQL book API<br/>[project.py]"]
end

subgraph group_auth["Authentication"]
  node_auth_api["Auth and access routes<br/>[main.py]"]
  node_user_schemas["User schemas<br/>[schemas.py]"]
  node_user_model["User model<br/>[models.py]"]
  node_password_utils["Password hashing<br/>[utils.py]"]
  node_auth_database["Auth database setup<br/>[auth_database.py]"]
end

subgraph group_storage["Persistence"]
  node_book_model["Book model<br/>[model.py]"]
  node_app_database["SQL database setup<br/>[database.py]"]
end

node_caller(("API caller"))
node_mysql[("MySQL database")]

node_caller -->|"sends requests"| node_greeting_api
node_caller -->|"sends requests"| node_book_crud_api
node_caller -->|"sends requests"| node_sql_book_api
node_caller -->|"sends requests"| node_auth_api
node_book_crud_api -->|"reads and mutates"| node_memory_catalog
node_sql_book_api -->|"gets sessions"| node_app_database
node_sql_book_api -->|"queries and creates"| node_book_model
node_app_database -->|"connects to"| node_mysql
node_auth_api -->|"validates input"| node_user_schemas
node_auth_api -->|"queries and saves"| node_user_model
node_auth_api -->|"hashes and verifies"| node_password_utils
node_auth_api -->|"gets sessions"| node_auth_database
node_auth_database -->|"connects to"| node_mysql

click node_greeting_api "https://github.com/samanwaya938/fastapi_tutorial/blob/main/main.py"
click node_book_crud_api "https://github.com/samanwaya938/fastapi_tutorial/blob/main/crud.py"
click node_memory_catalog "https://github.com/samanwaya938/fastapi_tutorial/blob/main/crud.py"
click node_sql_book_api "https://github.com/samanwaya938/fastapi_tutorial/blob/main/project.py"
click node_book_model "https://github.com/samanwaya938/fastapi_tutorial/blob/main/model.py"
click node_app_database "https://github.com/samanwaya938/fastapi_tutorial/blob/main/database.py"
click node_auth_api "https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/main.py"
click node_user_schemas "https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/schemas.py"
click node_user_model "https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/models.py"
click node_password_utils "https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/utils.py"
click node_auth_database "https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/auth_database.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_greeting_api toneBlue
class node_book_crud_api,node_memory_catalog,node_sql_book_api,node_mysql toneAmber
class node_auth_api,node_user_schemas,node_user_model,node_password_utils,node_auth_database,node_caller toneMint
class node_book_model,node_app_database toneRose
```

## Components

### Basic API

- [Greeting and student API](https://github.com/samanwaya938/fastapi_tutorial/blob/main/main.py): `main.py`

### Book APIs

- [Book CRUD API](https://github.com/samanwaya938/fastapi_tutorial/blob/main/crud.py): `crud.py`
- [In-memory catalog](https://github.com/samanwaya938/fastapi_tutorial/blob/main/crud.py): `crud.py`
- [SQL book API](https://github.com/samanwaya938/fastapi_tutorial/blob/main/project.py): `project.py`

### Authentication

- [Auth and access routes](https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/main.py): `auth/main.py`
- [User schemas](https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/schemas.py): `auth/schemas.py`
- [User model](https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/models.py): `auth/models.py`
- [Password hashing](https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/utils.py): `auth/utils.py`
- [Auth database setup](https://github.com/samanwaya938/fastapi_tutorial/blob/main/auth/auth_database.py): `auth/auth_database.py`

### Persistence

- [Book model](https://github.com/samanwaya938/fastapi_tutorial/blob/main/model.py): `model.py`
- [SQL database setup](https://github.com/samanwaya938/fastapi_tutorial/blob/main/database.py): `database.py`

### Other components

- **API caller**
- **MySQL database**

## Connections

- API caller → Greeting and student API: sends requests (evidence: `main.py`)
- API caller → Book CRUD API: sends requests (evidence: `crud.py`)
- API caller → SQL book API: sends requests (evidence: `project.py`)
- API caller → Auth and access routes: sends requests (evidence: `auth/main.py`)
- Book CRUD API → In-memory catalog: reads and mutates (evidence: `crud.py`)
- SQL book API → SQL database setup: gets sessions (evidence: `project.py`)
- SQL book API → Book model: queries and creates (evidence: `project.py`)
- SQL database setup → MySQL database: connects to (evidence: `database.py`)
- Auth and access routes → User schemas: validates input (evidence: `auth/main.py`)
- Auth and access routes → User model: queries and saves (evidence: `auth/main.py`)
- Auth and access routes → Password hashing: hashes and verifies (evidence: `auth/main.py`)
- Auth and access routes → Auth database setup: gets sessions (evidence: `auth/main.py`)
- Auth database setup → MySQL database: connects to (evidence: `auth/auth_database.py`)
