# ch4zzy/checks-api architecture

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

- Interactive diagram: https://gitdiagram.com/ch4zzy/checks-api
- Repository: https://github.com/ch4zzy/checks-api

## Overview

##### Project type and purpose
- This is a Django-based backend microservice (“Checks API”) whose sole responsibility is to accept new order data via REST endpoints, create “check” records for each printer at a given location, and asynchronously generate PDF receipts.
- Key indicators:
- apps/reciept: Django app with models, serializers, views, templates (PDF).
- config/celery.py + tasks.py: Asynchronous PDF generation.
- Dockerfile / docker-compose.yml: Containerized deployment.

##### File structure
- Top-level:
- apps/reciept: Core Django app: models.py, serializers.py, views.py, urls.py, tasks.py, templates/pdf_template.html.
- config: Django settings, URL routing, WSGI, Celery config, custom storage backends, media dirs.
- manage.py, Dockerfile, docker-compose.yml: orchestration and containerization.
- .github/workflows: CI for linting, tests, migrations.
- Patterns:
- MVC (Django’s MTV): models ↔ views ↔ templates.
- Asynchronous worker pattern (Celery + broker).
- PDF generation via HTML template and storage backend.

##### README for additional insights
- Defines REST endpoints for listing, retrieving, updating “checks,” and creating them.
- Describes error-handling rules when no printers exist or if checks already created.
- Notes pytest-django integration.

##### Detailed yet focused
- Django component: APIView/Serializer → Model → Task
- Template rendering → PDF file path registration
- Error-path checks (e.g., “No printers → API returns 400”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client Application"]:::external
    Client -->|"HTTP Request"| DjangoApp

    subgraph "Django Application"
        DjangoApp["Django API Service"]:::web
        Model["Check Model"]:::web
        PDFTemp["PDF Template"]:::web
        Settings["Project Settings"]:::web
        WSGI["WSGI Entry Point"]:::web
        Manage["Application Bootstrap"]:::web
    end

    subgraph "Celery Worker"
        CeleryConfig["Celery Configuration"]:::worker
        Tasks["Asynchronous Task Definitions"]:::worker
    end

    subgraph "Infrastructure"
        DB["PostgreSQL Database"]:::data
        Broker["Message Broker (Redis/RabbitMQ)"]:::data
        Storage["Storage Backend"]:::data
        Printers["External Printers"]:::external
    end

    subgraph "CI/CD Pipeline"
       CI["GitHub Actions"]:::external
    end

    %% Flows
    DjangoApp -->|"ORM Reads/Writes"| Model
    DjangoApp -->|"Publishes PDF Task"| Broker
    DjangoApp -->|"Templates Render"| PDFTemp
    DjangoApp -->|"Uses Settings"| Settings
    DjangoApp -->|"Entrypoint"| WSGI
    DjangoApp -->|"manage.py Commands"| Manage

    Broker -->|"Task Message"| Tasks
    CeleryConfig -->|"Broker Integration"| Broker
    Tasks -->|"Generate PDF"| PDFTemp
    Tasks -->|"Store PDF"| Storage
    Tasks -->|"Update Check Record"| DB

    DjangoApp -->|"Validates Printers"| Printers
    Client -->|"Polls Status"| DjangoApp
    Client -->|"Downloads PDF"| Storage

    CI -->|"Runs on Push"| DjangoApp
    CI -->|"Runs on Push"| Tasks

    %% Click events
    click DjangoApp "https://github.com/ch4zzy/checks-api/blob/main/apps/reciept/views.py"
    click DjangoApp "https://github.com/ch4zzy/checks-api/blob/main/apps/reciept/serializers.py"
    click DjangoApp "https://github.com/ch4zzy/checks-api/blob/main/apps/reciept/urls.py"
    click DjangoApp "https://github.com/ch4zzy/checks-api/blob/main/config/urls.py"
    click Model "https://github.com/ch4zzy/checks-api/blob/main/apps/reciept/models.py"
    click PDFTemp "https://github.com/ch4zzy/checks-api/blob/main/apps/reciept/templates/reciept/pdf_template.html"
    click Tasks "https://github.com/ch4zzy/checks-api/blob/main/apps/reciept/tasks.py"
    click CeleryConfig "https://github.com/ch4zzy/checks-api/blob/main/config/celery.py"
    click Storage "https://github.com/ch4zzy/checks-api/blob/main/config/storage_backends.py"
    click Storage "https://github.com/ch4zzy/checks-api/tree/main/config/media/pdf/"
    click Settings "https://github.com/ch4zzy/checks-api/blob/main/config/settings.py"
    click WSGI "https://github.com/ch4zzy/checks-api/blob/main/config/wsgi.py"
    click Manage "https://github.com/ch4zzy/checks-api/blob/main/manage.py"
    click CI "https://github.com/ch4zzy/checks-api/blob/main/.github/workflows/django.yml"
    click CI "https://github.com/ch4zzy/checks-api/blob/main/.github/workflows/pre-commit.yml"
    click CI "https://github.com/ch4zzy/checks-api/tree/main/Dockerfile"
    click CI "https://github.com/ch4zzy/checks-api/blob/main/docker-compose.yml"

    %% Styles
    classDef web fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef data fill:#E6FFEA,stroke:#28a745,color:#28a745;
    classDef worker fill:#FFEFD0,stroke:#d18616,color:#d18616;
    classDef external fill:#F0F0F0,stroke:#666666,color:#666666;
```
