# nathan-au/rpg-mini architecture

> Architecture diagram of the GitHub repository nathan-au/rpg-mini, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nathan-au/rpg-mini
- Repository: https://github.com/nathan-au/rpg-mini

## Overview

##### Project type and purpose
- This is a standalone backend microservice (likely built with a web framework like FastAPI or Flask) that ingests documents, classifies them, and extracts data before persisting results in a local database.
- Key features (inferred from filenames):
– “endpoints/…”: REST API layer
– “logic/…”: business logic (classification, extraction)
– “database/…”: data access and ORM models
– “main.py”: application entry point

##### File structure
- Top-level files:
– constants.py, enums.py: shared configurations and types
– main.py: kicks off the web server and routes
– database.db (& database/database.db): SQLite database file
- Directories:
– endpoints/: REST handlers grouped by domain (clients, documents, intakes)
– logic/: core processing modules (classification.py, extraction.py)
– database/: DB layer (models.py defines ORM, database.py handles connections)
– tests/: sample docs and test suite

##### README
- No architecture details provided. We rely entirely on file structure.

a. Main components
1. API Gateway / Web Framework (main.py + endpoints/)
2. Business Logic Layer (logic/classification.py, logic/extraction.py)
3. Data Access Layer (database/database.py, database/models.py)
4. Persistence Store (SQLite database file)
5. External Clients (CLI, web UI, or upstream services consuming the API)
b. Relationships & data flows
- External Clients → HTTP requests → API Gateway
- API Gateway → invokes → Endpoint Handlers (clients.py, documents.py, intakes.py)
- Endpoint Handlers → call → Business Logic functions
- Business Logic → uses → Data Access Layer to read/write models
- Data Access Layer → persists → SQLite database
- Optionally: Business Logic may return results directly to clients or enqueue follow‐up tasks
c. Architectural patterns
- Layered architecture (Presentation/API → Business Logic → Data Access → Persistence)
- Separation of concerns: endpoints only handle HTTP, logic modules only handle processing
d. Key technologies & libraries
- Web framework (FastAPI/Flask) in main.py
- SQLAlchemy (or similar) in database/models.py
- SQLite (database.db)

##### Detailed separation of components
1. “Clients” at the left.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Actor
    Client["External Clients"]:::external

    %% API Layer
    subgraph "API Layer"
        main["main.py"]:::api
        clients_ep["endpoints/clients.py"]:::api
        docs_ep["endpoints/documents.py"]:::api
        intakes_ep["endpoints/intakes.py"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        logic_cls["logic/classification.py"]:::logic
        logic_ext["logic/extraction.py"]:::logic
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        db_conn["database/database.py"]:::data
        db_models["database/models.py"]:::data
    end

    %% Persistence Store
    DB_file(("SQLite Database")):::db

    %% Connections
    Client -->|"HTTP/JSON"| main
    main -->|"routes to"| clients_ep
    main -->|"routes to"| docs_ep
    main -->|"routes to"| intakes_ep

    clients_ep -->|"calls"| logic_cls
    clients_ep -->|"calls"| logic_ext
    docs_ep -->|"calls"| logic_cls
    docs_ep -->|"calls"| logic_ext
    intakes_ep -->|"calls"| logic_cls
    intakes_ep -->|"calls"| logic_ext

    logic_cls -->|"uses ORM"| db_conn
    logic_cls -->|"uses models"| db_models
    logic_ext -->|"uses ORM"| db_conn
    logic_ext -->|"uses models"| db_models

    db_conn -->|"persists data"| DB_file
    db_models -->|"persists schema"| DB_file

    %% Click Events
    click main "https://github.com/nathan-au/rpg-mini/blob/main/main.py"
    click clients_ep "https://github.com/nathan-au/rpg-mini/blob/main/endpoints/clients.py"
    click docs_ep "https://github.com/nathan-au/rpg-mini/blob/main/endpoints/documents.py"
    click intakes_ep "https://github.com/nathan-au/rpg-mini/blob/main/endpoints/intakes.py"
    click logic_cls "https://github.com/nathan-au/rpg-mini/blob/main/logic/classification.py"
    click logic_ext "https://github.com/nathan-au/rpg-mini/blob/main/logic/extraction.py"
    click db_conn "https://github.com/nathan-au/rpg-mini/blob/main/database/database.py"
    click db_models "https://github.com/nathan-au/rpg-mini/blob/main/database/models.py"
    click DB_file "https://github.com/nathan-au/rpg-mini/blob/main/database/database.db"

    %% Styles
    classDef external fill:#D6EAF8,stroke:#1F618D,color:#1F618D
    classDef api fill:#D5F5E3,stroke:#27AE60,color:#27AE60
    classDef logic fill:#FCF3CF,stroke:#F1C40F,color:#B7950B
    classDef data fill:#FADBD8,stroke:#E74C3C,color:#C0392B
    classDef db fill:#F2F3F4,stroke:#A6ACAF,color:#566573
```
