# prinova/pi-agent-codebase-workflows architecture

> Architecture diagram of the GitHub repository prinova/pi-agent-codebase-workflows, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prinova/pi-agent-codebase-workflows
- Repository: https://github.com/prinova/pi-agent-codebase-workflows

## Overview

1. **What this repository is**
   - This is not an application runtime; it is a **Pi package of agent workflows**.
   - Its job is to supply **skills, prompt templates, and shared schemas** that Pi can install and use for codebase understanding, safe changes, architecture review, validation, and doc migration.

2. **Primary packaging boundary**
   - The package is discovered through `package.json` entries for **`pi.skills`** and **`pi.prompts`**.
   - At runtime, Pi loads the content in `skills/` and `prompts/`; there is no server, CLI daemon, or compiled code path in this repo.

3. **Skill subsystem**
   - Each skill lives in `skills/<skill-name>/SKILL.md`.
   - The included skills form the main execution workflows:
     - `safe-start`
     - `codebase-recon`
     - `safe-change`
     - `arch-code-review`
     - `structured-doc-validate`
     - `structured-docs-migration`
   - These are the agent-facing “entrypoints” for structured repo work.

4. **Prompt-template subsystem**
   - The `prompts/` directory contains task-specific markdown templates used by those skills.
   - They are grouped by workflow family:
     - reconstruction (`recon-*`)
     - greenfield start (`safe-start-*`)
     - change/bug/feature/refactor/risk workflows
     - architecture review and validation
   - The prompts are orchestration artifacts, not executable logic.

5. **Shared schema and reference layer**
   - `skills/_shared/references/` is the package’s canonical contract layer.
   - It contains:
     - `artifact-api.md`
     - JSON schemas for all structured artifact types
   - These schemas define the shape of the YAML docs the workflows produce and validate.

6. **Structured-docs architecture**
   - The repo is built around a **structured YAML artifact model**, not prose docs.
   - The logical docs layout is:
     - `<docs-root>/repo/*.yaml`
     - `<docs-root>/scopes/by-path/.../*.yaml`
     - `<docs-root>/scopes/by-domain/.../*.yaml`
   - Core artifacts include inventory, architecture, data flow, invariants, dependency rules, risks, contracts, testing strategy, ADRs, and change guides.

7. **Workspace resolution and storage boundary**
   - Workflows target either a **repo-local structured docs root** or a **global overlay root** under `~/.pi/agent/workspaces/<workspace-fingerprint>/docs/agent/api`.
   - `safe-start` is special: it creates the initial repo-local root at `<workspace_root>/docs/agent/api`.
   - Other skills use the repo-local root only if it already exists; otherwise they fall back to the global overlay.
   - This is a key architectural boundary between the **source repository being analyzed** and the **agent artifact store**.

8. **Data flow through the workflows**
   - Typical flow is: user invokes a skill/prompt → the agent resolves workspace root and docs root → reads existing structured artifacts and source evidence → writes or updates YAML artifacts → validates references and schema shape.
   - The workflows are designed to preserve stable IDs, update by source-of-truth fields, and mark unsupported records stale rather than deleting them.

9. **Scope routing model**
   - `scopes.yaml` is the routing layer for artifact ownership.
   - Path scopes map to `<docs-root>/scopes/by-path/<repo-relative-path>/`.
   - Domain scopes map to `<docs-root>/scopes/by-domain/<slug>/`.
   - This makes the system capable of organizing architecture and change context by code path or by business/domain boundary.

10. **Governance and safety controls**
   - The repo emphasizes **validation-first** and **evidence-backed** updates.
   - `structured-doc-validate` is the explicit audit workflow for schema validity, reference integrity, evidence quality, and granularity.
   - The structured artifact protocol also requires deterministic YAML formatting, read-before-write behavior, and explicit reporting of validation results.

11. **Operational compatibility layer**
   - Root `AGENTS.md` is intentionally kept as a compact harness-facing file.
   - It is generated from `agent-operating-guide.yaml` so systems that do not consume Pi skills/prompts directly still have a minimal operational contract.

