# robinthrift/belt architecture

> Architecture diagram of the GitHub repository robinthrift/belt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/robinthrift/belt
- Repository: https://github.com/robinthrift/belt

## Overview

##### Main Components Identification

a) Frontend Layer:
- UI Components (React-based, found in /ui/src/components)
- State Management (found in /ui/src/state)
- API Client Layer (found in /ui/src/storage/remote)

b) Backend Layer:
- HTTP Server (/internal/server)
- Authentication System (/internal/auth)
- API Controllers (/internal/control)
- Plugin System (/internal/plugins)
- Storage Layer (/internal/storage)

**┌─ Client Layer ─────────────────────┐**
- React UI                           │
- ┌─────────────┐    ┌────────────┐ │
- Components │    │   State    │ │
- ┘    └────────────┘ │
- ┌─────────────────────────────────┐│
- API Client Layer         ││
- ┴─────────────────────────────────┘│
- ▲                    ▼
- HTTP/WebSocket

**┌─ Server Layer ────────────────────────────────────┐**
- ┌─────────────┐    ┌────────────┐  ┌───────────┐ │
- Ingress   │───▶│ Controllers│  │  Plugins  │ │
- ┘    └────────────┘  └───────────┘ │

- ┌─────────────┐    ┌────────────┐       │        │
- Auth     │◀───│   Domain   │◀──────┘        │
- ┘    └────────────┘                │

- ┌─────────────────────────────────────────────┐  │
- Storage Layer                  │  │
- ┌────────────┐        ┌─────────────┐      │  │
- Database  │        │  Filesystem │      │  │
- ┘        └─────────────┘      │  │
- ┘  │
- ┘

##### Component Relationships

- User interactions flow from UI Components → State Management → API Client
- API requests flow from API Client → Server Ingress → Controllers
- Authentication checks flow between Controllers ↔ Auth
- Data operations flow from Controllers → Domain → Storage
- Plugin interactions flow from Plugins → Domain

##### Important Details

a) Frontend:
- Separation between UI components and state management
- API client interface
- Markdown processing system

b) Backend:
- Plugin architecture for extensibility
- Storage abstraction with both SQLite and filesystem
- Authentication and session management
- API versioning (v1)

##### Technical Stack Callouts

Labels for key technologies:
- React (Frontend)
- SQLite (Database)
- Go (Backend)
- OpenAPI (API Documentation)
- Markdown Processing
- Authentication System

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef auth fill:#f1c40f,color:black
    classDef storage fill:#9b59b6,color:white
    classDef plugin fill:#e67e22,color:white
    classDef api fill:#e74c3c,color:white

    %% Frontend Layer
    subgraph Client
        UI[UI Components]
        State[State Management]
        APIClient[API Client Layer]
        
        UI --> State
        State --> APIClient
    end

    %% Server Layer
    subgraph Server
        Ingress[HTTP Server]
        APIRoutes["API Routes"]
        UIRoutes["UI Routes"]
        Controllers[API Controllers]
        Auth[Authentication]
        Domain[Domain Logic]
        Jobs[Job System]
        Session[Session Management]
        
        Ingress --> APIRoutes
        Ingress --> UIRoutes
        APIRoutes --> Controllers
        UIRoutes --> Controllers
        Controllers --> Auth
        Controllers --> Domain
        Domain --> Jobs
        Auth --> Session
    end

    %% Plugin System
    subgraph Plugins
        PluginSystem[Plugin System]
        PluginSystem --> Domain
    end

    %% Storage Layer
    subgraph Storage
        StorageLayer[Storage Layer]
        DB[Database Storage]
        FS[File System Storage]
        
        StorageLayer --> DB
        StorageLayer --> FS
        Domain --> StorageLayer
    end

    %% Cross-layer connections
    APIClient --> Ingress

    %% Component click events
    click UI "https://github.com/RobinThrift/belt/tree/main/ui/src/components/"
    click State "https://github.com/RobinThrift/belt/tree/main/ui/src/state/"
    click APIClient "https://github.com/RobinThrift/belt/tree/main/ui/src/storage/remote/"
    click Ingress "https://github.com/RobinThrift/belt/tree/main/internal/server/"
    click Auth "https://github.com/RobinThrift/belt/tree/main/internal/auth/"
    click Controllers "https://github.com/RobinThrift/belt/tree/main/internal/control/"
    click PluginSystem "https://github.com/RobinThrift/belt/tree/main/internal/plugins/"
    click StorageLayer "https://github.com/RobinThrift/belt/tree/main/internal/storage/"
    click DB "https://github.com/RobinThrift/belt/tree/main/internal/storage/database/sqlite/"
    click FS "https://github.com/RobinThrift/belt/tree/main/internal/storage/filesystem/"
    click APIRoutes "https://github.com/RobinThrift/belt/tree/main/internal/ingress/apiv1/"
    click UIRoutes "https://github.com/RobinThrift/belt/tree/main/internal/ingress/ui/"
    click Domain "https://github.com/RobinThrift/belt/tree/main/internal/domain/"
    click Jobs "https://github.com/RobinThrift/belt/tree/main/internal/jobs/"
    click Session "https://github.com/RobinThrift/belt/tree/main/internal/server/session/"

    %% Style applications
    class UI,State,APIClient frontend
    class Ingress,Controllers,Domain,Jobs backend
    class Auth,Session auth
    class StorageLayer,DB,FS storage
    class PluginSystem plugin
    class APIRoutes,UIRoutes api
```
