# aeriesec/orgforge architecture

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

- Interactive diagram: https://gitdiagram.com/aeriesec/orgforge
- Repository: https://github.com/aeriesec/orgforge

## Overview

1. **What this repo is**
OrgForge is a deterministic, event-driven simulation engine for generating synthetic enterprise corpora. The core architectural idea is that a single simulated state machine produces a canonical event log, and all downstream artifacts are derived from that log rather than independently “invented” by LLM calls.

2. **Top-level execution flow**
The main runtime starts in `src/flow.py`, which acts as the simulation orchestrator. It advances day by day, applies org lifecycle changes, asks planners for what should happen next, dispatches those plans into typed activities, and records every significant action as a `SimEvent` in the shared memory/event bus.

3. **Planning boundary vs execution boundary**
`src/day_planner.py` and `src/planner_models.py` handle the LLM-facing planning layer: they propose daily activities per department and define the structured plan objects. `src/plan_validator.py` is the important integrity boundary; it checks the LLM-produced plan before execution so invalid or out-of-sequence actions do not enter the simulation.

4. **Normal-day artifact generation**
`src/normal_day.py` is the dispatcher for routine simulation output. It turns validated activities into concrete artifacts such as Slack chatter, Confluence pages, JIRA tickets, Zoom transcripts, Git PRs, and other day-to-day business output. This is where typed artifact generation happens, but only from already-established simulation facts.

5. **Shared event log and memory**
`src/memory.py` is the central knowledge substrate. It stores the SimEvent stream and supports retrieval for later artifact generation. The architecture is intentionally grounded here: artifacts read facts from the event log, which prevents temporal drift across multi-day output and makes the corpus suitable for evaluation.

6. **Org lifecycle and knowledge gaps**
`src/org_lifecycle.py` models hires, departures, and associated knowledge gaps. Departures are not just HR events; they trigger state changes that affect incident handoffs, ownership, and future explanations in generated artifacts. The README’s “departure cascade” is a key cross-cutting behavior that propagates into planning, graph dynamics, and downstream documents.

7. **Social graph and stress propagation**
`src/graph_dynamics.py` maintains the weighted relationship graph for the organization. It drives stress propagation, edge decay, escalation routing, and recomputation of centrality after roster changes. This subsystem is important because it influences who gets pulled into incidents, how load shifts after departures, and how morale/stress evolves over time.

8. **CRM and customer-facing propagation**
`src/crm_system.py` manages Salesforce and Zendesk behavior as a coupled domain. When incidents occur, the simulation can propagate effects into customer support tickets, account risk flags, opportunity status, and escalations. This is a major boundary because it links internal engineering events to customer-impact artifacts.

9. **Specialized domain handlers**
Several modules generate domain-specific outputs from shared simulation state: `src/confluence_writer.py`, `src/external_email_ingest.py`, `src/ticket_assigner.py`, `src/causal_chain_handler.py`, and `src/post_sim_artifacts.py`. They are not separate sources of truth; they are consumers of the event log and simulation state, each responsible for one output surface or post-processing step.

10. **Stateful world components**
`src/sim_clock.py` provides deterministic time progression; `src/genesis.py` and `src/org_lifecycle.py` bootstrap the org state; `src/artifact_registry.py` tracks artifact types and outputs; `src/agent_factory.py` and `src/flow.py` coordinate the roles that participate in the simulation. Together these form the internal world model that the planner and artifact writers operate against.

11. **Insider threat as an isolated overlay**
`src/insider_threat.py` adds an optional adversarial layer without contaminating the normal simulation path. When enabled, it emits separate security telemetry and keeps ground truth distinct from normal enterprise artifacts. This is architecturally important because the threat signals are an orthogonal data stream, not part of the main business-event corpus.

12. **Embedding and retrieval support**
`src/embed_worker.py` supports vector embedding generation for memory/RAG-style workflows. The README indicates the project can use local Ollama models, AWS Bedrock, OpenAI embeddings, or local GPU models depending on `config/config.yaml`. That means model choice is a deployment/runtime concern, while the simulation semantics remain the same.

