# protortyp/melon architecture

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

- Interactive diagram: https://gitdiagram.com/protortyp/melon
- Repository: https://github.com/protortyp/melon

## Overview

##### Main Components

a) Core Services Layer:
- Scheduler Daemon (melond)
- Worker Service (mworker)
- Web UI Service

b) Client Tools Layer:
- mbatch (job submission)
- mqueue (job listing)
- mcancel (job cancellation)
- mextend (job extension)
- mshow (job details)

c) Infrastructure Layer:
- SQLite Database
- cgroups (Linux resource management)
- File System Storage

##### Detailed Component Breakdown

Scheduler (melond):
- Subcomponents:
- API Server (port 8088)
- Application Server (port 8080)
- Scheduler Core
- Database Interface

Worker (mworker):
- Connection to scheduler
- Subcomponents:
- Job Executor
- cgroups Manager
- Resource Monitor

##### Specific Implementation Details

- Protocol Buffers (proto/melon.proto)
- Configuration Management
- Resource Controls (cgroups)
- Job State Management

##### Additional Elements

Annotations for:
- Port numbers (8080, 8088, 8082)
- File paths (/var/lib/melon)
- Service user contexts (melond, mworker)

**[Web UI] -----> [API Server (8088)] ---> [Scheduler Core] <---- [CLI Tools]**

- [Database (SQLite)]

- v
- [Worker Service]

- v
- [cgroups Manager]

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style Definitions
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef infra fill:#757575,stroke:#424242,color:white
    classDef tools fill:#FF9800,stroke:#EF6C00,color:white
    classDef resource fill:#FF5722,stroke:#D84315,color:white

    %% User Interface Layer
    subgraph UI
        WebUI["Web UI"]:::frontend
        JobList["Job List Component"]:::frontend
        WebUI --> JobList
    end

    %% Client Tools Layer
    subgraph Tools
        mbatch["mbatch"]:::tools
        mqueue["mqueue"]:::tools
        mcancel["mcancel"]:::tools
        mextend["mextend"]:::tools
        mshow["mshow"]:::tools
    end

    %% Core Services Layer
    subgraph Scheduler
        APIServer["API Server\n(Port 8088)"]:::core
        AppServer["Application Server\n(Port 8080)"]:::core
        SchedulerCore["Scheduler Core"]:::core
        DBInterface["Database Interface"]:::core
        
        APIServer --> SchedulerCore
        AppServer --> SchedulerCore
        SchedulerCore --> DBInterface
    end

    %% Worker Layer
    subgraph Worker
        WorkerCore["Worker Core"]:::core
        ResourceMgmt["Resource Management"]:::resource
        
        WorkerCore --> ResourceMgmt
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        DB[(SQLite)]:::infra
        CGroups["cgroups Manager"]:::resource
        ProtoFiles["Protocol Buffers"]:::infra
        Config["Configuration"]:::infra
    end

    %% Connections
    UI --> APIServer
    Tools --> APIServer
    DBInterface --> DB
    SchedulerCore --> WorkerCore
    ResourceMgmt --> CGroups
    
    %% Click Events
    click WebUI "https://github.com/protortyp/melon/blob/main/ui/src/App.tsx"
    click JobList "https://github.com/protortyp/melon/blob/main/ui/src/components/JobList.tsx"
    click mbatch "https://github.com/protortyp/melon/tree/main/crates/mbatch/"
    click mqueue "https://github.com/protortyp/melon/tree/main/crates/mqueue/"
    click mcancel "https://github.com/protortyp/melon/tree/main/crates/mcancel/"
    click mextend "https://github.com/protortyp/melon/tree/main/crates/mextend/"
    click mshow "https://github.com/protortyp/melon/tree/main/crates/mshow/"
    click APIServer "https://github.com/protortyp/melon/blob/main/crates/melond/src/api.rs"
    click AppServer "https://github.com/protortyp/melon/blob/main/crates/melond/src/application.rs"
    click SchedulerCore "https://github.com/protortyp/melon/blob/main/crates/melond/src/scheduler.rs"
    click DBInterface "https://github.com/protortyp/melon/blob/main/crates/melond/src/db.rs"
    click WorkerCore "https://github.com/protortyp/melon/blob/main/crates/mworker/src/worker.rs"
    click ResourceMgmt "https://github.com/protortyp/melon/blob/main/crates/mworker/src/core_mask.rs"
    click CGroups "https://github.com/protortyp/melon/tree/main/crates/cgroups/"
    click ProtoFiles "https://github.com/protortyp/melon/blob/main/proto/melon.proto"
    click Config "https://github.com/protortyp/melon/tree/main/crates/melond/configuration/"

    %% Legend
    subgraph Legend
        Frontend["Frontend"]:::frontend
        CoreService["Core Service"]:::core
        Infrastructure["Infrastructure"]:::infra
        ClientTools["Client Tools"]:::tools
        ResourceMgmt2["Resource Management"]:::resource
    end
```
