# mohdsaleh/loops-engineering-for-coding-agents architecture

> Architecture diagram of the GitHub repository mohdsaleh/loops-engineering-for-coding-agents, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohdsaleh/loops-engineering-for-coding-agents
- Repository: https://github.com/mohdsaleh/loops-engineering-for-coding-agents

## Overview

#### Purpose and Entry Points
This repository implements Loop Engineering v3.0 as a local, file-backed orchestration system for coding-agent goals. It operationalizes the documented nine-phase loop with Python CLIs, JSON schemas, event history, projections, and agent-facing packets.

Primary entry points:
- `install.py` installs/bootstrap-copies the system into a target workspace.
- `system/scripts/agenticctl.py` is the control-plane CLI for lifecycle operations.
- `system/protocol/LOOP-ENGINEERING-v3.0.md` defines the canonical agent execution contract.

#### Workspace and Contract Boundary
A target workspace is represented by structured JSON state and requirements, seeded from:
- `system/templates/workspace.json`
- `system/templates/REQUIREMENTS.json`
- `system/templates/PROJECT-SPEC.md`

Schemas make workspace state, goals, requirements, versions, events, and packet formats machine-validatable. This is the key boundary between an LLM/agent’s actions and deterministic protocol enforcement:
- `system/schemas/workspace.schema.json`
- `system/schemas/goal.schema.json`
- `system/schemas/state.schema.json`

#### Goal Intake and Versioned Lifecycle
Goal registration validates and records a new goal before it can enter execution. Goals have explicit lifecycle state and sequential versioning/checkpoint semantics, preventing uncontrolled context carryover between completed and subsequent work.
- `system/scripts/register_goal.py`
- `system/scripts/transition.py`
- `system/schemas/versions.schema.json`

The example goal document shows the expected project-task input shape:
- `examples/goal.project-task.json`

#### Event Store and Materialized Projections
The system uses append-only event recording as the audit source of truth. Current status and other queryable state are rebuilt as projections rather than treated as independently authoritative mutable state.
- `system/scripts/append_event.py`
- `system/scripts/event_store.py`
- `system/scripts/rebuild_projections.py`

This creates an observable, interruptible control flow: lifecycle commands emit events; projections summarize those events into workspace/project status.

#### Planning, Agent Packets, and Knowledge Graph
Execution context is assembled into role-specific packets for maker and verifier agents. A lightweight knowledge graph captures nodes, edges, and manifests for goal-related context and dependencies.
- `system/scripts/build_packets.py`
- `system/scripts/kg.py`
- `system/schemas/maker-packet.schema.json`
- `system/schemas/verifier-packet.schema.json`
- `system/schemas/kg-manifest.schema.json`

Packets are the agent integration boundary: this repository governs inputs, state transitions, and validation, while an external coding agent performs the actual plan/execution work.

#### Verification, Repair Limits, and Stop Gates
Verification is deterministic and schema/requirement-driven before repair is considered. Attempts are recorded, scope is checked, and a stop gate provides explicit termination when retry, confidence, token, or step budgets are exceeded.
- `system/scripts/verify_goal.py`
- `system/scripts/verify_scope.py`
- `system/scripts/record_attempt.py`
- `system/scripts/stop_gate.py`

Relevant contracts include:
- `system/schemas/project-status.schema.json`
- `system/schemas/verifier-packet.schema.json`
- `system/schemas/event.schema.json`

#### Runtime and Deployment Model
The implementation runtime is Python 3.9+ with dependencies declared in `system/scripts/requirements.txt`. It is local-file based: no database, hosted service, LLM provider, queue, or web server is present in the repository. External agentic IDEs or LLM runners consume the protocol/templates and invoke the CLI or scripts.

Operational installation and migration guidance is maintained in:
- `DEPLOYMENT-GUIDE.md`
- `MIGRATION-v2.1-to-v3.0.md`

