# kabirul/python-fastapi-postgresql-crud-example architecture

> Architecture diagram of the GitHub repository kabirul/python-fastapi-postgresql-crud-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kabirul/python-fastapi-postgresql-crud-example
- Repository: https://github.com/kabirul/python-fastapi-postgresql-crud-example

## Overview

##### Project type and purpose
- This is a standalone backend microservice built with Python’s FastAPI framework.
- It exposes a RESTful CRUD API for managing “blogs” (notes), backed by a PostgreSQL database.
- It also auto-generates OpenAPI docs (Swagger at `/docs`, Redoc at `/redoc`).

##### File structure
- Top-level files:
- `requirements.txt` – Python dependencies (FastAPI, SQLAlchemy/Databases, Uvicorn, etc.).
- `README.md` – run instructions and endpoints.
- `app/main.py` – the FastAPI application instantiation and server setup.
- `app/db.py` – database connection, session management, Base model metadata.
- `app/api/api.py` – FastAPI router(s) registration.
- `app/api/models/blog.py` – ORM/Pydantic schemas for the Blog entity.
- `app/api/crud/blog.py` – data-access layer: create/read/update/delete operations.
- `app/api/endpoints/blogs.py` – HTTP endpoint handlers wiring routes to CRUD functions.

##### README for additional insights
- Shows the base API URL: `http://localhost:8000/api/blogs`.
- Mentions docs at `/docs` and `/redoc`.
- Launch via Uvicorn with hot-reload, single worker.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Browser/REST Client)"]:::external

    subgraph "HTTP/ASGI Layer"
        Uvicorn["Uvicorn ASGI Server"]:::asgi
        FastAPIApp["FastAPI Application"]:::asgi
    end

    subgraph "API Layer"
        Router["API Router"]:::asgi
        Endpoints["BlogEndpoints"]:::business
    end

    subgraph "Business Logic Layer"
        CRUD["BlogCRUD"]:::business
        Models["Blog Models"]:::business
    end

    subgraph "Persistence Layer"
        DBSession["DB Connection & Session"]:::persistence
        Postgres["PostgreSQL Database"]:::persistence
    end

    Swagger["Swagger UI (/docs)"]:::external
    Redoc["Redoc (/redoc)"]:::external
    Requirements["requirements.txt"]:::external

    Client -->|Sends HTTP Request| Uvicorn
    Uvicorn -->|Forwards Request| FastAPIApp
    FastAPIApp -->|Routes to| Router
    Router -->|Calls| Endpoints
    Endpoints -->|Uses| CRUD
    Endpoints -->|Uses| Models
    CRUD -->|Opens Session| DBSession
    DBSession -->|Queries| Postgres

    FastAPIApp -->|Generates Docs| Swagger
    FastAPIApp -->|Generates Docs| Redoc

    click Uvicorn "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/app/main.py"
    click FastAPIApp "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/app/main.py"
    click Router "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/app/api/api.py"
    click Endpoints "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/app/api/endpoints/blogs.py"
    click CRUD "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/app/api/crud/blog.py"
    click Models "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/app/api/models/blog.py"
    click DBSession "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/app/db.py"
    click Requirements "https://github.com/kabirul/python-fastapi-postgresql-crud-example/blob/main/requirements.txt"

    classDef asgi fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef business fill:#FFA500,stroke:#333,stroke-width:1px
    classDef persistence fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
