# n0zom1z0/touhou-reconstruction-factory architecture

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

- Interactive diagram: https://gitdiagram.com/n0zom1z0/touhou-reconstruction-factory
- Repository: https://github.com/n0zom1z0/touhou-reconstruction-factory

## Overview

Touhou Reconstruction Factory is a control plane that imports existing game repositories, composes era/toolchain-specific capabilities, and manages evidence through replay, receipt validation, and policy-gated acceptance into a shared truth model. Its user-facing workflow runs through an MCP service and durable jobs; optional repository workspaces support bounded source work. The README documents several operational stages, while source excerpts and the index show selected module references; edges involving unsampled implementations are omitted unless documented.

Main entry points: [`src/reconstruction_factory/job_service.py`](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/job_service.py) (Job service), [`src/reconstruction_factory/replay_runner.py`](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/replay_runner.py) (Replay runner), [`src/reconstruction_factory/acceptance.py`](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/acceptance.py) (Acceptance policy), [`src/reconstruction_factory/ontology.py`](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/ontology.py) (Truth ontology)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Truth and evidence"]
  node_ontology["Truth ontology<br/>[ontology.py]"]
  node_receipts["Oracle receipts<br/>[oracle_receipts.py]"]
end

subgraph group_inputs["Repository inputs"]
  node_adapters["Repository adapters<br/>[base.py]"]
  node_adapter_th04["TH04 adapter<br/>[th04.py]"]
  node_providers["Platform providers<br/>[builtin.py]"]
end

subgraph group_verification["Verification and policy"]
  node_analysis["Analysis gateway<br/>[analysis_mcp.py]"]
  node_replay["Replay runner<br/>[replay_runner.py]"]
  node_drivers["Replay drivers<br/>[replay_drivers.py]"]
  node_identity["Replay identity<br/>[replay_identity.py]"]
  node_acceptance["Acceptance policy<br/>[acceptance.py]"]
  node_artifacts[("Artifact store<br/>[artifact_store.py]")]
  node_mz["MZ analysis<br/>[mz_analysis.py]"]
end

subgraph group_service["Service and workflows"]
  node_mcp["MCP interface<br/>[mcp_server.py]"]
  node_jobsvc["Job service<br/>[job_service.py]"]
  node_jobstore[("Durable jobs<br/>[jobs.py]")]
  node_config["Service config<br/>[service_config.py]"]
  node_workspace["Workspaces<br/>[workspaces.py]"]
  node_repo_work["Repository work<br/>[repository_work.py]"]
end

subgraph group_knowledge["Knowledge and analysis"]
  node_knowledge["Factory knowledge<br/>[knowledge.py]"]
  node_regressions["Regression contracts<br/>[regressions.py]"]
  node_game_knowledge["Game knowledge<br/>[game_knowledge.py]"]
  node_semantic_debt["Semantic debt<br/>[semantic_debt.py]"]
end

node_human(("Human / agent"))

node_human -->|"requests tools"| node_mcp
node_mcp -->|"dispatches jobs"| node_jobsvc
node_mcp -->|"routes analysis"| node_analysis
node_mcp -->|"loads settings"| node_config
node_jobsvc -->|"coordinates jobs"| node_jobstore
node_jobsvc -->|"uses workspaces"| node_workspace
node_jobsvc -->|"runs repository work"| node_repo_work
node_jobsvc -->|"runs replay"| node_replay
node_jobsvc -->|"checks receipts"| node_acceptance
node_adapters -->|"selects adapter"| node_adapter_th04
node_adapter_th04 -->|"builds snapshot"| node_ontology
node_providers -.->|"defines identities"| node_ontology
node_analysis -->|"binds targets"| node_ontology
node_analysis -->|"uses PE analysis"| node_mz
node_replay -->|"dispatches drivers"| node_drivers
node_replay -->|"captures identity"| node_identity
node_replay -->|"creates receipts"| node_receipts
node_replay -->|"stores artifacts"| node_artifacts
node_acceptance -->|"validates receipts"| node_receipts
node_acceptance -->|"verifies artifacts"| node_artifacts
node_acceptance -.->|"accepts truth"| node_ontology
node_knowledge -->|"loads contracts"| node_regressions
node_game_knowledge -->|"validates knowledge"| node_ontology
node_repo_work -.->|"tracks debt"| node_semantic_debt
node_human -.->|"edits bounded work"| node_workspace
node_human -->|"submits evidence"| node_acceptance