13. **Configuration and deployment boundaries**
`config/config.yaml` is the single source of truth for company structure, personas, lifecycle schedules, quality presets, and external contacts. The repo is containerized with Docker and `docker-compose.yaml`, and can run with MongoDB plus either local Ollama or cloud LLM services. Those infrastructure choices affect how model calls and persistence are wired, but not the core simulation architecture.

14. **Evaluation and export pipeline**
The `eval/` subtree contains dataset export and insider-threat evaluation scripts, including HuggingFace export support. This is a downstream analysis layer, separate from simulation generation. It consumes exported artifacts and ground truth to benchmark retrieval, rescore outputs, and package datasets for external use.

15. **Testing and correctness strategy**
The `tests/` directory covers the major architectural seams: flow, lifecycle, memory, planning, routing, CRM behavior, external email handling, insider threat, and post-simulation artifacts. That test layout mirrors the subsystem boundaries and reinforces that the repo’s correctness depends on deterministic state transitions and consistent cross-artifact grounding.

Main entry points: [`src/memory.py`](https://github.com/aeriesec/orgforge/blob/main/src/memory.py) (Memory), [`src/flow.py`](https://github.com/aeriesec/orgforge/blob/main/src/flow.py) (Flow), [`src/normal_day.py`](https://github.com/aeriesec/orgforge/blob/main/src/normal_day.py) (Normal day), [`src/genesis.py`](https://github.com/aeriesec/orgforge/blob/main/src/genesis.py) (Genesis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Simulation core"]
  node_flow["Flow<br/>orchestrator<br/>[flow.py]"]
  node_clock(("Clock<br/>time engine<br/>[sim_clock.py]"))
  node_genesis["Genesis<br/>bootstrap<br/>[genesis.py]"]
  node_lifecycle["Lifecycle<br/>org state<br/>[org_lifecycle.py]"]
  node_graph{{"Graph<br/>[graph_dynamics.py]"}}
  node_planner["Planner<br/>[day_planner.py]"]
  node_plan_models["Plan models<br/>schema<br/>[planner_models.py]"]
  node_validator{{"Validator<br/>integrity gate<br/>[plan_validator.py]"}}
  node_memory[("Memory<br/>event log<br/>[memory.py]")]
end

subgraph group_domains["Domain outputs"]
  node_normal_day["Normal day<br/>dispatcher<br/>[normal_day.py]"]
  node_crm["CRM<br/>customer domain<br/>[crm_system.py]"]
  node_confluence["Confluence<br/>doc writer"]
  node_email["Email ingest<br/>external input"]
  node_tickets["Ticketing<br/>routing<br/>[ticket_assigner.py]"]
  node_causal["Causal chain<br/>postprocess"]
  node_postsim["Post-sim<br/>export"]
  node_threat{{"Insider threat<br/>overlay<br/>[insider_threat.py]"}}
end

subgraph group_infra["Config and runtime"]
  node_embed(("Embedding<br/>retrieval worker<br/>[embed_worker.py]"))
  node_config["Config<br/>[config.yaml]"]
end

subgraph group_eval["Evaluation"]
  node_evalexp["Export<br/>[export_to_hf.py]"]
  node_evalthreat["Threat eval<br/>benchmark"]
end

node_config -->|"bootstrap"| node_genesis
node_genesis -->|"start"| node_flow
node_clock -->|"ticks"| node_flow
node_flow -->|"applies"| node_lifecycle
node_flow -->|"updates"| node_graph
node_flow -->|"requests"| node_planner
node_planner -->|"produces"| node_plan_models
node_plan_models -->|"validated by"| node_validator
node_validator -->|"approves"| node_normal_day
node_flow -->|"records"| node_memory
node_normal_day -->|"reads/writes"| node_memory
node_memory -->|"retrieves"| node_normal_day
node_normal_day -->|"writes"| node_confluence
node_normal_day -->|"updates"| node_crm
node_normal_day -->|"routes"| node_tickets
node_email -->|"ingests"| node_memory
node_causal -->|"explains"| node_memory
node_postsim -->|"exports"| node_evalexp
node_threat -.->|"separates"| node_memory
node_embed -->|"indexes"| node_memory
node_flow -.->|"optional"| node_threat
node_memory -->|"benchmarks"| node_evalthreat

click node_flow "https://github.com/aeriesec/orgforge/blob/main/src/flow.py"
click node_clock "https://github.com/aeriesec/orgforge/blob/main/src/sim_clock.py"
click node_genesis "https://github.com/aeriesec/orgforge/blob/main/src/genesis.py"
click node_lifecycle "https://github.com/aeriesec/orgforge/blob/main/src/org_lifecycle.py"
click node_graph "https://github.com/aeriesec/orgforge/blob/main/src/graph_dynamics.py"
click node_planner "https://github.com/aeriesec/orgforge/blob/main/src/day_planner.py"
click node_plan_models "https://github.com/aeriesec/orgforge/blob/main/src/planner_models.py"
click node_validator "https://github.com/aeriesec/orgforge/blob/main/src/plan_validator.py"
click node_memory "https://github.com/aeriesec/orgforge/blob/main/src/memory.py"
click node_normal_day "https://github.com/aeriesec/orgforge/blob/main/src/normal_day.py"
click node_crm "https://github.com/aeriesec/orgforge/blob/main/src/crm_system.py"
click node_confluence "https://github.com/aeriesec/orgforge/blob/main/src/confluence_writer.py"
click node_email "https://github.com/aeriesec/orgforge/blob/main/src/external_email_ingest.py"
click node_tickets "https://github.com/aeriesec/orgforge/blob/main/src/ticket_assigner.py"
click node_causal "https://github.com/aeriesec/orgforge/blob/main/src/causal_chain_handler.py"
click node_postsim "https://github.com/aeriesec/orgforge/blob/main/src/post_sim_artifacts.py"
click node_threat "https://github.com/aeriesec/orgforge/blob/main/src/insider_threat.py"
click node_embed "https://github.com/aeriesec/orgforge/blob/main/src/embed_worker.py"
click node_config "https://github.com/aeriesec/orgforge/blob/main/config/config.yaml"
click node_evalexp "https://github.com/aeriesec/orgforge/blob/main/eval/export_to_hf.py"
click node_evalthreat "https://github.com/aeriesec/orgforge/blob/main/eval/insider_threat/eval_insider_threat.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_flow,node_clock,node_genesis,node_lifecycle,node_graph,node_planner,node_plan_models,node_validator,node_memory toneBlue
class node_normal_day,node_crm,node_confluence,node_email,node_tickets,node_causal,node_postsim,node_threat toneAmber
class node_embed,node_config toneMint
class node_evalexp,node_evalthreat toneRose
```

## Components

### Simulation core

Deterministic runtime, planning, memory, and state transitions.

- [Flow](https://github.com/aeriesec/orgforge/blob/main/src/flow.py): orchestrator · Main day-by-day simulation runtime. · `src/flow.py`
- [Clock](https://github.com/aeriesec/orgforge/blob/main/src/sim_clock.py): time engine · Deterministic simulation time progression. · `src/sim_clock.py`
- [Genesis](https://github.com/aeriesec/orgforge/blob/main/src/genesis.py): bootstrap · Initial org and world-state construction. · `src/genesis.py`
- [Lifecycle](https://github.com/aeriesec/orgforge/blob/main/src/org_lifecycle.py): org state · Hires, departures, and knowledge-gap transitions. · `src/org_lifecycle.py`
- [Graph](https://github.com/aeriesec/orgforge/blob/main/src/graph_dynamics.py): social graph · Weighted relationships, stress propagation, and centrality updates. · `src/graph_dynamics.py`
- [Planner](https://github.com/aeriesec/orgforge/blob/main/src/day_planner.py): LLM planner · Daily activity proposal layer. · `src/day_planner.py`
- [Plan models](https://github.com/aeriesec/orgforge/blob/main/src/planner_models.py): schema · Structured plan and activity definitions. · `src/planner_models.py`
- [Validator](https://github.com/aeriesec/orgforge/blob/main/src/plan_validator.py): integrity gate · Checks planned activities before execution. · `src/plan_validator.py`
- [Memory](https://github.com/aeriesec/orgforge/blob/main/src/memory.py): event log · Canonical SimEvent store and retrieval substrate. · `src/memory.py`

### Domain outputs

Concrete business and security artifact generation surfaces.

- [Normal day](https://github.com/aeriesec/orgforge/blob/main/src/normal_day.py): dispatcher · Routes validated activities into routine artifacts. · `src/normal_day.py`
- [CRM](https://github.com/aeriesec/orgforge/blob/main/src/crm_system.py): customer domain · Salesforce and Zendesk coupled customer-impact state. · `src/crm_system.py`
- [Confluence](https://github.com/aeriesec/orgforge/blob/main/src/confluence_writer.py): doc writer · Generates knowledge-base pages from simulation facts. · `src/confluence_writer.py`
- [Email ingest](https://github.com/aeriesec/orgforge/blob/main/src/external_email_ingest.py): external input · Processes external email-driven signals. · `src/external_email_ingest.py`
- [Ticketing](https://github.com/aeriesec/orgforge/blob/main/src/ticket_assigner.py): routing · Assigns and routes operational tickets. · `src/ticket_assigner.py`
- [Causal chain](https://github.com/aeriesec/orgforge/blob/main/src/causal_chain_handler.py): postprocess · Derives linked event narratives and explanations. · `src/causal_chain_handler.py`
- [Post-sim](https://github.com/aeriesec/orgforge/blob/main/src/post_sim_artifacts.py): export · Generates final artifacts after simulation ends. · `src/post_sim_artifacts.py`
- [Insider threat](https://github.com/aeriesec/orgforge/blob/main/src/insider_threat.py): overlay · Optional adversarial telemetry stream. · `src/insider_threat.py`

### Config and runtime

Configuration, embedding, persistence, and deployment boundaries.

- [Embedding](https://github.com/aeriesec/orgforge/blob/main/src/embed_worker.py): retrieval worker · Builds vectors for memory and RAG workflows. · `src/embed_worker.py`
- [Config](https://github.com/aeriesec/orgforge/blob/main/config/config.yaml): runtime config · Company, personas, schedules, and model settings. · `config/config.yaml`

### Evaluation

Export and benchmarking workflows.

- [Export](https://github.com/aeriesec/orgforge/blob/main/eval/export_to_hf.py): dataset export · Converts artifacts for external evaluation use. · `eval/export_to_hf.py`
- [Threat eval](https://github.com/aeriesec/orgforge/blob/main/eval/insider_threat/eval_insider_threat.py): benchmark · Insider-threat evaluation and rescoring pipeline. · `eval/insider_threat/eval_insider_threat.py`

## Connections

- Config → Genesis: bootstrap · Configuration seeds initial org state.
- Genesis → Flow: start · Initial world state enters the main runtime.
- Clock → Flow: ticks · Deterministic time advances the simulation.
- Flow → Lifecycle: applies · Roster and ownership changes are executed.
- Flow → Graph: updates · Relationship graph is recomputed after state changes.
- Flow → Planner: requests · Daily planning is generated from current state.
- Planner → Plan models: produces · LLM-facing planner emits structured plans.
- Plan models → Validator: validated by · Plan schema and sequencing are checked before execution.
- Validator → Normal day: approves · Only valid activities reach the dispatcher.
- Flow → Memory: records · Significant actions are appended as canonical events.
- Normal day → Memory: reads/writes · Routine artifact generation consumes and emits grounded facts.
- Memory → Normal day: retrieves · Artifacts are derived from prior event log context.
- Normal day → Confluence: writes · Generates knowledge-base pages.
- Normal day → CRM: updates · Propagates incidents into customer-facing systems.
- Normal day → Ticketing: routes · Creates and assigns operational tickets.
- Email ingest → Memory: ingests · External mail becomes simulation-grounded evidence.
- Causal chain → Memory: explains · Derives narrative chains from the event log.
- Post-sim → Export: exports · Final corpus is packaged for downstream analysis.
- Insider threat → Memory: separates · Security telemetry remains an orthogonal stream.
- Embedding → Memory: indexes · Embeddings support retrieval over stored events.
- Flow → Insider threat: optional · Adversarial overlay may run alongside normal simulation.
- Memory → Threat eval: benchmarks · Ground truth and outputs support insider-threat evaluation.
