# vatmena/hayya architecture

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

- Interactive diagram: https://gitdiagram.com/vatmena/hayya
- Repository: https://github.com/vatmena/hayya

## Overview

##### Main System Components

a) Frontend Layer:
- SvelteKit application (main UI framework)
- UI Components (located in src/lib/components)
- Documentation System (in src/lib/docs)
- Route-based features (in src/routes)

b) Backend Layer:
- Server-side API routes (in src/routes/api)
- Authentication system (src/lib/auth.ts)
- Permissions system (src/lib/perms)
- Database interactions (via Prisma)

c) Database Layer:
- PostgreSQL database (indicated by postgres.docker-compose.yml)
- Prisma ORM (shown by prisma directory)

d) External Services:
- VATSIM authentication
- Moodle integration (src/lib/moodle)

##### Architectural Patterns to Highlight

a) Route-based Architecture:
- (hq) routes for main application
- (docs) routes for documentation
- API routes for external integrations

b) Component Architecture:
- UI component hierarchy
- Shared components system
- Documentation components

c) Data Flow:
- Authentication flow
- Permission checks
- API interactions
- Database operations

##### Specific Implementation Details

Key features:

a) Core Features:
- Training management system
- Event management
- Resource management
- User roster system
- TVC (Transfer/Visit/Certification) system

b) Security Layer:
- Authentication mechanisms
- Permission management
- Role-based access control

**[Client Layer]**
- ↓ ↑
**[Application Layer]**
- ↓ ↑
**[Service Layer]**
- ↓ ↑
**[Data Access Layer]**
- ↓ ↑
**[Database Layer]**

##### Connection Types

Show:

##### Important Subsystems to Detail

- Training management workflow
- Event management system
- User permission system
- Documentation system
- TVC processing system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        UI["UI Components"]:::frontend
        Doc["Documentation Components"]:::frontend
        Routes["Route Components"]:::frontend
    end

    subgraph Application
        Auth["Authentication System"]:::security
        Perms["Permissions System"]:::security
        TVCProc["TVC Processing"]:::service
        Training["Training Management"]:::service
        Events["Event Management"]:::service
        Resources["Resource Management"]:::service
        Roster["User Roster"]:::service
    end

    subgraph Services
        API["API Routes"]:::backend
        MoodleInt["Moodle Integration"]:::external
        VATSIMAuth["VATSIM Authentication"]:::external
    end

    subgraph Data
        DB[(PostgreSQL)]:::database
        Migrations["Database Migrations"]:::database
        PrismaORM["Prisma ORM"]:::database
    end

    UI --> Routes
    UI --> Doc
    Routes --> Auth
    Routes --> API
    Auth --> VATSIMAuth
    Auth --> Perms
    API --> PrismaORM
    API --> MoodleInt
    PrismaORM --> DB
    Migrations --> DB
    
    %% Core Feature Connections
    Routes --> TVCProc
    Routes --> Training
    Routes --> Events
    Routes --> Resources
    Routes --> Roster
    
    TVCProc --> API
    Training --> API
    Events --> API
    Resources --> API
    Roster --> API

    %% Click Events
    click UI "https://github.com/VATMENA/hayya/tree/main/src/lib/components/ui/"
    click Doc "https://github.com/VATMENA/hayya/tree/main/src/lib/docs/"
    click Auth "https://github.com/VATMENA/hayya/blob/main/src/lib/auth.ts"
    click Perms "https://github.com/VATMENA/hayya/tree/main/src/lib/perms/"
    click API "https://github.com/VATMENA/hayya/tree/main/src/routes/(hq)/api/v1/"
    click MoodleInt "https://github.com/VATMENA/hayya/tree/main/src/lib/moodle/"
    click TVCProc "https://github.com/VATMENA/hayya/tree/main/src/routes/(hq)/[id]/tvc/"
    click Training "https://github.com/VATMENA/hayya/tree/main/src/routes/(hq)/[id]/training/"
    click Events "https://github.com/VATMENA/hayya/tree/main/src/routes/(hq)/[id]/events/"
    click Resources "https://github.com/VATMENA/hayya/tree/main/src/routes/(hq)/[id]/resources/"
    click Roster "https://github.com/VATMENA/hayya/tree/main/src/routes/(hq)/[id]/roster/"
    click DB "https://github.com/VATMENA/hayya/blob/main/prisma/schema.prisma"
    click Migrations "https://github.com/VATMENA/hayya/tree/main/prisma/migrations/"

    %% Styling
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef security fill:#F44336,stroke:#C62828,color:white
    classDef database fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef external fill:#FFC107,stroke:#FFA000,color:black
    classDef service fill:#00BCD4,stroke:#00838F,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        Security["Security Component"]:::security
        Database["Database Component"]:::database
        External["External Service"]:::external
        Service["Internal Service"]:::service
    end
```
