# sumanentc/fastapi-celery-rabbitmq-application architecture

> Architecture diagram of the GitHub repository sumanentc/fastapi-celery-rabbitmq-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sumanentc/fastapi-celery-rabbitmq-application
- Repository: https://github.com/sumanentc/fastapi-celery-rabbitmq-application

## Overview

##### Project type and purpose
- This is a backend API application demonstrating an asynchronous architecture using FastAPI for HTTP request handling and Celery (with RabbitMQ as broker/backend) for background task processing. There is no separate “frontend” beyond the automatically generated Swagger UI.

##### File structure
- Top-level scripts and configs:
- main.py – Entry point that creates the FastAPI app and wires up Celery
- Pipfile / requirements.txt – Dependency / environment management
- Directories:
- api/ – Core business-logic functions (e.g., universities.py)
- routers/ – FastAPI route definitions pointing to api functions
- schemas/ – Pydantic models for request/response validation
- celery_tasks/ – Celery task definitions calling api functions asynchronously
- config/ – Celery configuration and helper utilities
- No database folder—so persistence is external or out of scope; RabbitMQ doubles as broker and result backend.

##### Insights from the README
- Components: FastAPI app, Celery workers, RabbitMQ broker/backend, optional Flower UI for monitoring

##### Relationships and data flow
- Client → HTTP POST/GET → FastAPI endpoint
- FastAPI enqueues Celery task via Celery client (configured to use RabbitMQ)
- Task message → RabbitMQ queue
- Celery worker consumes from queue → executes task (calls into api/)
- On completion, Celery stores result back in RabbitMQ backend
- FastAPI can poll or retrieve the result by task ID
- Flower subscribes to RabbitMQ to display task status

##### Architectural patterns and principles
- Asynchronous, decoupled processing using message queue (push-based)
- Single responsibility: routers handle HTTP, api modules handle logic, celery_tasks handle async wrappers, config modules handle settings
- Pydantic models for schema validation (type-safe contracts)
- Clear separation between sync (FastAPI) and async (Celery) components

##### Technologies & libraries
- FastAPI (uvicorn)
- Celery (task queue)
- RabbitMQ (broker & backend)
- Flower (monitoring)
- Pydantic (schemas)
- Pipenv (environment)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Client["HTTP Client / Swagger UI"]:::client

    %% Dependency Management
    subgraph "Dependencies"
        Pipfile["Pipfile"]:::service
        Requirements["requirements.txt"]:::service
    end

    %% FastAPI Service
    subgraph "FastAPI Service"
        FastAPI["FastAPI App (main.py)"]:::service
        Routers["Routers (routers/universities.py)"]:::service
        API["API Logic (api/universities.py)"]:::service
        Schemas["Schemas (schemas/schemas.py)"]:::service
    end

    %% Celery Configuration
    subgraph "Celery Configuration"
        CeleryConfig["Celery Config (config/celery_config.py)"]:::service
        CeleryUtils["Celery Utils (config/celery_utils.py)"]:::service
    end

    %% Message Broker
    RabbitMQ["RabbitMQ Broker/Backend"]:::messageBroker

    %% Celery Workers
    subgraph "Celery Workers"
        Tasks["Celery Tasks (celery_tasks/tasks.py)"]:::worker
    end

    %% Monitoring
    Flower["Flower UI"]:::monitor

    %% Data Flow
    Client -->|"HTTP Request"| FastAPI
    FastAPI -->|"Enqueue Task (AMQP)"| RabbitMQ
    RabbitMQ -->|"Consume Task"| Tasks
    Tasks -->|"Store Result"| RabbitMQ
    RabbitMQ -->|"Retrieve Result"| FastAPI
    Flower -->|"Monitor Tasks"| RabbitMQ

    %% Click Events
    click FastAPI "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/main.py"
    click Routers "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/routers/universities.py"
    click API "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/api/universities.py"
    click Schemas "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/schemas/schemas.py"
    click CeleryConfig "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/config/celery_config.py"
    click CeleryUtils "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/config/celery_utils.py"
    click Tasks "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/celery_tasks/tasks.py"
    click Pipfile "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/tree/master/Pipfile"
    click Requirements "https://github.com/sumanentc/fastapi-celery-rabbitmq-application/blob/master/requirements.txt"

    %% Styles
    classDef service fill:#f9f,stroke:#333,stroke-width:1px
    classDef messageBroker fill:#ff9,stroke:#333,stroke-width:1px
    classDef worker fill:#9f9,stroke:#333,stroke-width:1px
    classDef client fill:#9ff,stroke:#333,stroke-width:1px
    classDef monitor fill:#f99,stroke:#333,stroke-width:1px
```