12. **Important exclusions**
   - The repo intentionally does **not** generate legacy `docs/agent/*.md` project-agent prose docs as its primary output.
   - The structured YAML artifacts are the canonical interface for downstream automation and agent ingestion.

13. **What to draw in an architecture diagram**
   - Draw the repo as a **content package** with three internal layers:
     - **workflow definitions** in `skills/`
     - **task prompts** in `prompts/`
     - **shared artifact schemas/contracts** in `skills/_shared/references/`
   - Then show outputs going to a **workspace-scoped structured docs root** and, secondarily, to a **root AGENTS.md compatibility file**.
   - The main external dependency is the **Pi runtime/installer**, which interprets these assets and applies them to target workspaces.

14. **Overall architectural summary**
   - This repository is a **documentation-and-governance framework for agentic repo work**.
   - Its architecture centers on standardized artifacts, schema enforcement, scope routing, and workspace-aware storage, rather than code execution or service composition.

Main entry points: [`skills/safe-start/SKILL.md`](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/safe-start/SKILL.md) (safe-start), [`skills/safe-change/SKILL.md`](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/safe-change/SKILL.md) (safe-change), [`skills/_shared/references/schemas`](https://github.com/prinova/pi-agent-codebase-workflows/tree/main/skills/_shared/references/schemas) (schemas), [`package.json`](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/package.json) (package.json)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_package["Package"]
  node_package_json["package.json<br/>pi manifest<br/>[package.json]"]
end

subgraph group_workflows["Workflows"]
  node_skill_safe_start["safe-start<br/>skill<br/>[SKILL.md]"]
  node_skill_recon["codebase-recon<br/>skill<br/>[SKILL.md]"]
  node_skill_safe_change["safe-change<br/>skill<br/>[SKILL.md]"]
  node_skill_arch_review["arch-code-review<br/>skill<br/>[SKILL.md]"]
  node_skill_validate["structured-doc-validate<br/>skill<br/>[SKILL.md]"]
  node_skill_migrate["structured-docs-migration<br/>skill<br/>[SKILL.md]"]
end

subgraph group_prompts["Prompts"]
  node_prompt_safe_start_all["safe-start-all<br/>prompt bundle<br/>[safe-start-all.md]"]
  node_prompt_recon_all["recon-all<br/>prompt bundle<br/>[recon-all.md]"]
  node_prompt_change_family["change prompts<br/>prompt set<br/>[bug-implement.md]"]
  node_prompt_review["review-arch<br/>prompt<br/>[review-arch.md]"]
  node_prompt_validate["validate docs<br/>prompt"]
end

subgraph group_contracts["Contracts"]
  node_artifact_api["artifact API<br/>contract guide<br/>[artifact-api.md]"]
  node_schemas[("schemas<br/>json schema set")]
  node_scopes_schema["scopes routing<br/>schema<br/>[scopes.schema.json]"]
end

subgraph group_storage["Storage"]
  node_workspace_docs[("docs root")]
  node_global_overlay[("overlay root<br/>workspace store")]
  node_agents_compat["AGENTS.md<br/>compat file"]
end

node_pi_runtime(("Pi runtime<br/>installer/runtime"))

node_package_json -->|"registers skills"| node_skill_safe_start
node_package_json -->|"registers prompts"| node_prompt_recon_all
node_package_json -->|"package metadata"| node_pi_runtime
node_pi_runtime -->|"loads"| node_skill_safe_start
node_pi_runtime -->|"loads"| node_skill_safe_change
node_pi_runtime -->|"loads"| node_prompt_validate
node_skill_safe_start -->|"uses prompts"| node_prompt_safe_start_all
node_skill_recon -->|"uses prompts"| node_prompt_recon_all
node_skill_safe_change -->|"uses prompts"| node_prompt_change_family
node_skill_arch_review -->|"uses prompt"| node_prompt_review
node_skill_validate -->|"uses prompt"| node_prompt_validate
node_skill_migrate -->|"depends on"| node_artifact_api
node_skill_recon -->|"reads/writes"| node_schemas
node_skill_safe_change -->|"reads/writes"| node_schemas
node_skill_validate -->|"validates"| node_schemas
node_schemas -->|"includes"| node_scopes_schema
node_skill_safe_start -->|"creates"| node_workspace_docs
node_skill_recon -->|"prefers"| node_workspace_docs
node_skill_safe_change -->|"reads/writes"| node_workspace_docs
node_skill_validate -->|"audits"| node_workspace_docs
node_workspace_docs -.->|"falls back to"| node_global_overlay
node_skill_safe_start -->|"generates"| node_agents_compat
node_artifact_api -->|"governs"| node_workspace_docs
node_scopes_schema -->|"routes"| node_workspace_docs
node_pi_runtime -->|"resolves root"| node_workspace_docs
node_pi_runtime -->|"resolves fallback"| node_global_overlay

click node_package_json "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/package.json"
click node_skill_safe_start "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/safe-start/SKILL.md"
click node_skill_recon "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/codebase-recon/SKILL.md"
click node_skill_safe_change "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/safe-change/SKILL.md"
click node_skill_arch_review "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/arch-code-review/SKILL.md"
click node_skill_validate "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/structured-doc-validate/SKILL.md"
click node_skill_migrate "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/structured-docs-migration/SKILL.md"
click node_prompt_safe_start_all "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/safe-start-all.md"
click node_prompt_recon_all "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/recon-all.md"
click node_prompt_change_family "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/bug-implement.md"
click node_prompt_review "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/review-arch.md"
click node_prompt_validate "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/validate-structured-docs.md"
click node_artifact_api "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/_shared/references/artifact-api.md"
click node_schemas "https://github.com/prinova/pi-agent-codebase-workflows/tree/main/skills/_shared/references/schemas"
click node_scopes_schema "https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/_shared/references/schemas/scopes.schema.json"

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_package_json toneBlue
class node_skill_safe_start,node_skill_recon,node_skill_safe_change,node_skill_arch_review,node_skill_validate,node_skill_migrate toneAmber
class node_prompt_safe_start_all,node_prompt_recon_all,node_prompt_change_family,node_prompt_review,node_prompt_validate toneMint
class node_artifact_api,node_schemas,node_scopes_schema toneRose
class node_workspace_docs,node_global_overlay,node_agents_compat toneIndigo
class node_pi_runtime toneNeutral
```

## Components

### Package

Manifest and installable asset boundary

- [package.json](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/package.json): pi manifest · Declares the package entrypoints for Pi skills and prompts · `package.json`

### Workflows

Agent-facing skills that orchestrate repo tasks

- [safe-start](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/safe-start/SKILL.md): skill · Bootstraps a new structured-docs workspace and initial docs root · `skills/safe-start/SKILL.md`
- [codebase-recon](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/codebase-recon/SKILL.md): skill · Reconstructs inventory, architecture, data flow, and governance artifacts · `skills/codebase-recon/SKILL.md`
- [safe-change](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/safe-change/SKILL.md): skill · Coordinates scoped code or docs changes with validation-aware workflow selection · `skills/safe-change/SKILL.md`
- [arch-code-review](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/arch-code-review/SKILL.md): skill · Runs architecture-focused review workflows and feedback synthesis · `skills/arch-code-review/SKILL.md`
- [structured-doc-validate](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/structured-doc-validate/SKILL.md): skill · Audits schema validity, evidence quality, and reference integrity · `skills/structured-doc-validate/SKILL.md`
- [structured-docs-migration](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/structured-docs-migration/SKILL.md): skill · Migrates and consolidates legacy structured docs into the canonical model · `skills/structured-docs-migration/SKILL.md`

### Prompts

Task templates consumed by workflows

- [safe-start-all](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/safe-start-all.md): prompt bundle · Staged greenfield workflow template set for initial workspace setup · `prompts/safe-start-all.md`
- [recon-all](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/recon-all.md): prompt bundle · Orchestrates the repository reconstruction prompt sequence · `prompts/recon-all.md`
- [change prompts](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/bug-implement.md): prompt set · Bug, feature, refactor, risk, and preflight templates · `prompts/bug-implement.md`
- [review-arch](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/review-arch.md): prompt · Architecture review task template · `prompts/review-arch.md`
- [validate docs](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/prompts/validate-structured-docs.md): prompt · Structured-doc validation task template · `prompts/validate-structured-docs.md`

### Contracts

Shared artifact API and schema layer

- [artifact API](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/_shared/references/artifact-api.md): contract guide · Canonical contract for structured artifact handling and deterministic YAML updates · `skills/_shared/references/artifact-api.md`
- [schemas](https://github.com/prinova/pi-agent-codebase-workflows/tree/main/skills/_shared/references/schemas): json schema set · Schemas for inventory, architecture, scopes, risks, ADRs, and related artifacts · `skills/_shared/references/schemas`
- [scopes routing](https://github.com/prinova/pi-agent-codebase-workflows/blob/main/skills/_shared/references/schemas/scopes.schema.json): schema · Defines path and domain ownership for artifact routing · `skills/_shared/references/schemas/scopes.schema.json`

### Storage

Workspace-scoped structured docs outputs

- **docs root**: structured docs root · Repo-local structured YAML artifact root used by workflows
- **overlay root**: workspace store · Fallback global workspace artifact store under ~/.pi/agent/workspaces/.../docs/agent/api
- **AGENTS.md**: compat file · Compact harness-facing compatibility file generated from operating guidance

### Other components

- **Pi runtime**: installer/runtime · Loads skills and prompts, resolves workspace roots, and applies workflows

## Connections

- package.json → safe-start: registers skills · package.json advertises the skill entrypoints consumed by Pi
- package.json → recon-all: registers prompts · package.json advertises prompt templates consumed by Pi
- package.json → Pi runtime: package metadata · Pi uses the package manifest to discover installable assets
- Pi runtime → safe-start: loads · Runtime loads skill definitions from skills/
- Pi runtime → safe-change: loads · Runtime loads skill definitions from skills/
- Pi runtime → validate docs: loads · Runtime loads prompt templates from prompts/
- safe-start → safe-start-all: uses prompts · Skill orchestrates the staged safe-start prompt flow
- codebase-recon → recon-all: uses prompts · Skill orchestrates repository reconstruction prompts
- safe-change → change prompts: uses prompts · Skill selects the appropriate change workflow templates
- arch-code-review → review-arch: uses prompt · Architecture review skill is driven by the review template
- structured-doc-validate → validate docs: uses prompt · Validation skill is driven by the validation template
- structured-docs-migration → artifact API: depends on · Migration relies on the canonical artifact contract
- codebase-recon → schemas: reads/writes · Reconstruction updates structured YAML artifacts through schemas
- safe-change → schemas: reads/writes · Change workflows preserve and update structured artifact records
- structured-doc-validate → schemas: validates · Validation checks schema shape and reference integrity
- schemas → scopes routing: includes · The schema set includes scope-routing definitions
- safe-start → docs root: creates · Safe-start bootstraps the repo-local structured docs root
- codebase-recon → docs root: prefers · Uses repo-local docs root when available
- safe-change → docs root: reads/writes · Updates repo-local structured artifacts when present
- structured-doc-validate → docs root: audits · Validation inspects the current structured docs root
- docs root → overlay root: falls back to · Workflows use the global overlay when repo-local docs are absent
- safe-start → AGENTS.md: generates · Operational guidance is rendered into a compact harness-facing AGENTS.md
- artifact API → docs root: governs · Defines how structured artifacts are authored and updated
- scopes routing → docs root: routes · Scope mapping assigns artifacts to path or domain subtrees
- Pi runtime → docs root: resolves root · Runtime determines the workspace-aware storage location
- Pi runtime → overlay root: resolves fallback · Runtime can target the global overlay workspace store
