# rinit-org/rinit architecture

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

## Overview

##### Main Components Identification
The project consists of several key crates that should be represented as main components:

a. Core Components:
- svc (Service Manager)
- supervision (Process Supervision)
- ctl (Control Interface)
- service (Service Definition)
- parser (Configuration Parser)
- ipc (Inter-Process Communication)

##### Component Relationships

a. Control Flow:
- User/System → rctl → IPC → Service Manager
- Service Manager → Supervision → Actual Services

b. Data Flow:
- Parser → Service Definitions
- Service → Dependency Graph
- IPC → Request/Reply between components

##### Specific Elements

Components should be represented as follows:

**┌─────────────────────────────────────────────────────────┐**
- User Interface                       │
- (rctl)                          │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Service Manager                       │
- (rsvc)                           │
- ┌───────────────┐  ┌───────────────┐  ┌──────────────┐│
- Service Graph │  │  Live Service │  │    Parser    ││
- ┘  └───────────────┘  └──────────────┘│
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Supervision                         │
- (rsupervision)                       │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Managed Services                       │
- (oneshot, longrun, bundles, virtuals)          │
- ┘

##### Important Details to Highlight

a. Service Types:
- Oneshot (short-lived processes)
- Longrun (daemons)
- Bundles (service groups)
- Virtual Services

b. Operating Modes:
- Root Mode
- User Mode
- Project Mode

##### Technical Details to Note

- IPC mechanisms between components
- Process supervision details
- Configuration parsing flow
- Service state management

##### The different modes of operation

This system design should accurately represent rinit's architecture while highlighting its key features: service management, dependency handling, and process supervision.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        CTL["Control Interface (rctl)"]
        CMD["Command Processing"]
        CMDS["Core Commands"]
    end

    subgraph SM["Service Management Layer"]
        SVC["Service Manager (rsvc)"]
        LSM["Live Service Management"]
        SG["Service Graph"]
        RH["Request Handler"]
    end

    subgraph SUP["Supervision Layer"]
        PSUP["Process Supervisor"]
        SCRIPT["Script Execution"]
        PROC["Process Management"]
    end

    subgraph ST["Service Types"]
        ONE["Oneshot Services"]
        LONG["Longrun Services"]
        BUND["Bundle Services"]
        VIRT["Virtual Services"]
    end

    subgraph CFG["Configuration Layer"]
        PARS["Service Parser"]
        SECT["Section Parser"]
    end

    subgraph DEP["Dependency Layer"]
        DG["Dependency Graph"]
        GN["Graph Node"]
    end

    subgraph IPC["IPC System"]
        REQ["Request System"]
        REP["Reply System"]
        CONN["Async Connection"]
    end

    subgraph STATE["State Management"]
        SS["Service State"]
    end

    %% Relationships
    CTL --> CMD
    CMD --> CMDS
    CTL --> IPC
    IPC --> SVC
    SVC --> LSM
    SVC --> SG
    SVC --> RH
    SVC --> SUP
    SUP --> PSUP
    PSUP --> SCRIPT
    PSUP --> PROC
    PARS --> ST
    ST --> DG
    DG --> GN
    SS --> LSM

    %% Click Events
    click CTL "https://github.com/rinit-org/rinit/tree/main//ctl/"
    click CMD "https://github.com/rinit-org/rinit/tree/main//ctl/src/command/"
    click SVC "https://github.com/rinit-org/rinit/tree/main//svc/"
    click LSM "https://github.com/rinit-org/rinit/blob/main//svc/src/live_service.rs"
    click SG "https://github.com/rinit-org/rinit/blob/main//svc/src/live_service_graph.rs"
    click RH "https://github.com/rinit-org/rinit/blob/main//svc/src/request_handler.rs"
    click ONE "https://github.com/rinit-org/rinit/blob/main//service/src/types/oneshot.rs"
    click LONG "https://github.com/rinit-org/rinit/blob/main//service/src/types/longrun.rs"
    click BUND "https://github.com/rinit-org/rinit/blob/main//service/src/types/bundle.rs"
    click VIRT "https://github.com/rinit-org/rinit/blob/main//service/src/types/virtual_service.rs"
    click DG "https://github.com/rinit-org/rinit/blob/main//service/src/graph/dependency_graph.rs"
    click GN "https://github.com/rinit-org/rinit/blob/main//service/src/graph/node.rs"
    click REQ "https://github.com/rinit-org/rinit/blob/main//ipc/src/request.rs"
    click REP "https://github.com/rinit-org/rinit/blob/main//ipc/src/reply.rs"
    click CONN "https://github.com/rinit-org/rinit/blob/main//ipc/src/async_connection.rs"
    click PARS "https://github.com/rinit-org/rinit/blob/main//parser/src/service/parse_service.rs"
    click SECT "https://github.com/rinit-org/rinit/blob/main//parser/src/parse_section.rs"
    click PSUP "https://github.com/rinit-org/rinit/blob/main//svc/src/supervision/supervisor.rs"
    click SCRIPT "https://github.com/rinit-org/rinit/blob/main//svc/src/supervision/exec_script.rs"
    click PROC "https://github.com/rinit-org/rinit/blob/main//svc/src/supervision/kill_process.rs"
    click SS "https://github.com/rinit-org/rinit/blob/main//service/src/service_state.rs"

    %% Styling
    classDef ui fill:#2374ab
    classDef svc fill:#2a9d8f
    classDef sup fill:#e9c46a
    classDef cfg fill:#f4a261
    classDef dep fill:#e76f51
    classDef ipc fill:#9b5de5
    classDef state fill:#00f5d4

    class CTL,CMD,CMDS ui
    class SVC,LSM,SG,RH svc
    class PSUP,SCRIPT,PROC sup
    class PARS,SECT cfg
    class DG,GN dep
    class REQ,REP,CONN ipc
    class SS state
```
