# reminia/ticket-system architecture

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

- Interactive diagram: https://gitdiagram.com/reminia/ticket-system
- Repository: https://github.com/reminia/ticket-system

## Overview

##### Project Type & Purpose
- This is a backend-only RESTful microservice (“ticket system”) that lets clients create, query, and manually trigger processing of support tickets.
- It enqueues new tickets into Redis via RQ for asynchronous AI-driven categorization, prioritization, and initial responses.

##### Top-Level Components
From the file tree and README we see:
– API Layer: FastAPI routes in src/api/v1/ticket_api.py
– Business Logic / Workers: src/core (ai.py, worker.py, utils.py, config.py)
– Data Layer: src/models (SQLAlchemy + Pydantic models, SQLite database)
– Queueing: Redis + RQ (jobs queued and consumed by an RQ worker)
– External Services: LLM providers via LangChain (Anthropic/OpenAI or proxy)

##### Relationships & Data-Flow
Interactions:
a. Client → FastAPI HTTP server (uvicorn)
b. “Create Ticket” endpoint
- Validates payload via Pydantic schemas
- Persists initial ticket record in SQLite
- Enqueues a processing job to Redis/RQ
c. RQ Worker
- Pulls job from Redis
- Uses core.ai → LangChain → LLM provider
- Receives category/priority/response
- Updates ticket record in SQLite
d. Query endpoints read directly from SQLite
e. Manual trigger endpoint enqueues jobs similarly

##### Architectural Patterns & Principles
- Layered separation:
– Presentation/API
– Business/Worker logic
– Data/persistence
- Asynchronous processing via work queue
- Dependency injection via config.py (environment variables, proxies)
- Single-process DB (SQLite) – suitable for lightweight deployments

– Notes on environment/config (e.g., .env settings, proxy URLs)

Putting it all together:
Inside FastAPI, annotate src/api/v1.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Clients["Clients / Swagger UI"]:::external

    %% API Layer
    subgraph "API Layer"
        FastAPI["FastAPI App\n(src/api/v1)"]:::api
    end

    %% Queue Layer
    subgraph "Queue Layer"
        Redis["Redis (RQ)"]:::queue
    end

    %% Worker Layer
    subgraph "Worker Layer"
        Worker["RQ Worker\n(src/core/worker.py,\n ai.py, utils.py)"]:::worker
    end

    %% Data Layer
    subgraph "Data Layer"
        SQLiteDB["SQLite DB"]:::data
    end

    %% External Services
    LLM["LLM Providers\n(Anthropic/OpenAI\nvia LangChain)"]:::external

    %% Flows
    Clients -->|"POST /tickets"| FastAPI
    Clients -->|"GET /tickets"| FastAPI
    FastAPI -->|"SQLAlchemy INSERT"| SQLiteDB
    FastAPI -->|"RQ.enqueue()"| Redis
    Redis -->|"job pulled"| Worker
    Worker -->|"LangChain → LLM"| LLM
    Worker -->|"UPDATE ticket record"| SQLiteDB
    FastAPI -->|"SELECT"| SQLiteDB

    %% Click Events
    click FastAPI "https://github.com/reminia/ticket-system/blob/main/src/api/v1/ticket_api.py"
    click FastAPI "https://github.com/reminia/ticket-system/blob/main/src/main.py"
    click Worker "https://github.com/reminia/ticket-system/blob/main/src/core/worker.py"
    click Worker "https://github.com/reminia/ticket-system/blob/main/src/core/ai.py"
    click Worker "https://github.com/reminia/ticket-system/blob/main/src/core/utils.py"
    click SQLiteDB "https://github.com/reminia/ticket-system/blob/main/src/models/database.py"
    click SQLiteDB "https://github.com/reminia/ticket-system/blob/main/src/models/ticket.py"
    click SQLiteDB "https://github.com/reminia/ticket-system/blob/main/src/models/schemas.py"

    %% Styles
    classDef api fill:#cce5ff,stroke:#2196f3,color:#000;
    classDef queue fill:#ffe5b4,stroke:#fb8c00,color:#000;
    classDef worker fill:#ffd699,stroke:#f57c00,color:#000;
    classDef data fill:#d5f5e3,stroke:#27ae60,color:#000;
    classDef external fill:#e0e0e0,stroke:#757575,color:#000;
```