Main entry points: [`system/scripts/register_goal.py`](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/register_goal.py) (Goal registration), [`system/scripts/agenticctl.py`](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/agenticctl.py) (agenticctl), [`system/scripts/append_event.py`](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/append_event.py) (Event writer), [`system/scripts/build_packets.py`](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/build_packets.py) (Packet builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_contracts["Protocol &amp; Contracts"]
  node_protocol["Loop protocol<br/>execution contract"]
  node_templates["Workspace templates<br/>seed files<br/>[workspace.json]"]
  node_workspace_schemas["Workspace schemas<br/>JSON schemas"]
  node_version_schema["Version schema<br/>JSON schema"]
  node_agent_packet_schemas["Agent packet schemas<br/>JSON schemas"]
end

subgraph group_control["Lifecycle Control"]
  node_agenticctl["agenticctl<br/>control-plane CLI<br/>[agenticctl.py]"]
  node_goal_registration["Goal registration<br/>lifecycle command<br/>[register_goal.py]"]
  node_transition["State transitions<br/>lifecycle command<br/>[transition.py]"]
  node_event_store[("Append-only event store<br/>audit history<br/>[event_store.py]")]
  node_append_event["Event writer<br/>event command<br/>[append_event.py]"]
  node_projections[("Status projections<br/>materialized state")]
end

subgraph group_execution["Agent Execution &amp; Verification"]
  node_packet_builder["Packet builder<br/>context assembler<br/>[build_packets.py]"]
  node_knowledge_graph{{"Knowledge graph<br/>goal context graph<br/>[kg.py]"}}
  node_external_agent(("External coding agent<br/>agent runtime"))
  node_verification["Goal verification<br/>deterministic validator<br/>[verify_goal.py]"]
  node_scope_check["Scope check<br/>repair guard<br/>[verify_scope.py]"]
  node_attempt_log["Attempt recorder<br/>repair history<br/>[record_attempt.py]"]
  node_stop_gate["Stop gate<br/>budget guard<br/>[stop_gate.py]"]
end

node_installer["Installer<br/>bootstrap script<br/>[install.py]"]

node_installer -->|"installs"| node_templates
node_installer -->|"bootstraps"| node_agenticctl
node_protocol -.->|"governs"| node_agenticctl
node_templates -->|"seed data validated by"| node_workspace_schemas
node_agenticctl -->|"invokes"| node_goal_registration
node_goal_registration -->|"validates goal and state"| node_workspace_schemas
node_goal_registration -->|"assigns version under"| node_version_schema
node_goal_registration -->|"records"| node_append_event
node_agenticctl -->|"invokes"| node_transition
node_transition -->|"emits lifecycle event"| node_append_event
node_append_event -->|"appends to"| node_event_store
node_event_store -->|"rebuilt into"| node_projections
node_projections -->|"supplies current context"| node_packet_builder
node_knowledge_graph -->|"supplies dependencies"| node_packet_builder
node_agent_packet_schemas -->|"constrains output"| node_packet_builder
node_packet_builder -->|"delivers maker/verifier packets"| node_external_agent
node_external_agent -->|"submits work for"| node_verification
node_verification -->|"on repair path"| node_scope_check
node_scope_check -->|"approved attempts"| node_attempt_log
node_attempt_log -->|"reports retries"| node_stop_gate
node_stop_gate -->|"permits or halts lifecycle"| node_transition
node_verification -->|"records outcome"| node_append_event

click node_installer "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/install.py"
click node_protocol "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/protocol/LOOP-ENGINEERING-v3.0.md"
click node_templates "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/templates/workspace.json"
click node_workspace_schemas "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/schemas/workspace.schema.json"
click node_version_schema "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/schemas/versions.schema.json"
click node_agent_packet_schemas "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/schemas/maker-packet.schema.json"
click node_agenticctl "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/agenticctl.py"
click node_goal_registration "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/register_goal.py"
click node_transition "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/transition.py"
click node_event_store "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/event_store.py"
click node_append_event "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/append_event.py"
click node_projections "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/rebuild_projections.py"
click node_packet_builder "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/build_packets.py"
click node_knowledge_graph "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/kg.py"
click node_verification "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/verify_goal.py"
click node_scope_check "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/verify_scope.py"
click node_attempt_log "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/record_attempt.py"
click node_stop_gate "https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/stop_gate.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_protocol,node_templates,node_workspace_schemas,node_version_schema,node_agent_packet_schemas toneBlue
class node_agenticctl,node_goal_registration,node_transition,node_event_store,node_append_event,node_projections toneAmber
class node_packet_builder,node_knowledge_graph,node_external_agent,node_verification,node_scope_check,node_attempt_log,node_stop_gate toneMint
class node_installer toneNeutral
```

## Components

### Protocol & Contracts

Machine-validatable workspace and agent boundaries.

- [Loop protocol](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/protocol/LOOP-ENGINEERING-v3.0.md): execution contract · Canonical nine-phase agent contract. · `system/protocol/LOOP-ENGINEERING-v3.0.md`
- [Workspace templates](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/templates/workspace.json): seed files · Initial workspace, requirements, and project specification. · `system/templates/workspace.json`
- [Workspace schemas](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/schemas/workspace.schema.json): JSON schemas · Validates workspace, goal, and lifecycle state. · `system/schemas/workspace.schema.json`
- [Version schema](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/schemas/versions.schema.json): JSON schema · Enforces sequential versions and checkpoints. · `system/schemas/versions.schema.json`
- [Agent packet schemas](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/schemas/maker-packet.schema.json): JSON schemas · Defines maker, verifier, and knowledge-graph packet formats. · `system/schemas/maker-packet.schema.json`

### Lifecycle Control

Local CLI-driven goal orchestration.

- [agenticctl](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/agenticctl.py): control-plane CLI · Runs lifecycle operations in the local workspace. · `system/scripts/agenticctl.py`
- [Goal registration](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/register_goal.py): lifecycle command · Validates and records goals before execution. · `system/scripts/register_goal.py`
- [State transitions](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/transition.py): lifecycle command · Applies explicit goal lifecycle changes. · `system/scripts/transition.py`
- [Append-only event store](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/event_store.py): audit history · Authoritative record of lifecycle activity. · `system/scripts/event_store.py`
- [Event writer](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/append_event.py): event command · `system/scripts/append_event.py`
- [Status projections](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/rebuild_projections.py): materialized state · Rebuilds queryable workspace and project status from events. · `system/scripts/rebuild_projections.py`

### Agent Execution & Verification

Packets, deterministic checks, and bounded repair.

- [Packet builder](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/build_packets.py): context assembler · Builds role-specific execution packets. · `system/scripts/build_packets.py`
- [Knowledge graph](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/kg.py): goal context graph · Captures goal dependencies, nodes, edges, and manifests. · `system/scripts/kg.py`
- **External coding agent**: agent runtime · Consumes packets and performs plan or implementation work.
- [Goal verification](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/verify_goal.py): deterministic validator · Checks requirements and schema-driven completion. · `system/scripts/verify_goal.py`
- [Scope check](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/verify_scope.py): repair guard · Prevents repairs outside allowed scope. · `system/scripts/verify_scope.py`
- [Attempt recorder](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/record_attempt.py): repair history · `system/scripts/record_attempt.py`
- [Stop gate](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/system/scripts/stop_gate.py): budget guard · Terminates retries when configured limits are exceeded. · `system/scripts/stop_gate.py`

### Other components

- [Installer](https://github.com/mohdsaleh/loops-engineering-for-coding-agents/blob/main/install.py): bootstrap script · Copies the system into a target workspace. · `install.py`

## Connections

- Installer → Workspace templates: installs
- Installer → agenticctl: bootstraps
- Loop protocol → agenticctl: governs
- Workspace templates → Workspace schemas: seed data validated by
- agenticctl → Goal registration: invokes
- Goal registration → Workspace schemas: validates goal and state
- Goal registration → Version schema: assigns version under
- Goal registration → Event writer: records
- agenticctl → State transitions: invokes
- State transitions → Event writer: emits lifecycle event
- Event writer → Append-only event store: appends to
- Append-only event store → Status projections: rebuilt into
- Status projections → Packet builder: supplies current context
- Knowledge graph → Packet builder: supplies dependencies
- Agent packet schemas → Packet builder: constrains output
- Packet builder → External coding agent: delivers maker/verifier packets
- External coding agent → Goal verification: submits work for
- Goal verification → Scope check: on repair path
- Scope check → Attempt recorder: approved attempts
- Attempt recorder → Stop gate: reports retries
- Stop gate → State transitions: permits or halts lifecycle
- Goal verification → Event writer: records outcome
