# paularlott/knot architecture

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

- Interactive diagram: https://gitdiagram.com/paularlott/knot
- Repository: https://github.com/paularlott/knot

## Overview

##### Main Components

a. Core Services Layer:
- Web Server (web/*)
- API Server (api/*)
- Agent Service (agent/*)
- Proxy Service (proxy/*)
- SSH Server (internal/sshd/*)
- DNS Services (internal/dnsproxy/*, internal/dnsserver/*)

b. Database Layer:
- Multiple Database Support:
- BadgerDB (database/drivers/badgerdb/*)
- MySQL (database/drivers/mysql/*)
- Redis (database/drivers/redis/*)
- In-Memory (database/drivers/memory/*)

c. Container Management Layer:
- Container Backends:
- Nomad Integration (internal/container/nomad/*)
- Docker Integration (internal/container/docker/*)

d. Integration Layer:
- VSCode Integration
- Code Server Integration
- Terminal Services
- VNC Support
- Origin-Leaf Architecture (internal/origin_leaf/*)

##### Relationship Flows

- User → Web Interface/CLI → API Server
- API Server → Database Layer
- API Server → Container Management Layer
- Agent → Container Management Layer
- Proxy → Development Environments
- DNS Services ↔ Development Spaces

##### Key Design Elements

- Blue rectangles: Core services
- Orange hexagons: Container platforms
- Purple clouds: External integrations
- Yellow diamonds: Security components

##### Architectural Patterns to Highlight

- Multi-tenant architecture
- Plugin-based database system
- Microservices communication
- Origin-Leaf distribution model

##### Specific Components

**[Client Layer]**
- Web UI
- CLI Tools
- VS Code
- Terminal

**[Application Layer]**
- API Gateway
- Authentication/Authorization
- Template Management
- Space Management
- User/Group Management
- Role-Based Access Control

**[Infrastructure Layer]**
- Container Orchestration
- Volume Management
- Network Management
- DNS Services

**[Storage Layer]**
- Database Abstraction
- Multiple Backend Support

##### Additional Elements

- Security boundaries (showing authentication/authorization flows)
- Resource quotas and limits
- Template flow from definition to deployment
- Monitoring and logging pathways
- API endpoints and integration points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        WebUI["Web UI"]:::frontend
        CLI["CLI Tools"]:::client
        VSCode["VS Code"]:::client
        Terminal["Terminal"]:::client
    end

    subgraph AppLayer["Application Layer"]
        API["API Server"]:::core
        Auth["Authentication/Authorization"]:::security
        TempMgmt["Template Management"]:::core
        SpaceMgmt["Space Management"]:::core
        UserMgmt["User/Group Management"]:::core
        RBAC["Role-Based Access Control"]:::security
    end

    subgraph InfraLayer["Infrastructure Layer"]
        Agent["Agent Service"]:::core
        Proxy["Proxy Service"]:::core
        SSH["SSH Server"]:::core
        DNS["DNS Services"]:::core
        ContainerOrch["Container Orchestration"]:::infra
        VolumeMgmt["Volume Management"]:::infra
        NetworkMgmt["Network Management"]:::infra
    end

    subgraph DBLayer["Storage Layer"]
        DBAbstraction["Database Abstraction"]:::db
        subgraph DBBackends["Database Backends"]
            BadgerDB["BadgerDB"]:::db
            MySQL["MySQL"]:::db
            Redis["Redis"]:::db
            InMem["In-Memory"]:::db
        end
    end

    subgraph ContainerLayer["Container Management"]
        Nomad["Nomad Integration"]:::container
        Docker["Docker Integration"]:::container
    end

    subgraph Integration["Integration Layer"]
        OriginLeaf["Origin-Leaf Architecture"]:::integration
        CodeServer["Code Server"]:::integration
        VNC["VNC Support"]:::integration
    end

    %% Relationships
    WebUI --> API
    CLI --> API
    VSCode --> API
    Terminal --> API

    API --> Auth
    API --> DBAbstraction
    API --> ContainerOrch

    Auth --> UserMgmt
    Auth --> RBAC

    Agent --> ContainerOrch
    Proxy --> NetworkMgmt
    DNS --> NetworkMgmt

    ContainerOrch --> Nomad
    ContainerOrch --> Docker

    DBAbstraction --> DBBackends

    %% Click Events
    click API "https://github.com/paularlott/knot/tree/main/api/*"
    click Agent "https://github.com/paularlott/knot/tree/main/agent/*"
    click Proxy "https://github.com/paularlott/knot/tree/main/proxy/*"
    click SSH "https://github.com/paularlott/knot/tree/main/internal/sshd/*"
    click DNS "https://github.com/paularlott/knot/tree/main/internal/dnsproxy/*"
    click BadgerDB "https://github.com/paularlott/knot/tree/main/database/drivers/badgerdb/*"
    click MySQL "https://github.com/paularlott/knot/tree/main/database/drivers/mysql/*"
    click Redis "https://github.com/paularlott/knot/tree/main/database/drivers/redis/*"
    click InMem "https://github.com/paularlott/knot/tree/main/database/drivers/memory/*"
    click Nomad "https://github.com/paularlott/knot/tree/main/internal/container/nomad/*"
    click Docker "https://github.com/paularlott/knot/tree/main/internal/container/docker/*"
    click OriginLeaf "https://github.com/paularlott/knot/tree/main/internal/origin_leaf/*"
    click Auth "https://github.com/paularlott/knot/blob/main/middleware/authmiddleware.go"
    click CLI "https://github.com/paularlott/knot/tree/main/command/*"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef db fill:#2ecc71,stroke:#27ae60,color:white
    classDef container fill:#e67e22,stroke:#d35400,color:white
    classDef integration fill:#9b59b6,stroke:#8e44ad,color:white
    classDef infra fill:#f1c40f,stroke:#f39c12,color:black
    classDef frontend fill:#1abc9c,stroke:#16a085,color:white
    classDef client fill:#34495e,stroke:#2c3e50,color:white
```
