# jod35/fastapi-beyond-crud architecture

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

- Interactive diagram: https://gitdiagram.com/jod35/fastapi-beyond-crud
- Repository: https://github.com/jod35/fastapi-beyond-crud

## Overview

##### Project type and purpose
- This is a backend-only, monolithic REST API service built with FastAPI. It goes beyond basic CRUD by including authentication, background tasks (via Celery), email notifications, and domain modules (books, reviews, tags). It persists data in PostgreSQL (via SQLAlchemy/Alembic) and uses Redis as a broker/cache.

##### File structure
- Top-level artifacts:
- Dockerfile, compose.yml → containerization & orchestration
- alembic.ini + migrations/ → database schema migrations
- runworker.sh + src/celery_tasks.py → Celery worker setup
- requirements.txt → Python dependencies
- src/ → source code
- Inside src/:
- src/auth, src/books, src/reviews, src/tags → feature modules, each with routes, schemas (Pydantic models), and service logic
- src/db/ → database initialization (main.py), ORM models, Redis client
- src/config.py → centralized config (env vars)
- src/middleware.py → API-level middleware
- src/mail.py → email‐sending utility
- src/tests/ → pytest integration & unit tests

##### README for additional insights
- The README confirms the need for PostgreSQL and Redis, details Docker Compose usage, Celery worker startup, and highlights a course focus on advanced FastAPI concepts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client & Orchestration
    Client["Client"]:::external
    subgraph "Orchestration (Docker Compose)"
        direction TB
        FastAPIApp["FastAPI Application"]:::api
        Postgres["PostgreSQL"]:::db
        Redis["Redis (Broker/Cache)"]:::db
        subgraph "Celery Worker"
            direction TB
            CeleryTasks["src/celery_tasks.py"]:::worker
            RunWorker["runworker.sh"]:::worker
        end
    end
    MailServer["SMTP / Mail Server"]:::external

    %% FastAPI Application Internals
    subgraph "FastAPI App"
        direction TB
        Config["src/config.py"]:::api
        Middleware["src/middleware.py"]:::api

        subgraph "Auth Module"
            direction TB
            AuthRouter["Auth Router"]:::api
            AuthService["src/auth/service.py"]:::api
            AuthSchemas["src/auth/schemas.py"]:::api
        end

        subgraph "Books Module"
            direction TB
            BooksRouter["Books Router"]:::api
            BooksService["src/books/service.py"]:::api
            BooksSchemas["src/books/schemas.py"]:::api
        end

        subgraph "Reviews Module"
            direction TB
            ReviewsRouter["Reviews Router"]:::api
            ReviewsService["src/reviews/service.py"]:::api
            ReviewsSchemas["src/reviews/schemas.py"]:::api
        end

        subgraph "Tags Module"
            direction TB
            TagsRouter["Tags Router"]:::api
            TagsService["src/tags/service.py"]:::api
            TagsSchemas["src/tags/schemas.py"]:::api
        end
    end

    %% Database Migrations
    subgraph "Database Migrations"
        direction TB
        AlembicIni["alembic.ini"]:::db
        Migrations["migrations/"]:::db
    end

    %% Relationships
    Client -->|"HTTP/JSON"| FastAPIApp
    FastAPIApp -->|depends on| Config
    FastAPIApp -->|uses| Middleware

    FastAPIApp -->|"routes→services"| AuthRouter
    FastAPIApp -->|"routes→services"| BooksRouter
    FastAPIApp -->|"routes→services"| ReviewsRouter
    FastAPIApp -->|"routes→services"| TagsRouter

    AuthRouter -->|calls| AuthService
    AuthService -->|validates| AuthSchemas

    BooksRouter -->|calls| BooksService
    BooksService -->|validates| BooksSchemas

    ReviewsRouter -->|calls| ReviewsService
    ReviewsService -->|validates| ReviewsSchemas

    TagsRouter -->|calls| TagsService
    TagsService -->|validates| TagsSchemas

    FastAPIApp -->|"SQLAlchemy"| Postgres
    AlembicIni -->|"migrations"| Postgres
    Migrations -->|"migrations"| Postgres

    FastAPIApp -->|"Redis Pub/Sub"| Redis
    FastAPIApp -->|"enqueue tasks"| Redis

    Redis -->|"consume tasks"| CeleryTasks
    RunWorker -->|"launches"| CeleryTasks
    CeleryTasks -->|"SQLAlchemy"| Postgres
    CeleryTasks -->|"uses"| MailServer
    CeleryTasks -->|"uses"| Redis

    %% Click Events
    click FastAPIApp "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/db/main.py"
    click AuthRouter "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/auth/routes.py"
    click BooksRouter "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/books/routes.py"
    click ReviewsRouter "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/reviews/routes.py"
    click TagsRouter "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/tags/routes.py"
    click Middleware "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/middleware.py"
    click Config "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/config.py"
    click Migrations "https://github.com/jod35/fastapi-beyond-crud/tree/main/migrations/"
    click AlembicIni "https://github.com/jod35/fastapi-beyond-crud/blob/main/alembic.ini"
    click CeleryTasks "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/celery_tasks.py"
    click RunWorker "https://github.com/jod35/fastapi-beyond-crud/blob/main/runworker.sh"
    click Postgres "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/db/models.py"
    click Redis "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/db/redis.py"
    click MailServer "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/mail.py"
    click AuthService "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/auth/service.py"
    click BooksService "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/books/service.py"
    click ReviewsService "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/reviews/service.py"
    click TagsService "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/tags/service.py"
    click AuthSchemas "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/auth/schemas.py"
    click BooksSchemas "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/books/schemas.py"
    click ReviewsSchemas "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/reviews/schemas.py"
    click TagsSchemas "https://github.com/jod35/fastapi-beyond-crud/blob/main/src/tags/schemas.py"

    %% Styles
    classDef api fill:#AED6F1,stroke:#21618C,color:#1B2631
    classDef db fill:#A9DFBF,stroke:#1D8348,color:#1B2631
    classDef worker fill:#F5B041,stroke:#B9770E,color:#1B2631
    classDef external fill:#F9E79F,stroke:#B7950B,color:#1B2631
```
