# lokiworks/mega architecture

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

- Interactive diagram: https://gitdiagram.com/lokiworks/mega
- Repository: https://github.com/lokiworks/mega

## Overview

##### High-Level Architecture Components

The system should be represented as a multi-layered architecture with these main components:

a. Client Interface Layer:
- HTTP/SSH Gateway (mono)
- Web UI (moon)
- Desktop App (lunar)
- CLI Interface (mega)
- FUSE Filesystem (scorpio)

b. Core Services Layer:
- Git Protocol Handler (ceres)
- Git Internal Implementation (mercury)
- Storage Engine (jupiter)
- Authentication & Authorization (saturn)
- Key Management (vault)
- Decentralized Network (gemini)
- AI Integration (atlas)
- ZTM Relay Server (aries)

c. Storage Layer:
- PostgreSQL Database
- File System Storage
- Object Storage

##### Component Relationships

- Git protocol flows from clients through mono/gateway to ceres
- Storage operations flowing through jupiter to the database/storage systems
- Authentication requests passing through saturn
- Decentralized operations going through gemini
- FUSE operations through scorpio

##### Key Architectural Patterns to Highlight

a. Modular Design:
- Clear boundaries between modules (mercury, jupiter, ceres, etc.)
- Internal module dependencies
- Extension points for plugins/integrations

b. Protocol Support:
- Git Protocol handling
- HTTP/SSH interfaces
- FUSE filesystem integration
- Decentralized network protocols (Nostr, Matrix, Mastodon)

##### Specific Implementation Details

Technical annotations for:
- Language: Rust (primary implementation)
- Web Technologies: Next.js (moon, mars UIs)
- Desktop: Tauri (lunar)
- Database: PostgreSQL
- Protocols: Git, SSH, HTTP, FUSE
- Security: Cedar Policy (saturn)

##### Data Flow Patterns

Primary data flows:
- Git operations (push/pull/clone)
- Monorepo management operations
- Authentication/Authorization flows
- Storage operations
- Decentralized collaboration flows

##### Deployment Context

A separate section showing:
- Docker container boundaries
- Network isolation
- Volume mounts
- Service discovery

- Logical architecture
- Deployment architecture
- Data flow architecture
- Security architecture

This system design should emphasize Mega's unique features like Git compatibility, trunk-based development, and decentralized collaboration while showing how all components work together to create a cohesive monorepo management system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Interface Layer"
        MONO["HTTP/SSH Gateway"]:::gateway
        MOON["Web UI"]:::client
        LUNAR["Desktop App"]:::client
        MEGA["CLI Interface"]:::client
        SCORPIO["FUSE Filesystem"]:::client
    end

    subgraph "Core Services Layer"
        CERES["Git Protocol Handler"]:::core
        MERCURY["Git Internal Implementation"]:::core
        JUPITER["Storage Engine"]:::core
        SATURN["Authentication & Authorization"]:::security
        VAULT["Key Management"]:::security
        GEMINI["Decentralized Network"]:::network
        ATLAS["AI Integration"]:::ai
        ARIES["ZTM Relay Server"]:::network
    end

    subgraph "Storage Layer"
        DB[(PostgreSQL)]:::storage
        FS["File System Storage"]:::storage
        OBJ["Object Storage"]:::storage
    end

    %% Client to Core connections
    MONO --> CERES
    MOON --> CERES
    LUNAR --> CERES
    MEGA --> CERES
    SCORPIO --> CERES

    %% Core service interconnections
    CERES --> MERCURY
    MERCURY --> JUPITER
    JUPITER --> DB
    JUPITER --> FS
    JUPITER --> OBJ
    CERES --> SATURN
    SATURN --> VAULT
    GEMINI --> ARIES
    ATLAS --> MERCURY

    %% Security flows
    MONO --> SATURN
    MOON --> SATURN
    LUNAR --> SATURN
    MEGA --> SATURN

    %% Decentralized operations
    MOON --> GEMINI
    LUNAR --> GEMINI
    MEGA --> GEMINI

    %% Click events for component mapping
    click MONO "https://github.com/lokiworks/mega/tree/main/mono"
    click MOON "https://github.com/lokiworks/mega/tree/main/moon/src/app"
    click LUNAR "https://github.com/lokiworks/mega/tree/main/lunar/src-tauri"
    click MEGA "https://github.com/lokiworks/mega/tree/main/mega/src/commands"
    click SCORPIO "https://github.com/lokiworks/mega/tree/main/scorpio/src/fuse"
    click CERES "https://github.com/lokiworks/mega/tree/main/ceres/src/protocol"
    click MERCURY "https://github.com/lokiworks/mega/tree/main/mercury/src/internal"
    click JUPITER "https://github.com/lokiworks/mega/tree/main/jupiter/src/storage"
    click SATURN "https://github.com/lokiworks/mega/tree/main/saturn/src"
    click VAULT "https://github.com/lokiworks/mega/blob/main/vault/src/vault.rs"
    click GEMINI "https://github.com/lokiworks/mega/tree/main/gemini/src/nostr"
    click ATLAS "https://github.com/lokiworks/mega/tree/main/atlas/src/api"
    click ARIES "https://github.com/lokiworks/mega/blob/main/aries/src/service/relay_server.rs"
    click FS "https://github.com/lokiworks/mega/blob/main/jupiter/src/storage/file_storage/local_storage.rs"

    %% Styling
    classDef gateway fill:#87CEEB
    classDef client fill:#90EE90
    classDef core fill:#4169E1
    classDef security fill:#FF6B6B
    classDef network fill:#DDA0DD
    classDef storage fill:#FFD700
    classDef ai fill:#20B2AA

    %% Legend
    subgraph Legend
        L1["Gateway Component"]:::gateway
        L2["Client Interface"]:::client
        L3["Core Service"]:::core
        L4["Security Component"]:::security
        L5["Network Component"]:::network
        L6["Storage Component"]:::storage
        L7["AI Component"]:::ai
    end
```
