No. 138 Lower the entropy

Architecture entropy goal

Systematically reduce architectural entropy and converge the codebase toward a canonical, decoupled, maintainable system.

  • Claude Code
  • Codex
  • Cursor
  • Lower the entropy

Prompt

译

/goal Systematically reduce architectural entropy, normalize and unify, decouple modules, and govern complexity across the entire codebase, gradually evolving it into a highly regular, extremely easy-to-understand, extremely easy-to-maintain engineering system suitable for many Agents to develop in parallel.

Core idea:

Assume today is the first day this product was born, but we already know
all current real requirements, business constraints, and product shape.
Think about what this codebase should look like under ideal conditions,
then converge toward that state through safe, incremental, verifiable refactoring.

Pursue the following engineering properties:

1. Single Source of Truth
   Every business rule, data definition, configuration, state, and design specification
   should have a single, clear authoritative source.

2. Canonical Implementation
   Keep only one standard implementation for the same semantics and the same responsibility.
   Comprehensively eliminate historical parallel implementations, duplicate logic, temporary patches,
   meaningless compatibility layers, and multiple coexisting technical solutions.
   Keep compatibility capabilities that have real callers or explicit contract requirements.

3. Deep Modules
   Refer to John Ousterhout's A Philosophy of Software Design.
   Encapsulate complexity inside and expose capabilities through interfaces that are as simple and stable as possible.
   Reduce shallow modules, meaningless forwarding layers, and abstractions that leak internal implementations.

4. High Cohesion, Low Coupling
   Every module has a clear responsibility, ownership, and dependency direction.
   Modules are highly cohesive internally and interact through stable contracts.
   Eliminate circular dependencies, implicit coupling, cross-layer access, and shared mutable state.

5. Locality of Change
   When changing a business concept, modify only one logical location wherever possible.
   Eliminate situations where one requirement requires synchronized changes to many unrelated files.

6. Deletion over Accumulation
   Prioritize whether unnecessary complexity can be deleted.
   Every time a new standard implementation is introduced, check and migrate old callers,
   and delete the replaced implementation after confirming it is safe.
   Do not allow old and new systems to coexist for a long time.

7. Enforceable Architecture
   Turn established engineering specifications into machine-executable constraints,
   using the type system, Lint, AST checks, contract tests, and CI,
   to prevent future development from reintroducing chaos that has been eliminated.

Execution process:

First understand the entire codebase's real business, architecture, historical decisions,
module relationships, technology stack, existing tests, and production constraints.

Build a complete architecture map, dependency graph, state ownership map,
duplicate implementation list, technical solution list, and specification deviation list.

Inspect and govern one by one:

- UI components and design system
- Business logic and domain models
- API interfaces and data contracts
- State management and data flow
- Data access and caching
- Configuration and environment variables
- Error handling and retry mechanisms
- Logging and observability
- Permissions and identity authentication
- Naming, directory structure, and module boundaries
- Utility functions and common infrastructure
- Testing, build, and development toolchain

Continuously run the following loop:

Scan the entire system
→ discover architectural entropy and specification deviations
→ analyze real callers and dependency relationships
→ propose multiple refactoring plans
→ choose the plan with the lowest total complexity
→ establish a behavioral baseline and tests
→ complete a batch of complete migrations
→ delete old implementations that have been replaced
→ independently review
→ perform verification
→ establish anti-regression constraints
→ record the results and continue to the next round

Each round of refactoring must form a complete closed loop; it is forbidden to only establish new abstractions,
new directories, or new interfaces without migrating the original callers.

Use the Deletion Test to examine every layer of abstraction:
If this layer is deleted, will the complexity disappear, or will it spread to the callers?
Only abstractions that truly encapsulate complexity are worth keeping.

Acceptance criteria:

- Every core business concept has a clear authoritative implementation.
- Every core module has clear responsibilities and public interfaces.
- The same semantics do not have multiple unexplained implementations.
- There are no unapproved circular dependencies among core modules.
- Business logic is reasonably decoupled from UI, storage, frameworks, and external services.
- New features can be completed within clear module boundaries.
- Established key architectural specifications have automated anti-regression checks.
- All existing functionality, data compatibility, and external contracts are preserved.

Forbid over-abstraction, worthless directory moves, sacrificing readability
to reduce lines of code, and merging concepts with different semantics for the sake of formal uniformity.

Execute in an isolated Git worktree, with each batch of effective improvements as an independent commit.
Continuously maintain a progress file, architecture decision records, and an optimization task pool.

For matters that require product decisions, major architectural changes, or breaking migrations,
record them as pending confirmation and continue with other independent tasks.

No need to ask whether to continue each round.
Continue executing until all high-value governance tasks have converged,
or the operating budget is reached, or there are no further improvements that can be safely implemented.

When to use

“Architecture entropy goal” fits when the code works but the structure is harder than the behavior, because it says “/goal 对整个代码库进行系统性的架构降熵、规范化归一、模块解耦和复杂度治理,将其逐步演进为一个高度规整、极易理解、极易维护、适合大量 Agent 并行开发的工程系统。”, and that published sentence is the whole assignment.

For “Architecture entropy goal”, the extra line you type is the requirement those steps ask for, for example “make src/cart.js return 0 on an empty cart and skip a line with no price”, and the file then starts at “Single Source of Truth”.

When not to use

Leave “Architecture entropy goal” unused when the change is a one-line typo or a red build you have not read, because “/goal 对整个代码库进行系统性的架构降熵、规范化归一、模块解耦和复杂度治理,将其逐步演进为一个高度规整、极易理解、极易维护、适合大量 Agent 并行开发的工程系统。” points the other way

How to run it

Claude Code

Claude Code takes “Architecture entropy goal” as one paste at the repo root. Do not also save .claude/commands, or “/goal 对整个代码库进行系统性的架构降熵、规范化归一、模块解耦和复杂度治理,将其逐步演进为一个高度规整、极易理解、极易维护、适合大量 Agent 并行开发的工程系统。” replays on the next task.

Codex

Codex takes “Architecture entropy goal” as a paste above the task. Leave AGENTS.md unchanged so the next thread does not inherit “/goal 对整个代码库进行系统性的架构降熵、规范化归一、模块解耦和复杂度治理,将其逐步演进为一个高度规整、极易理解、极易维护、适合大量 Agent 并行开发的工程系统。”.

Cursor

Cursor should see “Architecture entropy goal” only as a chat paste of “/goal 对整个代码库进行系统性的架构降熵、规范化归一、模块解耦和复杂度治理,将其逐步演进为一个高度规整、极易理解、极易维护、适合大量 Agent 并行开发的工程系统。” for this turn. A file at .cursor/rules would keep applying after the turn ends.

Comparison

Prepending “Architecture entropy goal” did not make the model restructure a repository. It returned a shorter reduce that treats a missing price as 0. Without that prompt, the same task used a for-loop and Number.isFinite to drop a non-numeric line.

Related

来源:数字生命卡兹克 · https://x.com/Khazix0918/status/2126324185626734795 · 2026-12-01