# mithgal-jh/fastapi_training_project architecture

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

- Interactive diagram: https://gitdiagram.com/mithgal-jh/fastapi_training_project
- Repository: https://github.com/mithgal-jh/fastapi_training_project

## Overview

##### Project type and purpose
- This is a backend‐only RESTful API service built with FastAPI, whose sole responsibility is to serve as the backend for a Blog Management System.
- Purpose: allow users to register, authenticate (JWT/OAuth2), and perform CRUD operations on blog posts, following clean architecture and the Repository Pattern.

##### File structure
- Top‐level:
- main.py (entry stub)
- requirements.txt
- app/ (all application code)
- app/ contains:
- main.py – mounts FastAPI instance and routers
- database.py – SQLAlchemy engine & session setup (SQLite default)
- models.py – ORM entity definitions (User, Blog with 1-to-many relationship)
- schemas.py – Pydantic request/response models
- hashing.py – Passlib BCrypt hashing utility
- JWTtoken.py & oauth2.py – JWT creation/validation & OAuth2 dependency
- repository/ – business logic and DB CRUD operations (repository pattern)
- routers/ – APIRouter modules for user, blog, authentication endpoints

##### README for insights
- Emphasizes:
- Clean separation of concerns using the Repository Pattern.
- Security via JWT and OAuth2 password grant.
- Data validation with Pydantic.
- CRUD implementation with SQLAlchemy.
- Interactive docs via Swagger UI / ReDoc.

- Clear labels for every component (e.g., “Auth Router”, “Blog Repository”, “SQLite DB”)
- Blue for FastAPI layers (API Gateway, Routers)
- Green for Business Logic (Repository modules)
- Orange for Security (Hashing, JWT, OAuth2)
- Gray for Data Models & Database

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client (Postman / Swagger UI)"]:::external

    %% Entry Layer
    subgraph "Entry Layer"
        EntryStub["main.py (launch script)"]:::api
    end

    %% API Gateway Layer
    subgraph "API Gateway (FastAPI)"
        FastAPIApp["app/main.py"]:::api
        Docs["/docs & /redoc"]:::api
    end

    %% Routers Layer
    subgraph "Routers Layer" 
        AuthRouter["Authentication Router"]:::api
        UserRouter["User Router"]:::api
        BlogRouter["Blog Router"]:::api
    end

    %% Security Layer
    subgraph "Security Layer"
        HashUtil["hashing.py"]:::security
        JWTService["JWTtoken.py"]:::security
        OAuth2Dep["oauth2.py"]:::security
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        UserRepo["user.py"]:::repo
        BlogRepo["blog.py"]:::repo
    end

    %% Data Models & Persistence
    subgraph "Data Layer"
        DBConfig["app/database.py"]:::data
        ORMModels["app/models.py"]:::data
        Schemas["app/schemas.py"]:::data
        SQLiteDB["SQLite Database"]:::data
    end

    %% Documentation & Config
    subgraph "Project Files"
        Requirements["requirements.txt"]:::external
        Gitignore[".gitignore"]:::external
        Readme["README.md"]:::external
    end

    %% Connections
    Client -->|HTTPS Request| FastAPIApp
    EntryStub --> FastAPIApp
    FastAPIApp --> Docs
    FastAPIApp --> AuthRouter
    FastAPIApp --> UserRouter
    FastAPIApp --> BlogRouter

    AuthRouter -->|depends on| OAuth2Dep
    AuthRouter -->|calls| HashUtil
    AuthRouter -->|calls| JWTService

    UserRouter -->|calls| UserRepo
    BlogRouter -->|calls| BlogRepo

    UserRepo --> ORMModels
    BlogRepo --> ORMModels
    ORMModels --> SQLiteDB
    DBConfig --> SQLiteDB

    UserRepo --> Schemas
    BlogRepo --> Schemas
    Schemas --> FastAPIApp

    %% Click Events
    click FastAPIApp "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/main.py"
    click EntryStub "https://github.com/mithgal-jh/fastapi_training_project/blob/main/main.py"
    click DBConfig "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/database.py"
    click ORMModels "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/models.py"
    click Schemas "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/schemas.py"
    click HashUtil "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/hashing.py"
    click JWTService "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/JWTtoken.py"
    click OAuth2Dep "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/oauth2.py"
    click AuthRouter "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/routers/authentication.py"
    click UserRouter "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/routers/user.py"
    click BlogRouter "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/routers/blog.py"
    click UserRepo "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/repository/user.py"
    click BlogRepo "https://github.com/mithgal-jh/fastapi_training_project/blob/main/app/repository/blog.py"
    click Requirements "https://github.com/mithgal-jh/fastapi_training_project/blob/main/requirements.txt"
    click Gitignore "https://github.com/mithgal-jh/fastapi_training_project/blob/main/.gitignore"
    click Readme "https://github.com/mithgal-jh/fastapi_training_project/blob/main/README.md"

    %% Styles
    classDef api fill:#cce5ff,stroke:#3399ff,stroke-width:1px
    classDef repo fill:#d4edda,stroke:#28a745,stroke-width:1px
    classDef security fill:#fff3cd,stroke:#ffcd39,stroke-width:1px
    classDef data fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef external fill:#f0f9ff,stroke:#66b2ff,stroke-width:1px
```
