# claytonaalves/process-guardian architecture

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

- Interactive diagram: https://gitdiagram.com/claytonaalves/process-guardian
- Repository: https://github.com/claytonaalves/process-guardian

## Overview

##### Project Type and Purpose
- This is a lightweight command-line “Process Guardian” utility written in Free Pascal/Lazarus.
- Its sole responsibility is to read a simple INI-style config, launch one or more child processes under Windows, monitor them, and restart any that crash.

##### File Structure Analysis
- Top-level files only:
- Guardian.lpr / .lpi – the Pascal project and IDE project file
- UGuardian.pas – the core Pascal unit implementing the guardian logic
- README.md, LICENSE, .gitignore
- No separate “frontend” or “backend” directories—this is a single executable with no GUI.

##### README Insights
- Defines an INI format with sections per-process.
- Shows keys: command, params, working-dir, optional retries and check-network.
- Implies a loop: load config → spawn processes → detect exit → apply retry logic → restart.

a. Main Components
- Config Loader – parses the INI file into in-memory process definitions
- Supervisor Engine – core loop that starts, monitors, and restarts processes
- OS Interface – wraps Windows API calls for CreateProcess, WaitFor…
- (Optional) Network Checker – if “check-network=yes” enables a network-availability subroutine
- Logger – writes status to console or event log
- Child Processes – as defined in the config file
b. Relationships & Interactions
1. On startup, the Config Loader reads the INI file.
2. Supervisor Engine iterates over each process definition.
3. For each entry, Supervisor uses OS Interface to start the process.
4. Supervisor monitors the child’s exit code.
5. On crash/failure, applies retry policy, possibly invoking Network Checker first.
6. Logger records “started”, “stopped”, “restarting” events.
c. Architectural Patterns
- A single-process, event-driven loop (reactor pattern).
- Clear separation between config parsing, process control, and logging concerns.
d. Key Technologies
- Free Pascal / Lazarus runtime
- Windows API calls (CreateProcess, WaitForSingleObject, etc.)
- Simple INI parsing library (built into Free Pascal’s TIniFile)

## Diagram (Mermaid)

```mermaid
flowchart TD
    direction TB

    %% Internal Modules within CLI Executable
    subgraph "Process Guardian CLI"
        direction TB
        entry["Guardian.lpr\n(Main Executable)"]:::internal
        config["Config Loader"]:::internal
        supervisor["Supervisor Engine"]:::internal
        osif["OS Interface"]:::internal
        netchk["Network Checker"]:::internal
        logger["Logger"]:::internal
    end

    %% External Artifacts and Dependencies
    ini["INI Config File"]:::external
    OS["Windows OS"]:::external
    child["Managed Child Processes"]:::external
    res["Guardian.res\n(Resource Definitions)"]:::external
    readme["README.md\n(Usage & Config Spec)"]:::external
    license["LICENSE"]:::external
    gitig[".gitignore"]:::external
    ide["Guardian.lpi\n(IDE Project File)"]:::external

    %% Data Flows & Control
    ini -->|"parse→definitions"| config
    entry -->|"initialize"| config
    config -->|"load definitions"| supervisor
    supervisor -->|"start→process"| osif
    osif -->|"CreateProcess"| child
    child -->|"exit event"| supervisor
    supervisor -->|"log events"| logger
    supervisor -->|"if check-network"| netchk
    netchk -.->|"network OK?"| supervisor

    %% External Interactions
    supervisor -->|"OS calls"| OS

    %% Artifact Associations
    entry --- ide
    entry --- res
    readme --- ini
    readme --- config
    license --- entry
    gitig --- entry

    %% Click Events
    click entry "https://github.com/claytonaalves/process-guardian/blob/master/Guardian.lpr"
    click ide "https://github.com/claytonaalves/process-guardian/blob/master/Guardian.lpi"
    click config "https://github.com/claytonaalves/process-guardian/blob/master/UGuardian.pas"
    click supervisor "https://github.com/claytonaalves/process-guardian/blob/master/UGuardian.pas"
    click osif "https://github.com/claytonaalves/process-guardian/blob/master/UGuardian.pas"
    click netchk "https://github.com/claytonaalves/process-guardian/blob/master/UGuardian.pas"
    click logger "https://github.com/claytonaalves/process-guardian/blob/master/UGuardian.pas"
    click res "https://github.com/claytonaalves/process-guardian/blob/master/Guardian.res"
    click readme "https://github.com/claytonaalves/process-guardian/blob/master/README.md"
    click license "https://github.com/claytonaalves/process-guardian/tree/master/LICENSE"
    click gitig "https://github.com/claytonaalves/process-guardian/blob/master/.gitignore"

    %% Styles
    classDef internal fill:#add8e6,stroke:#000,stroke-width:1px
    classDef external fill:#90ee90,stroke:#000,stroke-width:1px
    linkStyle 7 stroke-dasharray: 5 5
    linkStyle 8 stroke-dasharray: 5 5
```
