Architecture Normalizer
Purpose
Use this skill as an architecture normalization engine, not as a general refactoring assistant. Its job is to move a repository toward deterministic, high-cohesion, low-coupling module hierarchy while preserving behavior and public APIs.
The central rule: every architectural decision must be produced as an explicit reviewable artifact before any source file is changed.
Required References
- Read
references/policy-format.md before creating, editing, or applying architecture policies.
- Read
references/artifact-contract.md before generating, reviewing, or executing .architecture/ artifacts.
- Read
references/analysis-signals.md when scoring cohesion, coupling, entropy, god files/classes/packages, split candidates, or dependency risk.
- Use
scripts/repo_fingerprint.py <repo> --json for manifest repository hashes and execution preflight checks.
Non-Negotiable Contract
- Do not modify source files during Analysis. Analysis may only create or update
.architecture/ artifacts.
- Do not execute normalization without completed Analysis artifacts and explicit approval for the specific actions being executed.
- During Execution, never invent moves, splits, renames, import updates, exports, compatibility layers, or deletes. Execute approved artifact actions only.
- Preserve public imports and exports whenever possible. Generate compatibility exports for moved public API paths.
- Load policies before analysis. Do not hardcode language thresholds, layout rules, public API rules, or allowed dependency rules into the plan.
- Keep output deterministic: sorted paths, stable action IDs, stable artifact filenames, and stable YAML/JSON ordering where feasible.
- Stop when the repository fingerprint differs from the manifest, artifacts conflict, a policy is missing or ambiguous, or validation cannot be run.
- Do not print or store secrets. Prefer structural evidence: imports, exported symbols, file names, non-secret config keys, tests, and public APIs.
Phase 0: Policy Loading
- Inspect repository structure and dependency/config files enough to identify languages and tooling.
- Load existing policies from
.architecture/policy.yaml or .architecture/policies/*.yaml when present.
- If no approved policy exists, resolve a conservative baseline policy from
references/policy-format.md, write it under .architecture/policies/<language>.yaml with status: proposed, and mark all execution actions unapproved.
- Record the resolved policy files and versions in
.architecture/manifest.yaml.
Execution is forbidden when the relevant policy is only proposed, rejected, missing, or internally inconsistent.
Phase 1: Architecture Analysis
Analysis is read-only for repository source files. It must generate deterministic artifacts inside .architecture/.
Required analysis behavior:
- Compute the repository fingerprint with
scripts/repo_fingerprint.py.
- Detect single-responsibility violations, multiple public types, god files, god classes, god packages, cyclic imports, dead code candidates, duplicate models/DTOs/enums/errors, forbidden generic names, large files/classes/functions, hidden public APIs, layer violations, dependency violations, feature envy, and architecture entropy.
- Generate explicit remediation artifacts for every proposed change.
- Use stable IDs such as
MOVE-0001, SPLIT-0001, RENAME-0001, IMPORT-0001, EXPORT-0001, and COMPAT-0001.
- Sort actions by normalized source path, action kind, then destination path.
- Include evidence and rationale for every action. Evidence should cite files, symbols, imports, exported APIs, tests, or dependency edges.
- Use
generated_at: null unless a deterministic repository-derived timestamp is available, such as the HEAD commit timestamp.
Required artifact set:
.architecture/manifest.yaml
.architecture/analysis.md
.architecture/entropy.json
.architecture/dependency-graph.graphml
.architecture/package-layout.graphml
.architecture/move-plan.yaml
.architecture/split-plan.yaml
.architecture/rename-plan.yaml
.architecture/imports-plan.yaml
.architecture/exports-plan.yaml
.architecture/compatibility-plan.yaml
.architecture/risk-report.yaml
.architecture/validation-plan.yaml
If a graph format cannot be produced with available tooling, create the file with a deterministic placeholder graph containing the nodes/edges that were derived and record the tooling gap in risk-report.yaml.
Phase 2: Human Review
Artifacts are the review boundary.
- Treat user edits to artifacts as authoritative unless they violate the non-negotiable contract.
- Execute only actions with
status: approved or with an explicit current user instruction approving the exact action set.
- Treat missing, proposed, rejected, stale, or conflicting actions as not executable.
- If review changes introduce new decisions, return to Analysis and regenerate affected artifacts before execution.
Phase 3: Architecture Execution
Execution reads approved artifacts only. It must not perform fresh architectural analysis.
Before editing source files:
- Recompute the repository fingerprint.
- Compare it with
.architecture/manifest.yaml.
- Inspect
git status --short and avoid overwriting unrelated user changes.
- Stop if the repository changed, unless the user explicitly asks to regenerate Analysis.
During execution:
- Prefer
git mv for file moves.
- Apply approved moves, splits, renames, import updates, public exports, and compatibility layers in dependency-safe order.
- Preserve public APIs through explicit exports: Python
__init__.py, TypeScript/JavaScript index.ts or index.js, Rust pub use, Go exported symbols, C/C++ public headers.
- Do not use wildcard exports.
- Delete obsolete files only when an approved delete action exists.
- If a needed action is missing, stop and write
.architecture/execution-blockers.yaml.
Execution must be idempotent. Running it twice against the same approved artifacts should produce no further source changes.
Phase 4: Validation
Validation is mandatory after execution.
Run the validation commands declared by policy and confirmed from repository configuration when available:
- formatter
- linter
- compiler or type checker
- unit and integration tests
- import/public API validation
- architecture layout validation
Record validation commands and results in .architecture/validation-results.yaml. Report failure exactly; do not claim success unless commands were run and passed.
Output Discipline
When reporting results:
- Separate Analysis, Review, Execution, and Validation status.
- List generated or changed artifacts.
- List source files changed only after Execution.
- Include exact validation commands and outcomes.
- State when execution was refused because approval, policy, fingerprint, or validation gates were not satisfied.
1---2name: architecture-normalizer3description: Decomposes large modules, god files, classes, or packages in reviewable steps while preserving public APIs. Not for routine refactors.4---56# Architecture Normalizer78## Purpose910Use this skill as an architecture normalization engine, not as a general refactoring assistant. Its job is to move a repository toward deterministic, high-cohesion, low-coupling module hierarchy while preserving behavior and public APIs.1112The central rule: every architectural decision must be produced as an explicit reviewable artifact before any source file is changed.1314## Required References1516- Read `references/policy-format.md` before creating, editing, or applying architecture policies.17- Read `references/artifact-contract.md` before generating, reviewing, or executing `.architecture/` artifacts.18- Read `references/analysis-signals.md` when scoring cohesion, coupling, entropy, god files/classes/packages, split candidates, or dependency risk.19- Use `scripts/repo_fingerprint.py <repo> --json` for manifest repository hashes and execution preflight checks.2021## Non-Negotiable Contract2223- Do not modify source files during Analysis. Analysis may only create or update `.architecture/` artifacts.24- Do not execute normalization without completed Analysis artifacts and explicit approval for the specific actions being executed.25- During Execution, never invent moves, splits, renames, import updates, exports, compatibility layers, or deletes. Execute approved artifact actions only.26- Preserve public imports and exports whenever possible. Generate compatibility exports for moved public API paths.27- Load policies before analysis. Do not hardcode language thresholds, layout rules, public API rules, or allowed dependency rules into the plan.28- Keep output deterministic: sorted paths, stable action IDs, stable artifact filenames, and stable YAML/JSON ordering where feasible.29- Stop when the repository fingerprint differs from the manifest, artifacts conflict, a policy is missing or ambiguous, or validation cannot be run.30- Do not print or store secrets. Prefer structural evidence: imports, exported symbols, file names, non-secret config keys, tests, and public APIs.3132## Phase 0: Policy Loading33341. Inspect repository structure and dependency/config files enough to identify languages and tooling.352. Load existing policies from `.architecture/policy.yaml` or `.architecture/policies/*.yaml` when present.363. If no approved policy exists, resolve a conservative baseline policy from `references/policy-format.md`, write it under `.architecture/policies/<language>.yaml` with `status: proposed`, and mark all execution actions unapproved.374. Record the resolved policy files and versions in `.architecture/manifest.yaml`.3839Execution is forbidden when the relevant policy is only proposed, rejected, missing, or internally inconsistent.4041## Phase 1: Architecture Analysis4243Analysis is read-only for repository source files. It must generate deterministic artifacts inside `.architecture/`.4445Required analysis behavior:4647- Compute the repository fingerprint with `scripts/repo_fingerprint.py`.48- Detect single-responsibility violations, multiple public types, god files, god classes, god packages, cyclic imports, dead code candidates, duplicate models/DTOs/enums/errors, forbidden generic names, large files/classes/functions, hidden public APIs, layer violations, dependency violations, feature envy, and architecture entropy.49- Generate explicit remediation artifacts for every proposed change.50- Use stable IDs such as `MOVE-0001`, `SPLIT-0001`, `RENAME-0001`, `IMPORT-0001`, `EXPORT-0001`, and `COMPAT-0001`.51- Sort actions by normalized source path, action kind, then destination path.52- Include evidence and rationale for every action. Evidence should cite files, symbols, imports, exported APIs, tests, or dependency edges.53- Use `generated_at: null` unless a deterministic repository-derived timestamp is available, such as the HEAD commit timestamp.5455Required artifact set:5657- `.architecture/manifest.yaml`58- `.architecture/analysis.md`59- `.architecture/entropy.json`60- `.architecture/dependency-graph.graphml`61- `.architecture/package-layout.graphml`62- `.architecture/move-plan.yaml`63- `.architecture/split-plan.yaml`64- `.architecture/rename-plan.yaml`65- `.architecture/imports-plan.yaml`66- `.architecture/exports-plan.yaml`67- `.architecture/compatibility-plan.yaml`68- `.architecture/risk-report.yaml`69- `.architecture/validation-plan.yaml`7071If a graph format cannot be produced with available tooling, create the file with a deterministic placeholder graph containing the nodes/edges that were derived and record the tooling gap in `risk-report.yaml`.7273## Phase 2: Human Review7475Artifacts are the review boundary.7677- Treat user edits to artifacts as authoritative unless they violate the non-negotiable contract.78- Execute only actions with `status: approved` or with an explicit current user instruction approving the exact action set.79- Treat missing, proposed, rejected, stale, or conflicting actions as not executable.80- If review changes introduce new decisions, return to Analysis and regenerate affected artifacts before execution.8182## Phase 3: Architecture Execution8384Execution reads approved artifacts only. It must not perform fresh architectural analysis.8586Before editing source files:87881. Recompute the repository fingerprint.892. Compare it with `.architecture/manifest.yaml`.903. Inspect `git status --short` and avoid overwriting unrelated user changes.914. Stop if the repository changed, unless the user explicitly asks to regenerate Analysis.9293During execution:9495- Prefer `git mv` for file moves.96- Apply approved moves, splits, renames, import updates, public exports, and compatibility layers in dependency-safe order.97- Preserve public APIs through explicit exports: Python `__init__.py`, TypeScript/JavaScript `index.ts` or `index.js`, Rust `pub use`, Go exported symbols, C/C++ public headers.98- Do not use wildcard exports.99- Delete obsolete files only when an approved delete action exists.100- If a needed action is missing, stop and write `.architecture/execution-blockers.yaml`.101102Execution must be idempotent. Running it twice against the same approved artifacts should produce no further source changes.103104## Phase 4: Validation105106Validation is mandatory after execution.107108Run the validation commands declared by policy and confirmed from repository configuration when available:109110- formatter111- linter112- compiler or type checker113- unit and integration tests114- import/public API validation115- architecture layout validation116117Record validation commands and results in `.architecture/validation-results.yaml`. Report failure exactly; do not claim success unless commands were run and passed.118119## Output Discipline120121When reporting results:122123- Separate Analysis, Review, Execution, and Validation status.124- List generated or changed artifacts.125- List source files changed only after Execution.126- Include exact validation commands and outcomes.127- State when execution was refused because approval, policy, fingerprint, or validation gates were not satisfied.