# jiawesoft/jiascheduler architecture

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

- Interactive diagram: https://gitdiagram.com/jiawesoft/jiascheduler
- Repository: https://github.com/jiawesoft/jiascheduler

## Overview

##### Project type and purpose
- Jiascheduler is a distributed, high-performance, dynamically configurable task scheduler written in Rust.
- It exposes four main executables:
1. console (the Web UI + REST API server)
2. comet (WebSocket gateway for agents)
3. agent (local task executor + SSH proxy)
4. jiascheduler (a bundled single-node package of the above three)

##### File structure
Top-level workspace crates:
- automate/…   (core scheduler library: bus, comet server/bridge, scheduler, SSH)
- openapi-derive/… (codegen macros for the REST API)
- openapi/…   (console service: API, entity layer, logic, middleware, state; Rust web server exposing OpenAPI)
- migration/…   (database migration CLI + SQL scripts)
- crates/leader-election/… (leader-election library for high availability)
- src/bin/agent.rs, comet.rs, console.rs, jiascheduler.rs (entrypoints)
- docker-compose.yml, Dockerfile, .env, assets/, examples/, dist/…

##### README for additional insights
- Confirms four executables (console, comet, agent, bundled).
- Browser ↔ Console (HTTP + WebSocket for web SSH)
- Console ↔ MySQL + Redis
- Console ↔ Comet (internal RPC or Redis pub/sub)
- Comet ↔ Agent (WebSocket)
- Agent ↔ target hosts (via SSH)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface
    Browser["User's Browser"]:::user

    %% Control Plane
    subgraph "Control Plane" 
        direction TB
        subgraph "Console Service (openapi)"
            direction TB
            CTOML["Cargo.toml"]:::control
            CLIB["lib.rs"]:::control
            CAPI["api.rs / api/"]:::control
            CENTITY["entity/"]:::control
            CLOGIC["logic/"]:::control
            CMIDDLE["middleware/"]:::control
            CSTATE["state.rs"]:::control
            CENTRY["console.rs"]:::control
        end
        subgraph "Migration CLI"
            direction TB
            MIGTOML["Cargo.toml"]:::cli
            MIGMAIN["main.rs"]:::cli
            MIGSCRIPTS["src/*.rs"]:::cli
            MIGSQL["sql/"]:::cli
        end
        subgraph "OpenAPI Derive"
            direction TB
            OADTOML["Cargo.toml"]:::control
            OADLIB["lib.rs"]:::control
            OADTEST["tests/"]:::control
        end
        JIASCHED["Bundled Single-Node (jiascheduler.rs)"]:::control
    end

    %% Data Plane
    subgraph "Data Plane"
        direction TB
        subgraph "Comet Service (automate::comet)"
            direction TB
            COMROOT["comet.rs"]:::data
            COMHANDLER["handler.rs"]:::data
            COMLOGIC["logic.rs"]:::data
            COMMACROS["macros.rs"]:::data
            COMTYPES["types.rs"]:::data
            COMENTRY["comet.rs"]:::data
        end
        subgraph "Agent Service (automate::scheduler + SSH)"
            direction TB
            SCHEDROOT["scheduler.rs"]:::data
            SCMD["cmd.rs"]:::data
            SEXEC["executor.rs"]:::data
            SFILE["file.rs"]:::data
            SSCHED["scheduler.rs"]:::data
            STYPES["types.rs"]:::data
            SSH["ssh.rs"]:::data
            AGENTRY["agent.rs"]:::data
        end
        LEADER["Leader Election (crates/leader-election)"]:::data
    end

    %% State Plane
    subgraph "State Plane"
        direction TB
        MySQL["MySQL"]:::state
        Redis["Redis (Cache / PubSub)"]:::state
    end

    %% Target Hosts
    Target["Target Hosts"]:::external

    %% Connections
    Browser -->|"HTTP/REST\nWS Tunnel"| CTOML
    subgraph _ConsoleFlows_
        direction LR
        CTOML -->|"CRUD API\nHTTP"| MySQL
        CTOML -->|"Cache / PubSub"| Redis
        CTOML -->|"RPC / PubSub"| COMROOT
    end
    COMROOT -->|"Pub/Sub"| Redis
    COMROOT -->|"WebSocket"| SCHEDROOT
    SCHEDROOT -->|"SSH"| Target

    MIGTOML -->|"pre-deployment migrations"| MySQL

    %% Bundled single-node combines flows
    JIASCHED --> CTOML
    JIASCHED --> COMROOT
    JIASCHED --> SCHEDROOT

    %% Click Events for Console Service
    click CTOML "https://github.com/jiawesoft/jiascheduler/blob/main/openapi/Cargo.toml"
    click CLIB "https://github.com/jiawesoft/jiascheduler/blob/main/openapi/src/lib.rs"
    click CAPI "https://github.com/jiawesoft/jiascheduler/blob/main/openapi/src/api.rs"
    click CENTITY "https://github.com/jiawesoft/jiascheduler/tree/main/openapi/src/entity/"
    click CLOGIC "https://github.com/jiawesoft/jiascheduler/tree/main/openapi/src/logic/"
    click CMIDDLE "https://github.com/jiawesoft/jiascheduler/tree/main/openapi/src/middleware/"
    click CSTATE "https://github.com/jiawesoft/jiascheduler/blob/main/openapi/src/state.rs"
    click CENTRY "https://github.com/jiawesoft/jiascheduler/blob/main/src/bin/console.rs"

    %% Click Events for Comet Service
    click COMROOT "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/comet.rs"
    click COMHANDLER "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/comet/handler.rs"
    click COMLOGIC "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/comet/logic.rs"
    click COMMACROS "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/comet/macros.rs"
    click COMTYPES "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/comet/types.rs"
    click COMENTRY "https://github.com/jiawesoft/jiascheduler/blob/main/src/bin/comet.rs"

    %% Click Events for Agent Service
    click SCHEDROOT "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/scheduler.rs"
    click SCMD "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/scheduler/cmd.rs"
    click SEXEC "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/scheduler/executor.rs"
    click SFILE "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/scheduler/file.rs"
    click SSCHED "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/scheduler/scheduler.rs"
    click STYPES "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/scheduler/types.rs"
    click SSH "https://github.com/jiawesoft/jiascheduler/blob/main/automate/src/ssh.rs"
    click AGENTRY "https://github.com/jiawesoft/jiascheduler/blob/main/src/bin/agent.rs"

    %% Click Event for Bundled
    click JIASCHED "https://github.com/jiawesoft/jiascheduler/blob/main/src/bin/jiascheduler.rs"

    %% Click Events for Migration CLI
    click MIGTOML "https://github.com/jiawesoft/jiascheduler/blob/main/migration/Cargo.toml"
    click MIGMAIN "https://github.com/jiawesoft/jiascheduler/blob/main/migration/src/main.rs"
    click MIGSCRIPTS "https://github.com/jiawesoft/jiascheduler/tree/main/migration/src"
    click MIGSQL "https://github.com/jiawesoft/jiascheduler/tree/main/migration/sql/"

    %% Click Event for Leader Election
    click LEADER "https://github.com/jiawesoft/jiascheduler/blob/main/crates/leader-election/src/lib.rs"

    %% Click Events for OpenAPI Derive
    click OADTOML "https://github.com/jiawesoft/jiascheduler/blob/main/openapi-derive/Cargo.toml"
    click OADLIB "https://github.com/jiawesoft/jiascheduler/blob/main/openapi-derive/src/lib.rs"
    click OADTEST "https://github.com/jiawesoft/jiascheduler/tree/main/openapi-derive/tests/"

    %% Styles
    classDef user fill:#FFE599,stroke:#D6A700,color:#000;
    classDef control fill:#C9DAF8,stroke:#6C8EBF,color:#000;
    classDef data fill:#F4CCCC,stroke:#CC4125,color:#000;
    classDef state fill:#D5A6BD,stroke:#8E3B8E,color:#000;
    classDef cli fill:#D9EAD3,stroke:#38761D,color:#000;
    classDef external fill:#EAD1DC,stroke:#C27BA0,color:#000;
```