click node_mcp "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/mcp_server.py"
click node_jobsvc "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/job_service.py"
click node_jobstore "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/jobs.py"
click node_config "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/service_config.py"
click node_workspace "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/workspaces.py"
click node_repo_work "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/repository_work.py"
click node_ontology "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/ontology.py"
click node_receipts "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/oracle_receipts.py"
click node_adapters "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/adapters/base.py"
click node_adapter_th04 "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/adapters/th04.py"
click node_providers "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/providers/builtin.py"
click node_analysis "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/analysis_mcp.py"
click node_replay "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/replay_runner.py"
click node_drivers "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/replay_drivers.py"
click node_identity "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/replay_identity.py"
click node_acceptance "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/acceptance.py"
click node_artifacts "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/artifact_store.py"
click node_knowledge "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/knowledge.py"
click node_regressions "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/regressions.py"
click node_game_knowledge "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/game_knowledge.py"
click node_semantic_debt "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/semantic_debt.py"
click node_mz "https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/mz_analysis.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_ontology,node_receipts toneBlue
class node_adapters,node_adapter_th04,node_providers toneAmber
class node_analysis,node_replay,node_drivers,node_identity,node_acceptance,node_artifacts,node_mz toneMint
class node_mcp,node_jobsvc,node_jobstore,node_config,node_workspace,node_repo_work toneRose
class node_knowledge,node_regressions,node_game_knowledge,node_semantic_debt,node_human toneIndigo
```

## Components

### Truth and evidence

- [Truth ontology](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/ontology.py): `src/reconstruction_factory/ontology.py`
- [Oracle receipts](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/oracle_receipts.py): `src/reconstruction_factory/oracle_receipts.py`

### Repository inputs

- [Repository adapters](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/adapters/base.py): `src/reconstruction_factory/adapters/base.py`
- [TH04 adapter](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/adapters/th04.py): `src/reconstruction_factory/adapters/th04.py`
- [Platform providers](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/providers/builtin.py): `src/reconstruction_factory/providers/builtin.py`

### Verification and policy

- [Analysis gateway](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/analysis_mcp.py): `src/reconstruction_factory/analysis_mcp.py`
- [Replay runner](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/replay_runner.py): `src/reconstruction_factory/replay_runner.py`
- [Replay drivers](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/replay_drivers.py): `src/reconstruction_factory/replay_drivers.py`
- [Replay identity](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/replay_identity.py): `src/reconstruction_factory/replay_identity.py`
- [Acceptance policy](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/acceptance.py): `src/reconstruction_factory/acceptance.py`
- [Artifact store](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/artifact_store.py): `src/reconstruction_factory/artifact_store.py`
- [MZ analysis](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/mz_analysis.py): `src/reconstruction_factory/mz_analysis.py`

### Service and workflows

- [MCP interface](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/mcp_server.py): `src/reconstruction_factory/mcp_server.py`
- [Job service](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/job_service.py): `src/reconstruction_factory/job_service.py`
- [Durable jobs](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/jobs.py): `src/reconstruction_factory/jobs.py`
- [Service config](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/service_config.py): `src/reconstruction_factory/service_config.py`
- [Workspaces](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/workspaces.py): `src/reconstruction_factory/workspaces.py`
- [Repository work](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/repository_work.py): `src/reconstruction_factory/repository_work.py`

### Knowledge and analysis

- [Factory knowledge](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/knowledge.py): `src/reconstruction_factory/knowledge.py`
- [Regression contracts](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/regressions.py): `src/reconstruction_factory/regressions.py`
- [Game knowledge](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/game_knowledge.py): `src/reconstruction_factory/game_knowledge.py`
- [Semantic debt](https://github.com/n0zom1z0/touhou-reconstruction-factory/blob/main/src/reconstruction_factory/semantic_debt.py): `src/reconstruction_factory/semantic_debt.py`

### Other components

- **Human / agent**

## Connections

- Human / agent → MCP interface: requests tools (evidence: `README.md`)
- MCP interface → Job service: dispatches jobs (evidence: `src/reconstruction_factory/mcp_server.py`)
- MCP interface → Analysis gateway: routes analysis (evidence: `src/reconstruction_factory/mcp_server.py`)
- MCP interface → Service config: loads settings (evidence: `src/reconstruction_factory/mcp_server.py`)
- Job service → Durable jobs: coordinates jobs (evidence: `src/reconstruction_factory/job_service.py`)
- Job service → Workspaces: uses workspaces (evidence: `src/reconstruction_factory/job_service.py`)
- Job service → Repository work: runs repository work (evidence: `src/reconstruction_factory/job_service.py`)
- Job service → Replay runner: runs replay (evidence: `src/reconstruction_factory/job_service.py`)
- Job service → Acceptance policy: checks receipts (evidence: `src/reconstruction_factory/job_service.py`)
- Repository adapters → TH04 adapter: selects adapter (evidence: `src/reconstruction_factory/adapters/__init__.py`)
- TH04 adapter → Truth ontology: builds snapshot (evidence: `src/reconstruction_factory/adapters/th04.py`)
- Platform providers → Truth ontology: defines identities (evidence: `src/reconstruction_factory/providers/builtin.py`)
- Analysis gateway → Truth ontology: binds targets (evidence: `src/reconstruction_factory/analysis_mcp.py`)
- Analysis gateway → MZ analysis: uses PE analysis (evidence: `src/reconstruction_factory/analysis_mcp.py`)
- Replay runner → Replay drivers: dispatches drivers (evidence: `src/reconstruction_factory/replay_runner.py`)
- Replay runner → Replay identity: captures identity (evidence: `src/reconstruction_factory/replay_runner.py`)
- Replay runner → Oracle receipts: creates receipts (evidence: `src/reconstruction_factory/replay_runner.py`)
- Replay runner → Artifact store: stores artifacts (evidence: `src/reconstruction_factory/replay_runner.py`)
- Acceptance policy → Oracle receipts: validates receipts (evidence: `src/reconstruction_factory/acceptance.py`)
- Acceptance policy → Artifact store: verifies artifacts (evidence: `src/reconstruction_factory/acceptance.py`)
- Acceptance policy → Truth ontology: accepts truth (evidence: `src/reconstruction_factory/acceptance.py`)
- Factory knowledge → Regression contracts: loads contracts (evidence: `src/reconstruction_factory/knowledge.py`)
- Game knowledge → Truth ontology: validates knowledge (evidence: `src/reconstruction_factory/game_knowledge.py`)
- Repository work → Semantic debt: tracks debt (evidence: `src/reconstruction_factory/repository_work.py`)
- Human / agent → Workspaces: edits bounded work (evidence: `README.md`)
- Human / agent → Acceptance policy: submits evidence (evidence: `README.md`)
