# maciejsmolinski/orchy architecture

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

- Interactive diagram: https://gitdiagram.com/maciejsmolinski/orchy
- Repository: https://github.com/maciejsmolinski/orchy

## Overview

##### Project type and purpose
- Orchy is a small, single‐process “webhook manager” CLI tool that spins up an HTTP server on Node.js (8181 by default) and, upon receiving an authenticated request, reads a JSON configuration, executes shell commands, logs output, and optionally posts to Slack.
- Built in PureScript, compiled via Spago → esbuild into a single Node.js bundle with zero npm dependencies at runtime.

##### File structure
Top‐level files & dirs:
- configuration.json.example – sample JSON definitions of “hooks.”
- package.json / spago.dhall / packages.dhall – build & dependency config for PureScript & esbuild.
- src/
– Main.purs → entrypoint, boots the HTTP server.
– HTTP/Server.purs & HTTP/Client.purs (.js FFI counterparts) → request parsing, routing, HTTP logic.
– Orchestrator/Main.purs (.js FFI in Orchestrator/FS.js) → read & parse configuration.json, select definition.
– System/Commands.purs (.js FFI in System/Commands.js) → spawn shell commands, capture results.
– Notifications/Slack.purs → format & POST messages to Slack.
– Logger.purs → unified logging facade.
– Utilities under HTTP/Utils.purs, System/Environment.purs.
- test/ → PureScript test modules for HTTP client, orchestrator, main logic.

##### Extract insights from README
- HTTP endpoints:
- GET /run?definition=<id>&secret=<token>
- Env vars: PORT, SLACK_HOOK_URL, SLACK_CHANNEL.
- Error and success flows all use structured console logging.
- Modes: local dev via `spago bundle-app --platform=node -w` + nodemon.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "External Clients"
        Client["Client (Browser/curl)"]:::external
    end

    Entry["Node.js Runtime & Entrypoint\nsrc/Main.purs"]:::orch
    Env["Environment Variables\nsrc/System/Environment.purs"]:::orch

    subgraph "HTTP Layer"
        HTTPServer["HTTP Server\nsrc/HTTP/Server.purs\nsrc/HTTP/Server.js"]:::http
        Auth["Auth Layer\n(src/HTTP/Server.purs)"]:::http
        HTTPClient["HTTP Client\nsrc/HTTP/Client.purs\nsrc/HTTP/Client.js"]:::http
        HTTPUtils["HTTP Utilities\nsrc/HTTP/Utils.purs\nsrc/HTTP/Utils.js"]:::http
    end

    subgraph "Orchestration & Execution Layer"
        Orchestrator["Orchestrator Engine\nsrc/Orchestrator/Main.purs"]:::orch
        ConfigLoader["Configuration Loader\nsrc/Orchestrator/FS.purs\nsrc/Orchestrator/FS.js\nsrc/Orchestrator/JSON.purs"]:::ffi
        Commands["Command Executor\nsrc/System/Commands.purs\nsrc/System/Commands.js"]:::ffi
        OSProc["OS Process"]:::external
        Logger["Logger\nsrc/Logger.purs"]:::ffi
    end

    subgraph "Notification Layer"
        Notification["Notification Subsystem\nsrc/Notifications/Slack.purs"]:::ffi
        SlackExt["Slack Webhook\nExternal Service"]:::external
    end

    FileSys["Configuration File\nconfiguration.json.example"]:::external

    %% Flow
    Client -->|"/run" request| HTTPServer
    Entry -->|boots| HTTPServer
    Env -->|injects vars| Entry
    HTTPServer -->|validates secret| Auth
    Auth -->|on success| Orchestrator
    Orchestrator -->|read config| ConfigLoader
    ConfigLoader -->|reads JSON| FileSys
    Orchestrator -->|spawn commands| Commands
    Commands -->|executes| OSProc
    OSProc -->|stdout/stderr| Logger
    Commands -->|sequence result| Logger
    Logger -->|logs outcome| Entry
    Orchestrator -->|on completion| Notification
    Notification -->|POST hook| SlackExt
    HTTPServer -->|return response| Client

    %% Click Events
    click Entry "https://github.com/maciejsmolinski/orchy/blob/master/src/Main.purs"
    click HTTPServer "https://github.com/maciejsmolinski/orchy/blob/master/src/HTTP/Server.purs"
    click HTTPClient "https://github.com/maciejsmolinski/orchy/blob/master/src/HTTP/Client.purs"
    click HTTPUtils "https://github.com/maciejsmolinski/orchy/blob/master/src/HTTP/Utils.purs"
    click Auth "https://github.com/maciejsmolinski/orchy/blob/master/src/HTTP/Server.purs"
    click ConfigLoader "https://github.com/maciejsmolinski/orchy/blob/master/src/Orchestrator/FS.purs"
    click Orchestrator "https://github.com/maciejsmolinski/orchy/blob/master/src/Orchestrator/Main.purs"
    click Commands "https://github.com/maciejsmolinski/orchy/blob/master/src/System/Commands.purs"
    click Logger "https://github.com/maciejsmolinski/orchy/blob/master/src/Logger.purs"
    click Notification "https://github.com/maciejsmolinski/orchy/blob/master/src/Notifications/Slack.purs"
    click Env "https://github.com/maciejsmolinski/orchy/blob/master/src/System/Environment.purs"
    click FileSys "https://github.com/maciejsmolinski/orchy/blob/master/configuration.json.example"

    %% Styles
    classDef http fill:#cce5ff,stroke:#2c7bb6,color:#0b2d59
    classDef orch fill:#d4edda,stroke:#27632a,color:#1b4620
    classDef ffi fill:#fff3cd,stroke:#b38600,color:#664d00
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#343a40
```
