# factorial-io/scotty architecture

> Architecture diagram of the GitHub repository factorial-io/scotty, 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/factorial-io/scotty
- Repository: https://github.com/factorial-io/scotty

## Overview

##### Main System Components

a) Core Server Components:
- API Server (Rust-based HTTP server)
- WebSocket Server
- Task Manager
- Docker Integration Layer
- Configuration Manager
- Notification System

b) External Components:
- Docker Engine
- Traefik/HAProxy (Load Balancers)
- Client Applications (CLI & Web UI)
- Notification Services (GitLab, Mattermost, Webhooks)

##### Key Relationships to Highlight

- Data flow between components
- Command execution paths
- Event notification routes
- Configuration management flow

##### Technical Details

Annotations for:
- Port numbers (21342)
- Volume mounts (/app/apps)
- Network configurations
- Authentication flow
- Configuration paths

##### Implementation Notes

- The modular Rust-based architecture
- Docker-compose based application management
- Real-time updates via WebSocket
- Multiple reverse proxy support
- Notification service integration

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#2196F3,color:white
    classDef external fill:#4CAF50,color:white
    classDef client fill:#FF9800,color:white
    classDef infra fill:#9C27B0,color:white
    classDef security fill:#f44336,color:white

    %% Client Layer
    subgraph ClientLayer
        WebUI["Web UI (Svelte)"]:::client
        CLI["CLI Tool (scottyctl)"]:::client
        ApiDocs["API Documentation (RapiDoc)"]:::client
    end

    %% Core Services Layer
    subgraph CoreServices
        ApiServer["API Server (21342)"]:::core
        WebSocket["WebSocket Server"]:::core
        Auth["Authentication Layer"]:::core
        TaskMgr["Task Manager"]:::core
        ConfigMgr["Configuration Manager"]:::core
        NotifSys["Notification System"]:::core
        AppLifecycle["App Lifecycle Management"]:::core
        StateHandlers["State Machine Handlers"]:::core
        AppState["Application State"]:::core
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        Docker["Docker Engine"]:::infra
        LoadBalancer["Load Balancer (Traefik/HAProxy)"]:::infra
        DockerCompose["Docker Compose Integration"]:::infra
        FileSystem["File System Operations"]:::infra
    end

    %% Notification Services
    subgraph NotificationServices
        GitLab["GitLab Notifications"]:::external
        Mattermost["Mattermost Notifications"]:::external
        Webhooks["Webhook Notifications"]:::external
    end

    %% Relationships
    WebUI --> ApiServer
    CLI --> ApiServer
    ApiDocs --> ApiServer
    
    ApiServer --> Auth
    ApiServer --> WebSocket
    ApiServer --> TaskMgr
    ApiServer --> ConfigMgr
    
    TaskMgr --> AppLifecycle
    TaskMgr --> DockerCompose
    
    AppLifecycle --> StateHandlers
    AppLifecycle --> AppState
    
    StateHandlers --> Docker
    DockerCompose --> Docker
    
    NotifSys --> GitLab
    NotifSys --> Mattermost
    NotifSys --> Webhooks
    
    Docker --> LoadBalancer
    
    ConfigMgr --> FileSystem

    %% Click Events
    click WebUI "https://github.com/factorial-io/scotty/tree/main/frontend/"
    click CLI "https://github.com/factorial-io/scotty/blob/main/src/scottyctl.rs"
    click ApiDocs "https://github.com/factorial-io/scotty/tree/main/bruno/scotty/"
    click ApiServer "https://github.com/factorial-io/scotty/tree/main/src/api/"
    click WebSocket "https://github.com/factorial-io/scotty/blob/main/src/api/ws.rs"
    click Auth "https://github.com/factorial-io/scotty/blob/main/src/api/basic_auth.rs"
    click TaskMgr "https://github.com/factorial-io/scotty/tree/main/src/tasks/"
    click ConfigMgr "https://github.com/factorial-io/scotty/tree/main/src/settings/"
    click NotifSys "https://github.com/factorial-io/scotty/tree/main/src/notification/"
    click AppLifecycle "https://github.com/factorial-io/scotty/tree/main/src/apps/"
    click StateHandlers "https://github.com/factorial-io/scotty/tree/main/src/docker/state_machine_handlers/"
    click AppState "https://github.com/factorial-io/scotty/blob/main/src/app_state.rs"
    click LoadBalancer "https://github.com/factorial-io/scotty/blob/main/src/docker/loadbalancer.rs"
    click DockerCompose "https://github.com/factorial-io/scotty/blob/main/src/docker/docker_compose.rs"
    click GitLab "https://github.com/factorial-io/scotty/blob/main/src/notification/gitlab.rs"
    click Mattermost "https://github.com/factorial-io/scotty/blob/main/src/notification/mattermost.rs"
    click Webhooks "https://github.com/factorial-io/scotty/blob/main/src/notification/webhook.rs"
```
