# mitchforest/context-layer architecture

> Architecture diagram of the GitHub repository mitchforest/context-layer, 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/mitchforest/context-layer
- Repository: https://github.com/mitchforest/context-layer

## Overview

#### Purpose

Context Layer is a Claude Code extension that generates and maintains hierarchical `AGENTS.md` architecture documentation for arbitrary codebases. It is not an application runtime; its behavior is expressed through Claude agent prompts, skills, and a shell installer.

#### Installation and Entry Points

The distribution entry point is `install/install.sh`, intended to run from a target project root. It installs the packaged agents and skills into that project’s `.claude/` directory.

User-facing Claude Code commands are defined by the installed skills:
- “Build context layer” — `skills/context-layer.md`
- Rule capture / placement — `skills/add-rule.md`

#### Orchestration Layer

The coordinator is the workflow authority in `agents/context-layer-coordinator.md`. It determines whether the target project needs an initial build, incremental update, review, or issue remediation; discovers documentable functional systems; and controls the capture/synthesis sequence.

It treats generated target-project state such as `.context-layer/manifest.json` and review output as persistent workflow inputs, even though those files are created outside this repository.

#### System Capture Stage

`agents/context-layer-capture.md` defines the per-system analysis worker. For each selected subsystem, it inspects source and dependency relationships and produces a focused `AGENTS.md` describing:
- ownership and exclusions,
- inbound and outbound dependencies,
- integration contracts,
- lifecycle/data flow,
- non-type-enforced invariants.

Capture is intentionally sequential under coordinator control, limiting overlap and allowing later captures to use earlier results.

#### Synthesis Stage

`agents/context-layer-synthesis.md` converts individual system captures into a navigable documentation hierarchy. It aggregates dependencies, identifies parent systems, adds architecture and data-flow context, and moves shared conventions to the lowest common ancestor.

A key preservation boundary is user-authored `## Rules`: synthesis must retain these rather than overwrite them. The resulting hierarchy uses `AGENTS.md` as canonical content and `CLAUDE.md` symlinks for Claude Code compatibility.

#### Rules and Human Knowledge Boundary

`skills/add-rule.md` handles knowledge that cannot reliably be inferred from code: prohibitions, mandatory practices, defaults, and approval gates. It scopes a rule to the appropriate documentation node and can recommend elevating duplicated rules to a shared parent.

This separates generated architectural analysis from durable human policy, while allowing synthesis to reorganize code-derived material safely.

#### Runtime and External Dependencies

The required execution environment is Claude Code, including its agent-spawning capability and model selection (Opus for orchestration/synthesis or major captures; Haiku for smaller updates). Installation requires a POSIX shell plus network access to retrieve `install/install.sh` from GitHub. Generated documentation is designed to be consumable by other AI coding tools that read `AGENTS.md` or `CLAUDE.md`.

