# jagadish210523-lgtm/fastapi-with-mysql architecture

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

- Interactive diagram: https://gitdiagram.com/jagadish210523-lgtm/fastapi-with-mysql
- Repository: https://github.com/jagadish210523-lgtm/fastapi-with-mysql

## Overview

This is a small FastAPI service for creating, listing, retrieving, updating, and deleting posts stored in MySQL. A client sends requests to the post endpoints; each endpoint uses a dependency-provided SQLAlchemy session to query or modify mapped post records, then returns results (or a not-found error). On startup, the application creates mapped tables. The source defines a User model, but no user endpoints or relationship are shown; user_id is stored as an integer. The graph reflects the supplied source excerpts.

Main entry points: [`main.py`](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/main.py) (Post endpoints), [`database.py`](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/database.py) (SQLAlchemy engine), [`models.py`](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/models.py) (Post ORM model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_posts_api["Post endpoints<br/>[main.py]"]
  node_post_schema["Post request schema<br/>[main.py]"]
end

subgraph group_persistence["Persistence"]
  node_db_dependency["DB session dependency<br/>[main.py]"]
  node_session_factory["Session factory<br/>[database.py]"]
  node_engine["SQLAlchemy engine<br/>[database.py]"]
  node_post_model["Post ORM model<br/>[models.py]"]
  node_user_model["User ORM model<br/>[models.py]"]
end

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

node_client -->|"sends requests"| node_posts_api
node_posts_api -->|"returns results"| node_client
node_posts_api -->|"validates input"| node_post_schema
node_posts_api -->|"depends on"| node_db_dependency
node_db_dependency -->|"creates session"| node_session_factory
node_session_factory -->|"binds to"| node_engine
node_posts_api -->|"queries and mutates"| node_post_model
node_engine -->|"executes database operations"| node_mysql
node_posts_api -->|"creates tables at startup"| node_engine

click node_posts_api "https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/main.py"
click node_post_schema "https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/main.py"
click node_db_dependency "https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/main.py"
click node_session_factory "https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/database.py"
click node_engine "https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/database.py"
click node_post_model "https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/models.py"
click node_user_model "https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/models.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_posts_api,node_post_schema,node_client toneBlue
class node_db_dependency,node_session_factory,node_engine,node_post_model,node_user_model,node_mysql toneAmber
```

## Components

### HTTP API

- [Post endpoints](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/main.py): `main.py`
- [Post request schema](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/main.py): `main.py`

### Persistence

- [DB session dependency](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/main.py): `main.py`
- [Session factory](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/database.py): `database.py`
- [SQLAlchemy engine](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/database.py): `database.py`
- [Post ORM model](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/models.py): `models.py`
- [User ORM model](https://github.com/jagadish210523-lgtm/fastapi-with-mysql/blob/main/models.py): `models.py`

### Other components

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

## Connections

- API client → Post endpoints: sends requests
- Post endpoints → API client: returns results
- Post endpoints → Post request schema: validates input
- Post endpoints → DB session dependency: depends on
- DB session dependency → Session factory: creates session
- Session factory → SQLAlchemy engine: binds to
- Post endpoints → Post ORM model: queries and mutates
- SQLAlchemy engine → MySQL database: executes database operations
- Post endpoints → SQLAlchemy engine: creates tables at startup
