# swarmourr/cj architecture

> Architecture diagram of the GitHub repository swarmourr/cj, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swarmourr/cj
- Repository: https://github.com/swarmourr/cj

## Overview

#### Purpose and Entry Points
`chaos-jungle` is a Python chaos-engineering framework for Linux and distributed targets. It injects infrastructure, storage, process, GPU, and LLM/agent faults while measuring and recording experiment outcomes. Primary interfaces are the Python API in `chaos_jungle/__init__.py`, CLI in `chaos_jungle/cli.py`, remote daemon in `chaos_jungle/daemon.py`, and decorator/session conveniences in `chaos_jungle/decorators.py`.

#### Experiment Orchestration
`ChaosRunner` owns the experiment lifecycle: preflight, baseline collection, guarded fault injection, workload execution, chaos collection, cleanup, and persistence. Scenarios group named fault instances; decorators and context managers adapt application code to this runner. Key paths: `chaos_jungle/runner.py`, `chaos_jungle/scenario.py`, `chaos_jungle/decorators.py`.

#### Fault Model and Execution Boundary
Fault implementations share a base abstraction and execute through a target command boundary. Families cover Linux traffic control/BPF, filesystem/storage scripts, process/resource/state changes, gateway behavior, GPU pressure, and LLM/MCP proxy failures. Faults must support reversal, enabling runner cleanup in exceptional paths. Key paths: `chaos_jungle/faults/base.py`, `chaos_jungle/faults/network.py`, `chaos_jungle/faults/llm.py`.

#### Targets and Remote Control
Targets abstract where commands and fault actions run: local host, SSH-connected Linux machines, HTTP daemon endpoints, and logging wrappers. SSH uses Paramiko; HTTP targets delegate control to the installed daemon with bearer-token authentication. This separates controller-side orchestration from privileged target-side execution. Key paths: `chaos_jungle/targets/base.py`, `chaos_jungle/targets/ssh.py`, `chaos_jungle/targets/http.py`.

#### Safety, Validation, and Scheduling
Construction-time validation and preflight checks prevent malformed fault parameters and incompatible or pre-existing system state. Guardrails mediate conflicts with raise/warn/force policies. Separate-mode sessions, timed execution, and multi-experiment scheduling are handled outside core fault definitions. Key paths: `chaos_jungle/guardrails.py`, `chaos_jungle/preflight.py`, `chaos_jungle/scheduler.py`.

#### Measurement, Judgement, and Persistence
Metrics are collected both before and during chaos via built-ins, custom decorated metrics, scripts, and strategies. Results may be evaluated through oracles, hypotheses, and judging components. Session metadata, fault parameters, command events, and results are persisted locally in SQLite, forming the source for exports and UI views. Key paths: `chaos_jungle/metrics/base.py`, `chaos_jungle/db/session_db.py`, `chaos_jungle/oracles.py`.

#### Operations, Reporting, and External Dependencies
The dashboard exposes persisted session status, events, metrics, logs, and system-tool availability through FastAPI/uvicorn. Exporters send results to Datadog, Prometheus, or webhooks. Runtime fault dependencies include Linux `tc`/netem, optional BPF/XDP, and bundled Python/C helper scripts; LLM faults run a local HTTP proxy and redirect client base-URL environment variables. Key paths: `chaos_jungle/dashboard.py`, `chaos_jungle/exporters/base.py`, `chaos_jungle/scripts/llm_proxy/llm_proxy.py`.

#### Parallel Suites
`ExperimentSuite` loads Python- or YAML-defined experiments and coordinates sequential or parallel runs across independently targeted scenarios. It is the higher-level fan-out layer above a single `ChaosRunner` session. Key paths: `chaos_jungle/suite.py`, `chaos_jungle/config.py`, `chaos_jungle/runner.py`.

