Skip to content

From Refactoring to Archon — Translation Path and Engineering Landings

An evaluation of Martin Fowler's Refactoring: Improving the Design of Existing Code (2nd ed., 2018) against the Archon framework, extracting actionable engineering disciplines.

Authority note: this document records the full translation process (Why + How). The operative definitions of each discipline live in soul.md — if this document conflicts with soul, soul wins.

Comic explainer: translate, don't copy

1. Why examine this book

Refactoring solves a core problem: how to continuously improve internal structure without changing external behavior. This matters just as much for AI engineering governance — but it can't be copy-pasted. Fowler's context is human teams collaborating; Archon's context is session-based AI-agent autonomy. What follows is a translation path, not a textbook port.

2. Concept cheat sheet

ConceptOne-line summary
RefactoringImprove internal structure in small steps without changing external behavior
Code SmellsSurface symptoms hinting at deeper structural problems (22+ categories)
Two HatsAt any moment do one thing: add features or refactor, never both
Rule of ThreeFirst time write it; second time tolerate it; third time abstract
Characterization TestBefore refactoring, write tests to pin current behavior first, then touch structure
Branch by AbstractionLarge-scale replacement without halting — old and new coexist, migrate gradually, delete old at the end
Refactoring CatalogEach smell pairs with a set of named techniques, forming a reusable diagnostic lookup table

3. Relationship to Archon

3.1 Already aligned (no new action needed)

Several of Archon soul.md's principles naturally coincide with Fowler's, just expressed in different vocabulary:

FowlerArchonAssessment
Eliminate dead codeZero-tolerance for dead codeFully aligned
Single Responsibility / Extract ClassOne file, one job; split when it bloatsAligned
DRY / Eliminate duplicationPattern consistency — one way to do one thingAligned
Tests as safety netValidate gate (validate fully green)Aligned
Continuous improvement over big rewritesDrift small-step accumulation + evolution mechanismAligned
Avoid speculative abstractionLeanness > accumulationAligned
Naming is designNaming is designFully aligned

These aren't coincidences. Fowler distilled from human team collaboration; Archon derived from AI-agent autonomous governance. Both arrived at the same engineering bedrock.

3.2 Gaps (adopted and landed)

Comic explainer: five adopted refactoring disciplines

The following five items were present in Fowler and missing in Archon. All five are now written into soul/delivery.md:

#GapFowler's originalArchon adaptationLanding location
1Two HatsDon't mix features and refactoringShip the feature delivery first, then do a refactor delivery — separate commitssoul/delivery.md §Product Quality
2Rule of ThreeAbstract only on the third repetitionAvoid premature generalization; two repetitions isn't an abstraction triggersoul/delivery.md §Product Quality
3Gradual ReplacementBranch by AbstractionOld and new coexist; migrate stepwise; no stop-the-world rewritesoul/delivery.md §Product Quality
4Restrained TempoDon't refactor near a deadlineIf a milestone feature isn't done, log the smell as debt; don't fix on the spotsoul/delivery.md §Product Quality
5Characterization TestWrite Characterization Tests before refactoringBefore refactoring an existing module, add tests that pin current behaviorsoul/delivery.md §New Code = New Guardrails

3.3 Explicitly rejected

CandidateRejection reasonArchon principle cited
TDD mandateFowler recommends test-first, but the Archon agent chooses the optimal execution path itself. A mandate reduces flexibility; the validate gate already guards the quality floorOwnership (agent judges its own path)
Standalone Refactoring Catalog docThe 22 generic smell categories are textbook content, not project knowledge. Consult the book when needed; not worth maintaining a copyLeanness > accumulation
Dedicated refactoring skill fileCurrently no accumulated project-specific smell patterns. An empty-shell skill violates "create-to-defend"Knowledge hygiene
Refactoring plan document templateProducing a plan file per refactor = governance bloat. Two-Hats discipline + validate gate are sufficientLeanness > accumulation

4. Adaptation approach: human discipline → AI mechanism

Comic explainer: load human disciplines as AI structural constraints

Fowler's refactoring disciplines rely on self-discipline, code review, and team culture. Archon's risk profile is different: an AI agent doesn't "forget the rules" the way a human would, but it does lose context and suffer cross-session cognitive drift. The adaptation goal is therefore to translate human behavioral discipline into AI structural constraint:

Human (Fowler)AI (Archon)Translation
"Remember not to mix feature and refactor"Two Hats written into soul/delivery.md → loaded automatically on every deliveryBehavioral discipline → cognitive pre-load
"Code Review catches smells"Reasoning capsules embedded in skills → symptom maps directly to fixTeam review → self-evolving knowledge
"Refactor on the third repetition"Rule of Three written into soul/delivery.md → decision anchorRule of thumb → decision primitive
"Write tests before refactoring"Characterization tests written into New Code = New Guardrails → wired to the validate gateBest practice → structural guard
"Phase large refactors"Gradual Replacement written into soul/delivery.md → aligned with drift small-step accumulationProject-management trick → engineering principle

Key insight: humans need to remember principles; AI needs principles loaded. Archon's soul (core + pattern-loaded extensions) is read on demand at every boot; writing into soul equals writing into the agent's working memory.

5. The role of Code Smells in AI coding

Comic explainer: from code smell to stronger guardrail

Fowler's 22 Code Smells are a diagnostic checklist for humans. For AI agents, the value isn't in "memorizing" them but in establishing smell → refactoring fast-decision paths.

Archon's handling strategy:

  1. Don't pre-store the generic catalog — the 22 smells are book knowledge the AI already has
  2. Accumulate project-specific mappings — when the same smell appears for a second time in this project, embed it in the relevant skill as a reasoning capsule (symptom → root cause → fix)
  3. From diagnosis to automation — if a smell can be detected by a lint rule, promote it to L1 (move up the Constraint Pyramid); more reliable than documentation

This matches soul's crystallization-path priority: if a lint can catch it, don't write prose; if a reasoning capsule can capture it, don't create a dedicated file.

6. Full quality-hygiene landscape after adoption

PrincipleSourceEnforcement
Naming is designOriginalCognitive pre-load
Single ResponsibilityOriginal / Fowler-alignedCognitive pre-load
Zero-tolerance for dead codeOriginal / Fowler-alignedCognitive pre-load
Types are documentationOriginalL0 compile constraint
Pattern consistencyOriginal / Fowler-alignedCognitive pre-load
Architectural boundariesOriginalL1 lint constraint
No TODOsOriginalCognitive pre-load
Two HatsAdopted from FowlerCognitive pre-load + commit-auditable
Rule of ThreeAdopted from FowlerCognitive pre-load (decision anchor)
Gradual ReplacementAdopted from FowlerCognitive pre-load + drift-linked
Restrained TempoAdopted from FowlerCognitive pre-load + debt-linked
Characterization Test (new guardrails)Adopted from FowlerL2 test constraint

7. Future evolution vectors

These aren't landed today, but may trigger evolution later:

Trigger signalAction
The same smell appears in the project for the 3rd timeWrite a reasoning capsule and embed in the relevant skill
A smell becomes detectable by static analysisWrite a custom lint rule; promote the constraint from L3 to L1
Milestone migrates critical infrastructureExecute via Gradual Replacement (Branch by Abstraction)
Page-layer refactor (currently lacks tests)Add Characterization Tests first, then touch structure

Released under the Apache-2.0 License.