# v13tthnh/mini-blog architecture

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

- Interactive diagram: https://gitdiagram.com/v13tthnh/mini-blog
- Repository: https://github.com/v13tthnh/mini-blog

## Overview

Mini Blog is a FastAPI blog and security-training demo with vulnerable and patched modes. A visitor browses, searches, and opens posts; registered users can create posts and comments, manage profiles, and administrators manage blog content and users. Requests enter through the app’s routers, which delegate business operations to services and render Jinja templates. The README describes SQLite, but the sampled runtime database adapter connects to PostgreSQL. The map uses the shown imports and calls; unsampled route and service behavior is not inferred beyond documented capabilities.

Main entry points: [`database.py`](https://github.com/v13tthnh/mini-blog/blob/main/database.py) (Database adapter), [`main.py`](https://github.com/v13tthnh/mini-blog/blob/main/main.py) (FastAPI app), [`app/utils/security.py`](https://github.com/v13tthnh/mini-blog/blob/main/app/utils/security.py) (Session and CSRF), [`app/services/post_service.py`](https://github.com/v13tthnh/mini-blog/blob/main/app/services/post_service.py) (Posts and comments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["FastAPI app<br/>[main.py]"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_post_routes["Post routes<br/>[posts.py]"]
  node_profile_routes["Profile routes<br/>[profile.py]"]
  node_admin_routes["Admin routes<br/>[admin.py]"]
  node_file_routes["File routes<br/>[files.py]"]
  node_templates["Jinja pages"]
end

subgraph group_domain["Blog and accounts"]
  node_auth_service["Account service<br/>[auth_service.py]"]
  node_post_service["Posts and comments<br/>[post_service.py]"]
  node_profile_service["Profile service<br/>[profile_service.py]"]
  node_admin_service["Admin service<br/>[admin_service.py]"]
end

subgraph group_security["Security controls"]
  node_security["Session and CSRF<br/>[security.py]"]
  node_sanitizer["HTML and filename checks<br/>[sanitize.py]"]
end

subgraph group_persistence["Persistence and files"]
  node_upload_helper["Upload handling<br/>[file_upload.py]"]
  node_file_service["File service<br/>[file_service.py]"]
  node_database["Database adapter<br/>[database.py]"]
  node_postgres[("PostgreSQL")]
  node_uploads[("Uploaded files")]
  node_configuration["Runtime configuration<br/>[config.py]"]
  node_db_setup["Database initialization<br/>[setup_postgres.py]"]
end

node_visitor(("Visitor"))

node_visitor -->|"sends requests"| node_app
node_app -->|"registers router"| node_auth_routes
node_app -->|"registers router"| node_post_routes
node_app -->|"registers router"| node_profile_routes
node_app -->|"registers router"| node_admin_routes
node_app -->|"registers router"| node_file_routes
node_app -->|"initializes database"| node_database
node_auth_routes -->|"delegates account actions"| node_auth_service
node_auth_routes -->|"reads current user"| node_security
node_post_routes -->|"delegates post actions"| node_post_service
node_post_routes -->|"reads user and CSRF"| node_security
node_profile_routes -->|"delegates profile actions"| node_profile_service
node_profile_routes -->|"reads current user"| node_security
node_admin_routes -->|"delegates admin actions"| node_admin_service
node_admin_routes -->|"reads current user"| node_security
node_file_routes -->|"delegates file actions"| node_file_service
node_auth_routes -->|"renders pages"| node_templates
node_post_routes -->|"renders pages"| node_templates
node_auth_service -->|"queries accounts"| node_database
node_auth_service -->|"hashes and signs"| node_security
node_post_service -->|"reads and writes posts"| node_database
node_post_service -->|"checks CSRF"| node_security
node_post_service -->|"cleans content"| node_sanitizer
node_post_service -->|"saves images"| node_upload_helper
node_profile_service -->|"reads and updates users"| node_database
node_profile_service -->|"checks CSRF"| node_security
node_profile_service -->|"saves avatars"| node_upload_helper
node_profile_service -->|"cleans biography"| node_sanitizer
node_admin_service -->|"manages blog records"| node_database
node_upload_helper -->|"checks and secures names"| node_sanitizer
node_upload_helper -->|"uses upload directory"| node_configuration
node_upload_helper -->|"writes uploaded files"| node_uploads
node_database -->|"loads connection settings"| node_configuration
node_database -->|"opens connections"| node_postgres
node_database -->|"runs initialization"| node_db_setup
node_file_service -->|"uses file settings"| node_configuration

click node_app "https://github.com/v13tthnh/mini-blog/blob/main/main.py"
click node_auth_routes "https://github.com/v13tthnh/mini-blog/blob/main/app/routes/auth.py"
click node_post_routes "https://github.com/v13tthnh/mini-blog/blob/main/app/routes/posts.py"
click node_profile_routes "https://github.com/v13tthnh/mini-blog/blob/main/app/routes/profile.py"
click node_admin_routes "https://github.com/v13tthnh/mini-blog/blob/main/app/routes/admin.py"
click node_file_routes "https://github.com/v13tthnh/mini-blog/blob/main/app/routes/files.py"
click node_templates "https://github.com/v13tthnh/mini-blog/tree/main/templates"
click node_auth_service "https://github.com/v13tthnh/mini-blog/blob/main/app/services/auth_service.py"
click node_post_service "https://github.com/v13tthnh/mini-blog/blob/main/app/services/post_service.py"
click node_profile_service "https://github.com/v13tthnh/mini-blog/blob/main/app/services/profile_service.py"
click node_admin_service "https://github.com/v13tthnh/mini-blog/blob/main/app/services/admin_service.py"
click node_security "https://github.com/v13tthnh/mini-blog/blob/main/app/utils/security.py"
click node_sanitizer "https://github.com/v13tthnh/mini-blog/blob/main/app/utils/sanitize.py"
click node_upload_helper "https://github.com/v13tthnh/mini-blog/blob/main/app/utils/file_upload.py"
click node_file_service "https://github.com/v13tthnh/mini-blog/blob/main/app/services/file_service.py"
click node_database "https://github.com/v13tthnh/mini-blog/blob/main/database.py"
click node_uploads "https://github.com/v13tthnh/mini-blog/tree/main/static/uploads"
click node_configuration "https://github.com/v13tthnh/mini-blog/blob/main/config.py"
click node_db_setup "https://github.com/v13tthnh/mini-blog/blob/main/setup_postgres.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_auth_routes,node_post_routes,node_profile_routes,node_admin_routes,node_file_routes,node_templates toneBlue
class node_auth_service,node_post_service,node_profile_service,node_admin_service toneAmber
class node_security,node_sanitizer toneMint
class node_upload_helper,node_file_service,node_database,node_postgres,node_uploads,node_configuration,node_db_setup toneRose
class node_visitor toneIndigo
```

## Components

### Web application

- [FastAPI app](https://github.com/v13tthnh/mini-blog/blob/main/main.py): `main.py`
- [Authentication routes](https://github.com/v13tthnh/mini-blog/blob/main/app/routes/auth.py): `app/routes/auth.py`
- [Post routes](https://github.com/v13tthnh/mini-blog/blob/main/app/routes/posts.py): `app/routes/posts.py`
- [Profile routes](https://github.com/v13tthnh/mini-blog/blob/main/app/routes/profile.py): `app/routes/profile.py`
- [Admin routes](https://github.com/v13tthnh/mini-blog/blob/main/app/routes/admin.py): `app/routes/admin.py`
- [File routes](https://github.com/v13tthnh/mini-blog/blob/main/app/routes/files.py): `app/routes/files.py`
- [Jinja pages](https://github.com/v13tthnh/mini-blog/tree/main/templates): `templates`

### Blog and accounts

- [Account service](https://github.com/v13tthnh/mini-blog/blob/main/app/services/auth_service.py): `app/services/auth_service.py`
- [Posts and comments](https://github.com/v13tthnh/mini-blog/blob/main/app/services/post_service.py): `app/services/post_service.py`
- [Profile service](https://github.com/v13tthnh/mini-blog/blob/main/app/services/profile_service.py): `app/services/profile_service.py`
- [Admin service](https://github.com/v13tthnh/mini-blog/blob/main/app/services/admin_service.py): `app/services/admin_service.py`

### Security controls

- [Session and CSRF](https://github.com/v13tthnh/mini-blog/blob/main/app/utils/security.py): `app/utils/security.py`
- [HTML and filename checks](https://github.com/v13tthnh/mini-blog/blob/main/app/utils/sanitize.py): `app/utils/sanitize.py`

### Persistence and files

- [Upload handling](https://github.com/v13tthnh/mini-blog/blob/main/app/utils/file_upload.py): `app/utils/file_upload.py`
- [File service](https://github.com/v13tthnh/mini-blog/blob/main/app/services/file_service.py): `app/services/file_service.py`
- [Database adapter](https://github.com/v13tthnh/mini-blog/blob/main/database.py): `database.py`
- **PostgreSQL**
- [Uploaded files](https://github.com/v13tthnh/mini-blog/tree/main/static/uploads): `static/uploads`
- [Runtime configuration](https://github.com/v13tthnh/mini-blog/blob/main/config.py): `config.py`
- [Database initialization](https://github.com/v13tthnh/mini-blog/blob/main/setup_postgres.py): `setup_postgres.py`

### Other components

- **Visitor**

## Connections

- Visitor → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → Authentication routes: registers router (evidence: `main.py`)
- FastAPI app → Post routes: registers router (evidence: `main.py`)
- FastAPI app → Profile routes: registers router (evidence: `main.py`)
- FastAPI app → Admin routes: registers router (evidence: `main.py`)
- FastAPI app → File routes: registers router (evidence: `main.py`)
- FastAPI app → Database adapter: initializes database (evidence: `main.py`)
- Authentication routes → Account service: delegates account actions (evidence: `app/routes/auth.py`)
- Authentication routes → Session and CSRF: reads current user (evidence: `app/routes/auth.py`)
- Post routes → Posts and comments: delegates post actions (evidence: `app/routes/posts.py`)
- Post routes → Session and CSRF: reads user and CSRF (evidence: `app/routes/posts.py`)
- Profile routes → Profile service: delegates profile actions (evidence: `app/routes/profile.py`)
- Profile routes → Session and CSRF: reads current user (evidence: `app/routes/profile.py`)
- Admin routes → Admin service: delegates admin actions (evidence: `app/routes/admin.py`)
- Admin routes → Session and CSRF: reads current user (evidence: `app/routes/admin.py`)
- File routes → File service: delegates file actions (evidence: `app/routes/files.py`)
- Authentication routes → Jinja pages: renders pages (evidence: `README.md`)
- Post routes → Jinja pages: renders pages (evidence: `app/routes/posts.py`)
- Account service → Database adapter: queries accounts (evidence: `app/services/auth_service.py`)
- Account service → Session and CSRF: hashes and signs (evidence: `app/services/auth_service.py`)
- Posts and comments → Database adapter: reads and writes posts (evidence: `app/services/post_service.py`)
- Posts and comments → Session and CSRF: checks CSRF (evidence: `app/services/post_service.py`)
- Posts and comments → HTML and filename checks: cleans content (evidence: `app/services/post_service.py`)
- Posts and comments → Upload handling: saves images (evidence: `app/services/post_service.py`)
- Profile service → Database adapter: reads and updates users (evidence: `app/services/profile_service.py`)
- Profile service → Session and CSRF: checks CSRF (evidence: `app/services/profile_service.py`)
- Profile service → Upload handling: saves avatars (evidence: `app/services/profile_service.py`)
- Profile service → HTML and filename checks: cleans biography (evidence: `app/services/profile_service.py`)
- Admin service → Database adapter: manages blog records (evidence: `app/services/admin_service.py`)
- Upload handling → HTML and filename checks: checks and secures names (evidence: `app/utils/file_upload.py`)
- Upload handling → Runtime configuration: uses upload directory (evidence: `app/utils/file_upload.py`)
- Upload handling → Uploaded files: writes uploaded files (evidence: `app/utils/file_upload.py`)
- Database adapter → Runtime configuration: loads connection settings (evidence: `database.py`)
- Database adapter → PostgreSQL: opens connections (evidence: `database.py`)
- Database adapter → Database initialization: runs initialization (evidence: `database.py`)
- File service → Runtime configuration: uses file settings (evidence: `app/services/file_service.py`)
