# n0pashkov/ticket-system architecture

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

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

## Overview

##### Project Overview & Components
- Project Type: This is a full-stack application for managing repair tickets in a school. The backend is built with FastAPI and uses SQLAlchemy for database operations, while the frontend is developed using a React-based structure.
- Main Components:
- Backend API Server: Located under the “app” directory. It includes modules for API endpoints (handling tickets, users, comments, attachments, notifications, etc.), core configuration/security, database connections, and models/schemas.
- Database: Uses SQLite in development and PostgreSQL in production. Connection and configuration details exist in the “app/db” section.
- Frontend: Found in the “ticket-system-frontend” directory. It holds the React components (pages, hooks, context providers) that interact with the backend.
- Migrations & Configuration: Alembic is used for migrations (files in the “alembic” directory) and configuration files (e.g., alembic.ini, .env).
- Auxiliary Scripts: Scripts like “run.py”, “start_app.bat” and others ensure proper startup, network checking etc.

##### Architectural Patterns and Design Principles
- MVC-like Pattern on the Backend:
- Controllers (API endpoints) invoke services and interact with models.
- “Schemas” (using Pydantic) for data validation and response modeling.
- Separation of Concerns:
- Frontend is completely separated from the Backend by REST API boundaries.
- Environment configuration is separated using the .env file.
- Security:
- JWT-based authentication is centralized in the “app/core/security.py”.
- Extensibility:
- The modular structure (multiple endpoint files) facilitates extension like adding notifications or integration with other systems.

##### Technology & Frameworks
- Backend: FastAPI, SQLAlchemy, Pydantic, Alembic.
- Frontend: React (create-react-app structure) with context (AuthContext), custom hooks and components.
- Database: SQLite (development) and PostgreSQL (production).
- Testing: Pytest for backend, with tests configured in pytest.ini.
- Optional: Docker components if demonstrating containerized deployment.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React Application"]:::frontend
        FEApi["API Service (ticket-system-frontend/src/api)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BA["Backend API Endpoints (app/api)"]:::backend
        Core["Core Config & Security (app/core)"]:::backend
        Models["Models (app/models)"]:::backend
        Schemas["Schemas (app/schemas)"]:::backend
        DBModule["Database Module (app/db)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["SQLite/PostgreSQL Database"]:::database
    end

    %% Migration & Deployment
    subgraph "Migration & Deployment"
        AlembicDir["Alembic Migrations (alembic)"]:::migration
        AlembicIni["Alembic Config (alembic.ini)"]:::migration
        Docker["Docker (Optional Container Deployment)"]:::deployment
    end

    %% Auxiliary Scripts
    subgraph "Auxiliary Scripts"
        RunPy["run.py"]:::utilities
        StartBat["start_app.bat"]:::utilities
        CheckNetBat["check_network.bat"]:::utilities
        InitDB["init_database.py"]:::utilities
    end

    %% Interactions
    FE -->|"REST_API_Calls"| BA
    FEApi -->|"HTTP_calls"| BA
    BA -->|"Uses"| Core
    BA -->|"Interacts_with"| DBModule
    BA -->|"Uses_Model"| Models
    BA -->|"Uses_Schema"| Schemas
    DBModule -->|"ORM_Operations"| DB
    BA -->|"Triggers_Migration"| AlembicDir
    RunPy -->|"Starts"| BA
    StartBat -->|"Starts"| BA
    CheckNetBat -->|"Verifies_Network"| BA
    InitDB -->|"Initializes"| DBModule

    %% Click Events
    click BA "https://github.com/n0pashkov/ticket-system/tree/main/app/api"
    click Core "https://github.com/n0pashkov/ticket-system/tree/main/app/core"
    click DBModule "https://github.com/n0pashkov/ticket-system/tree/main/app/db"
    click Models "https://github.com/n0pashkov/ticket-system/tree/main/app/models"
    click Schemas "https://github.com/n0pashkov/ticket-system/tree/main/app/schemas"
    click FE "https://github.com/n0pashkov/ticket-system/tree/main/ticket-system-frontend"
    click FEApi "https://github.com/n0pashkov/ticket-system/tree/main/ticket-system-frontend/src/api"
    click AlembicDir "https://github.com/n0pashkov/ticket-system/tree/main/alembic"
    click AlembicIni "https://github.com/n0pashkov/ticket-system/blob/main/alembic.ini"
    click RunPy "https://github.com/n0pashkov/ticket-system/blob/main/run.py"
    click StartBat "https://github.com/n0pashkov/ticket-system/blob/main/start_app.bat"
    click CheckNetBat "https://github.com/n0pashkov/ticket-system/blob/main/check_network.bat"
    click InitDB "https://github.com/n0pashkov/ticket-system/blob/main/init_database.py"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef migration fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef deployment fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef utilities fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
```
