# saranshkala/blog-api architecture

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

- Interactive diagram: https://gitdiagram.com/saranshkala/blog-api
- Repository: https://github.com/saranshkala/blog-api

## Overview

This is a FastAPI blog API. Clients register or log in, receive a JWT, then use user, post, and comment endpoints; protected operations resolve the caller and enforce ownership before returning validated responses or changing relational state. Route handlers contain the database logic directly. The graph reflects the sampled handlers and documented API surface; the README documents interactive Swagger UI and startup table creation, but migration tooling is absent.

Main entry points: [`app/main.py`](https://github.com/saranshkala/blog-api/blob/main/app/main.py) (FastAPI app), [`app/database.py`](https://github.com/saranshkala/blog-api/blob/main/app/database.py) (DB session and engine), [`app/routers/users.py`](https://github.com/saranshkala/blog-api/blob/main/app/routers/users.py) (User routes), [`app/routers/posts.py`](https://github.com/saranshkala/blog-api/blob/main/app/routers/posts.py) (Post routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API surface"]
  node_app["FastAPI app<br/>[main.py]"]
  node_users["User routes<br/>[users.py]"]
  node_posts["Post routes<br/>[posts.py]"]
  node_comments["Comment routes<br/>[comments.py]"]
  node_docs["Swagger UI<br/>[main.py]"]
end

subgraph group_identity["Identity and validation"]
  node_auth["JWT auth<br/>[oauth2.py]"]
  node_schemas["Request response schemas<br/>[schemas.py]"]
end

subgraph group_data["Relational data"]
  node_db["DB session and engine<br/>[database.py]"]
  node_models["User post comment models<br/>[models.py]"]
  node_postgres[("PostgreSQL")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"registers router"| node_users
node_app -->|"registers router"| node_posts
node_app -->|"registers router"| node_comments
node_users -->|"opens session"| node_db
node_posts -->|"opens session"| node_db
node_comments -->|"opens session"| node_db
node_users -->|"queries and mutates"| node_models
node_posts -->|"queries and mutates"| node_models
node_comments -->|"queries and mutates"| node_models
node_users -->|"issues and resolves tokens"| node_auth
node_posts -->|"resolves caller"| node_auth
node_comments -->|"resolves caller"| node_auth
node_auth -->|"loads user"| node_db
node_auth -->|"loads User"| node_models
node_users -->|"validates and shapes"| node_schemas
node_posts -->|"validates and shapes"| node_schemas
node_comments -->|"validates and shapes"| node_schemas
node_db -->|"connects and persists"| node_postgres
node_models -->|"defines relational tables"| node_postgres
node_app -->|"exposes API docs"| node_docs
node_app -->|"creates tables at startup"| node_db

click node_app "https://github.com/saranshkala/blog-api/blob/main/app/main.py"
click node_users "https://github.com/saranshkala/blog-api/blob/main/app/routers/users.py"
click node_posts "https://github.com/saranshkala/blog-api/blob/main/app/routers/posts.py"
click node_comments "https://github.com/saranshkala/blog-api/blob/main/app/routers/comments.py"
click node_auth "https://github.com/saranshkala/blog-api/blob/main/app/oauth2.py"
click node_schemas "https://github.com/saranshkala/blog-api/blob/main/app/schemas.py"
click node_db "https://github.com/saranshkala/blog-api/blob/main/app/database.py"
click node_models "https://github.com/saranshkala/blog-api/blob/main/app/models.py"
click node_docs "https://github.com/saranshkala/blog-api/blob/main/app/main.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_users,node_posts,node_comments,node_docs,node_client toneBlue
class node_auth,node_schemas toneAmber
class node_db,node_models,node_postgres toneMint
```

## Components

### API surface

- [FastAPI app](https://github.com/saranshkala/blog-api/blob/main/app/main.py): `app/main.py`
- [User routes](https://github.com/saranshkala/blog-api/blob/main/app/routers/users.py): `app/routers/users.py`
- [Post routes](https://github.com/saranshkala/blog-api/blob/main/app/routers/posts.py): `app/routers/posts.py`
- [Comment routes](https://github.com/saranshkala/blog-api/blob/main/app/routers/comments.py): `app/routers/comments.py`
- [Swagger UI](https://github.com/saranshkala/blog-api/blob/main/app/main.py): `app/main.py`

### Identity and validation

- [JWT auth](https://github.com/saranshkala/blog-api/blob/main/app/oauth2.py): `app/oauth2.py`
- [Request response schemas](https://github.com/saranshkala/blog-api/blob/main/app/schemas.py): `app/schemas.py`

### Relational data

- [DB session and engine](https://github.com/saranshkala/blog-api/blob/main/app/database.py): `app/database.py`
- [User post comment models](https://github.com/saranshkala/blog-api/blob/main/app/models.py): `app/models.py`
- **PostgreSQL**

### Other components

- **API client**

## Connections

- API client → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → User routes: registers router (evidence: `app/main.py`)
- FastAPI app → Post routes: registers router (evidence: `app/main.py`)
- FastAPI app → Comment routes: registers router (evidence: `app/main.py`)
- User routes → DB session and engine: opens session (evidence: `app/routers/users.py`)
- Post routes → DB session and engine: opens session (evidence: `app/routers/posts.py`)
- Comment routes → DB session and engine: opens session (evidence: `app/routers/comments.py`)
- User routes → User post comment models: queries and mutates (evidence: `app/routers/users.py`)
- Post routes → User post comment models: queries and mutates (evidence: `app/routers/posts.py`)
- Comment routes → User post comment models: queries and mutates (evidence: `app/routers/comments.py`)
- User routes → JWT auth: issues and resolves tokens (evidence: `app/routers/users.py`)
- Post routes → JWT auth: resolves caller (evidence: `app/routers/posts.py`)
- Comment routes → JWT auth: resolves caller (evidence: `app/routers/comments.py`)
- JWT auth → DB session and engine: loads user (evidence: `app/oauth2.py`)
- JWT auth → User post comment models: loads User (evidence: `app/oauth2.py`)
- User routes → Request response schemas: validates and shapes (evidence: `app/routers/users.py`)
- Post routes → Request response schemas: validates and shapes (evidence: `app/routers/posts.py`)
- Comment routes → Request response schemas: validates and shapes (evidence: `app/routers/comments.py`)
- DB session and engine → PostgreSQL: connects and persists (evidence: `README.md`)
- User post comment models → PostgreSQL: defines relational tables (evidence: `app/models.py`)
- FastAPI app → Swagger UI: exposes API docs (evidence: `README.md`)
- FastAPI app → DB session and engine: creates tables at startup (evidence: `README.md`)