Main entry points: [`chaos_jungle/runner.py`](https://github.com/swarmourr/cj/blob/main/chaos_jungle/runner.py) (ChaosRunner), [`chaos_jungle/faults/base.py`](https://github.com/swarmourr/cj/blob/main/chaos_jungle/faults/base.py) (Fault abstraction), [`chaos_jungle/suite.py`](https://github.com/swarmourr/cj/blob/main/chaos_jungle/suite.py) (Experiment suite), [`chaos_jungle/targets/base.py`](https://github.com/swarmourr/cj/blob/main/chaos_jungle/targets/base.py) (Target abstraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Interfaces"]
  node_python_api["Python API<br/>public API<br/>[__init__.py]"]
  node_cli["CLI<br/>command interface<br/>[cli.py]"]
  node_decorators["Decorators &amp; sessions<br/>application adapter<br/>[decorators.py]"]
  node_daemon{{"Remote daemon<br/>privileged HTTP control<br/>[daemon.py]"}}
end

subgraph group_control["Experiment control"]
  node_suite["Experiment suite<br/>parallel coordinator<br/>[suite.py]"]
  node_config["Experiment config<br/>suite definitions<br/>[config.py]"]
  node_runner["ChaosRunner<br/>experiment lifecycle<br/>[runner.py]"]
  node_scenario["Scenario<br/>named fault set<br/>[scenario.py]"]
  node_safety["Guardrails &amp; preflight<br/>safety checks<br/>[preflight.py]"]
  node_scheduler["Scheduler<br/>timed execution<br/>[scheduler.py]"]
end

subgraph group_execution["Target execution"]
  node_fault_base["Fault abstraction<br/>reversible fault contract<br/>[base.py]"]
  node_fault_families["Fault families<br/>[network.py]"]
  node_llm_faults["LLM/MCP faults<br/>proxy faults<br/>[llm.py]"]
  node_target_contract["Target abstraction<br/>command boundary<br/>[base.py]"]
  node_ssh_target["SSH target<br/>Paramiko remote execution<br/>[ssh.py]"]
  node_http_target["HTTP target<br/>authenticated daemon client<br/>[http.py]"]
  node_llm_proxy{{"LLM proxy<br/>local HTTP proxy<br/>[llm_proxy.py]"}}
end

subgraph group_observability["Results and operations"]
  node_metrics["Metrics collection<br/>baseline and chaos metrics<br/>[base.py]"]
  node_oracles["Oracles &amp; judgement<br/>result evaluation<br/>[oracles.py]"]
  node_session_db[("Session database<br/>SQLite persistence<br/>[session_db.py]")]
  node_dashboard["Dashboard<br/>FastAPI views<br/>[dashboard.py]"]
  node_exporters["Exporters<br/>external result delivery<br/>[base.py]"]
end

node_python_api -->|"starts experiments"| node_runner
node_cli -->|"runs suites"| node_suite
node_decorators -->|"adapts application code"| node_runner
node_suite -->|"loads definitions"| node_config
node_suite -->|"fans out runs"| node_runner
node_scheduler -->|"times sessions"| node_runner
node_runner -->|"executes"| node_scenario
node_runner -->|"preflight checks"| node_safety
node_runner -->|"collects baseline and chaos"| node_metrics
node_runner -->|"evaluates outcomes"| node_oracles
node_runner -->|"persists lifecycle"| node_session_db
node_scenario -->|"contains faults"| node_fault_base
node_fault_families -->|"implements"| node_fault_base
node_llm_faults -->|"implements"| node_fault_base
node_fault_base -->|"executes through"| node_target_contract
node_target_contract -->|"remote implementation"| node_ssh_target
node_target_contract -->|"daemon implementation"| node_http_target
node_http_target -->|"bearer-auth control"| node_daemon
node_llm_faults -->|"uses"| node_llm_proxy
node_dashboard -->|"reads sessions and events"| node_session_db
node_exporters -->|"publishes results"| node_session_db

click node_python_api "https://github.com/swarmourr/cj/blob/main/chaos_jungle/__init__.py"
click node_cli "https://github.com/swarmourr/cj/blob/main/chaos_jungle/cli.py"
click node_decorators "https://github.com/swarmourr/cj/blob/main/chaos_jungle/decorators.py"
click node_daemon "https://github.com/swarmourr/cj/blob/main/chaos_jungle/daemon.py"
click node_suite "https://github.com/swarmourr/cj/blob/main/chaos_jungle/suite.py"
click node_config "https://github.com/swarmourr/cj/blob/main/chaos_jungle/config.py"
click node_runner "https://github.com/swarmourr/cj/blob/main/chaos_jungle/runner.py"
click node_scenario "https://github.com/swarmourr/cj/blob/main/chaos_jungle/scenario.py"
click node_safety "https://github.com/swarmourr/cj/blob/main/chaos_jungle/preflight.py"
click node_scheduler "https://github.com/swarmourr/cj/blob/main/chaos_jungle/scheduler.py"
click node_fault_base "https://github.com/swarmourr/cj/blob/main/chaos_jungle/faults/base.py"
click node_fault_families "https://github.com/swarmourr/cj/blob/main/chaos_jungle/faults/network.py"
click node_llm_faults "https://github.com/swarmourr/cj/blob/main/chaos_jungle/faults/llm.py"
click node_target_contract "https://github.com/swarmourr/cj/blob/main/chaos_jungle/targets/base.py"
click node_ssh_target "https://github.com/swarmourr/cj/blob/main/chaos_jungle/targets/ssh.py"
click node_http_target "https://github.com/swarmourr/cj/blob/main/chaos_jungle/targets/http.py"
click node_llm_proxy "https://github.com/swarmourr/cj/blob/main/chaos_jungle/scripts/llm_proxy/llm_proxy.py"
click node_metrics "https://github.com/swarmourr/cj/blob/main/chaos_jungle/metrics/base.py"
click node_oracles "https://github.com/swarmourr/cj/blob/main/chaos_jungle/oracles.py"
click node_session_db "https://github.com/swarmourr/cj/blob/main/chaos_jungle/db/session_db.py"
click node_dashboard "https://github.com/swarmourr/cj/blob/main/chaos_jungle/dashboard.py"
click node_exporters "https://github.com/swarmourr/cj/blob/main/chaos_jungle/exporters/base.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_python_api,node_cli,node_decorators,node_daemon toneBlue
class node_suite,node_config,node_runner,node_scenario,node_safety,node_scheduler toneAmber
class node_fault_base,node_fault_families,node_llm_faults,node_target_contract,node_ssh_target,node_http_target,node_llm_proxy toneMint
class node_metrics,node_oracles,node_session_db,node_dashboard,node_exporters toneRose
```

## Components

### Interfaces

- [Python API](https://github.com/swarmourr/cj/blob/main/chaos_jungle/__init__.py): public API · `chaos_jungle/__init__.py`
- [CLI](https://github.com/swarmourr/cj/blob/main/chaos_jungle/cli.py): command interface · `chaos_jungle/cli.py`
- [Decorators & sessions](https://github.com/swarmourr/cj/blob/main/chaos_jungle/decorators.py): application adapter · `chaos_jungle/decorators.py`
- [Remote daemon](https://github.com/swarmourr/cj/blob/main/chaos_jungle/daemon.py): privileged HTTP control · `chaos_jungle/daemon.py`

### Experiment control

- [Experiment suite](https://github.com/swarmourr/cj/blob/main/chaos_jungle/suite.py): parallel coordinator · Loads Python or YAML experiments for sequential or parallel execution. · `chaos_jungle/suite.py`
- [Experiment config](https://github.com/swarmourr/cj/blob/main/chaos_jungle/config.py): suite definitions · `chaos_jungle/config.py`
- [ChaosRunner](https://github.com/swarmourr/cj/blob/main/chaos_jungle/runner.py): experiment lifecycle · Runs preflight, baseline, injection, workload, collection, cleanup, and persistence. · `chaos_jungle/runner.py`
- [Scenario](https://github.com/swarmourr/cj/blob/main/chaos_jungle/scenario.py): named fault set · `chaos_jungle/scenario.py`
- [Guardrails & preflight](https://github.com/swarmourr/cj/blob/main/chaos_jungle/preflight.py): safety checks · Validates parameters, target state, and conflict policy. · `chaos_jungle/preflight.py`
- [Scheduler](https://github.com/swarmourr/cj/blob/main/chaos_jungle/scheduler.py): timed execution · Handles separate-mode sessions and multi-experiment timing. · `chaos_jungle/scheduler.py`

### Target execution

- [Fault abstraction](https://github.com/swarmourr/cj/blob/main/chaos_jungle/faults/base.py): reversible fault contract · `chaos_jungle/faults/base.py`
- [Fault families](https://github.com/swarmourr/cj/blob/main/chaos_jungle/faults/network.py): Linux, GPU, gateway, LLM faults · Includes traffic control/BPF, storage, process, resource, and proxy failures. · `chaos_jungle/faults/network.py`
- [LLM/MCP faults](https://github.com/swarmourr/cj/blob/main/chaos_jungle/faults/llm.py): proxy faults · `chaos_jungle/faults/llm.py`
- [Target abstraction](https://github.com/swarmourr/cj/blob/main/chaos_jungle/targets/base.py): command boundary · `chaos_jungle/targets/base.py`
- [SSH target](https://github.com/swarmourr/cj/blob/main/chaos_jungle/targets/ssh.py): Paramiko remote execution · `chaos_jungle/targets/ssh.py`
- [HTTP target](https://github.com/swarmourr/cj/blob/main/chaos_jungle/targets/http.py): authenticated daemon client · `chaos_jungle/targets/http.py`
- [LLM proxy](https://github.com/swarmourr/cj/blob/main/chaos_jungle/scripts/llm_proxy/llm_proxy.py): local HTTP proxy · Redirects client base-URL environment variables for injected failures. · `chaos_jungle/scripts/llm_proxy/llm_proxy.py`

### Results and operations

- [Metrics collection](https://github.com/swarmourr/cj/blob/main/chaos_jungle/metrics/base.py): baseline and chaos metrics · Supports built-in, custom, script, and strategy metrics. · `chaos_jungle/metrics/base.py`
- [Oracles & judgement](https://github.com/swarmourr/cj/blob/main/chaos_jungle/oracles.py): result evaluation · `chaos_jungle/oracles.py`
- [Session database](https://github.com/swarmourr/cj/blob/main/chaos_jungle/db/session_db.py): SQLite persistence · Stores metadata, fault parameters, command events, and results. · `chaos_jungle/db/session_db.py`
- [Dashboard](https://github.com/swarmourr/cj/blob/main/chaos_jungle/dashboard.py): FastAPI views · Shows persisted session status, events, metrics, logs, and tool availability. · `chaos_jungle/dashboard.py`
- [Exporters](https://github.com/swarmourr/cj/blob/main/chaos_jungle/exporters/base.py): external result delivery · Publishes to Datadog, Prometheus, or webhooks. · `chaos_jungle/exporters/base.py`

## Connections

- Python API → ChaosRunner: starts experiments
- CLI → Experiment suite: runs suites
- Decorators & sessions → ChaosRunner: adapts application code
- Experiment suite → Experiment config: loads definitions
- Experiment suite → ChaosRunner: fans out runs
- Scheduler → ChaosRunner: times sessions
- ChaosRunner → Scenario: executes
- ChaosRunner → Guardrails & preflight: preflight checks
- ChaosRunner → Metrics collection: collects baseline and chaos
- ChaosRunner → Oracles & judgement: evaluates outcomes
- ChaosRunner → Session database: persists lifecycle
- Scenario → Fault abstraction: contains faults
- Fault families → Fault abstraction: implements
- LLM/MCP faults → Fault abstraction: implements
- Fault abstraction → Target abstraction: executes through
- Target abstraction → SSH target: remote implementation
- Target abstraction → HTTP target: daemon implementation
- HTTP target → Remote daemon: bearer-auth control
- LLM/MCP faults → LLM proxy: uses
- Dashboard → Session database: reads sessions and events
- Exporters → Session database: publishes results