Main entry points: [`agents/context-layer-coordinator.md`](https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-coordinator.md) (Context Layer coordinator), [`install/install.sh`](https://github.com/mitchforest/context-layer/blob/main/install/install.sh) (Shell installer), [`agents/context-layer-synthesis.md`](https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-synthesis.md) (Documentation synthesis), [`agents/context-layer-capture.md`](https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-capture.md) (System capture)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_distribution["Distribution"]
  node_installer["Shell installer<br/>[install.sh]"]
end

subgraph group_claude["Claude Code workflow"]
  node_coordinator{{"Context Layer coordinator<br/>workflow agent"}}
  node_capture["System capture<br/>analysis agent"]
  node_synthesis["Documentation synthesis<br/>synthesis agent"]
  node_build_skill["Build context layer<br/>Claude skill<br/>[context-layer.md]"]
  node_rule_skill["Add rule<br/>Claude skill<br/>[add-rule.md]"]
end

subgraph group_target["Target project outputs"]
  node_target_source["Target codebase<br/>analyzed project"]
  node_manifest["Workflow manifest<br/>persistent state"]
  node_captures["System captures<br/>intermediate docs"]
  node_hierarchy["AGENTS.md hierarchy<br/>canonical documentation"]
  node_claude_links["CLAUDE.md symlinks<br/>compatibility output"]
  node_user_rules["User-authored rules<br/>durable policy"]
end

node_claude_code(("Claude Code<br/>execution environment"))
node_ai_consumers(("AI coding tools<br/>documentation consumer"))

node_installer -->|"installs"| node_build_skill
node_installer -->|"installs"| node_rule_skill
node_installer -->|"installs"| node_coordinator
node_installer -->|"installs"| node_capture
node_installer -->|"installs"| node_synthesis
node_claude_code -->|"invokes"| node_build_skill
node_claude_code -->|"invokes"| node_rule_skill
node_build_skill -->|"starts"| node_coordinator
node_coordinator -->|"reads workflow state"| node_manifest
node_coordinator -->|"discovers systems"| node_target_source
node_coordinator -->|"dispatches sequentially"| node_capture
node_capture -->|"inspects"| node_target_source
node_capture -->|"produces"| node_captures
node_coordinator -->|"initiates"| node_synthesis
node_captures -->|"aggregates"| node_synthesis
node_synthesis -->|"writes"| node_hierarchy
node_user_rules -->|"preserves"| node_synthesis
node_rule_skill -->|"places rules"| node_user_rules
node_hierarchy -->|"links via symlinks"| node_claude_links
node_hierarchy -->|"documents architecture"| node_ai_consumers
node_claude_links -->|"compatibility access"| node_ai_consumers

click node_installer "https://github.com/mitchforest/context-layer/blob/main/install/install.sh"
click node_coordinator "https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-coordinator.md"
click node_capture "https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-capture.md"
click node_synthesis "https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-synthesis.md"
click node_build_skill "https://github.com/mitchforest/context-layer/blob/main/skills/context-layer.md"
click node_rule_skill "https://github.com/mitchforest/context-layer/blob/main/skills/add-rule.md"

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_installer toneBlue
class node_coordinator,node_capture,node_synthesis,node_build_skill,node_rule_skill toneAmber
class node_target_source,node_manifest,node_captures,node_hierarchy,node_claude_links,node_user_rules toneMint
class node_claude_code,node_ai_consumers toneNeutral
```

## Components

### Distribution

- [Shell installer](https://github.com/mitchforest/context-layer/blob/main/install/install.sh): installer · Installs packaged agents and skills into a target project. · `install/install.sh`

### Claude Code workflow

- [Context Layer coordinator](https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-coordinator.md): workflow agent · Selects build, update, review, or remediation and controls capture. · `agents/context-layer-coordinator.md`
- [System capture](https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-capture.md): analysis agent · Sequentially documents each selected functional subsystem. · `agents/context-layer-capture.md`
- [Documentation synthesis](https://github.com/mitchforest/context-layer/blob/main/agents/context-layer-synthesis.md): synthesis agent · Builds the documentation hierarchy while preserving user rules. · `agents/context-layer-synthesis.md`
- [Build context layer](https://github.com/mitchforest/context-layer/blob/main/skills/context-layer.md): Claude skill · `skills/context-layer.md`
- [Add rule](https://github.com/mitchforest/context-layer/blob/main/skills/add-rule.md): Claude skill · Captures non-inferable human policy at the appropriate scope. · `skills/add-rule.md`

### Target project outputs

Created in the project being documented.

- **Target codebase**: analyzed project
- **Workflow manifest**: persistent state · Records generated workflow state for subsequent operations.
- **System captures**: intermediate docs · Focused subsystem AGENTS.md analyses.
- **AGENTS.md hierarchy**: canonical documentation · Architecture and data-flow documentation organized by system.
- **CLAUDE.md symlinks**: compatibility output · Claude Code-compatible links to canonical documentation.
- **User-authored rules**: durable policy · Preserved Rules sections for prohibitions, defaults, and approval gates.

### Other components

- **Claude Code**: execution environment · Runs skills and agents with model selection and agent spawning.
- **AI coding tools**: documentation consumer · Tools that consume AGENTS.md or CLAUDE.md.

## Connections

- Shell installer → Build context layer: installs
- Shell installer → Add rule: installs
- Shell installer → Context Layer coordinator: installs
- Shell installer → System capture: installs
- Shell installer → Documentation synthesis: installs
- Claude Code → Build context layer: invokes
- Claude Code → Add rule: invokes
- Build context layer → Context Layer coordinator: starts
- Context Layer coordinator → Workflow manifest: reads workflow state
- Context Layer coordinator → Target codebase: discovers systems
- Context Layer coordinator → System capture: dispatches sequentially
- System capture → Target codebase: inspects
- System capture → System captures: produces
- Context Layer coordinator → Documentation synthesis: initiates
- System captures → Documentation synthesis: aggregates
- Documentation synthesis → AGENTS.md hierarchy: writes
- User-authored rules → Documentation synthesis: preserves
- Add rule → User-authored rules: places rules
- AGENTS.md hierarchy → CLAUDE.md symlinks: links via symlinks
- AGENTS.md hierarchy → AI coding tools: documents architecture
- CLAUDE.md symlinks → AI coding tools: compatibility access
