Install
openclaw skills install ai-codebase-deep-modulesDesigns and refactors software codebases to be AI-friendly by aligning the filesystem with domain/feature boundaries, creating deep (greybox) modules with small public interfaces, enforcing import boundaries, and tightening tests/feedback loops. Use when the user asks to "make the codebase AI-ready", "reduce coupling", "introduce deep modules", "create module boundaries", "restructure folders by feature", "define service interfaces", or "plan a refactor + tests so AI agents can work safely".
openclaw skills install ai-codebase-deep-modulesTurn “a web of shallow, cross-importing files” into a codebase that is easy for AI (and humans) to navigate, change, and test.
This skill is built around four ideas:
Use this skill when the user wants any of the following:
Do not use this skill for:
If available, ask for or infer:
If the user hasn’t provided this, do not stall. Make best-effort guesses by inspecting:
package.json, pyproject.toml, go.mod, pom.xml, build.gradle, Makefile, justfilesrc/, app/, packages/, services/, modules/Goal: ensure there is a fast “did it work?” loop before and during refactors.
tsc -p tsconfig.jsonnpm test, pytest -q, go test ./...eslint ., ruff check, golangci-lint runmake verify, just verify, npm run verify, ./scripts/verify.shDeliverable: a short “Feedback loop” section with the exact commands and expected outputs.
Goal: identify the natural groupings that already exist in the product.
auth, billing, thumbnail-editor, video-editor, cms-formsDeliverable: a Module Map (table) with: domain, responsibilities, key files, current coupling risks.
Goal: reduce the number of things the agent must keep in working memory.
For each domain/module candidate:
domain → shared primitivesdomain ↔ domain cross-importsDeliverable: an Interface Spec for each deep module:
See: references/module-templates.md
Goal: make it obvious where to look.
Default rule: outside code imports only from a module’s public entrypoint.
Recommended structure (adapt per language):
src/<module>/
index.* (public exports)types.* (public types)internal/ (implementation details; not imported from outside)__tests__/ or tests/ (contract tests for the public API)If the repo uses packages, prefer packages/<module>/ with explicit exports.
Deliverable: a “Move plan” listing:
Goal: you shouldn’t need to understand internals to trust behaviour.
Deliverable: test plan + initial contract test skeletons.
See: references/testing-and-feedback.md
Goal: prevent the codebase from drifting back into a web.
Pick the lightest viable enforcement:
no-restricted-imports, ESLint boundary plugins)internal/, Rust pub(crate), Java modules)Deliverable: an “Enforcement” section with the exact rules and where to configure them.
See: references/boundary-enforcement.md
Goal: avoid giant-bang rewrites.
Suggested sequence:
Deliverable: a stepwise refactor plan with checkpoints and rollback options.
When this skill is activated, produce a structured plan using this outline:
Optional: copy the template from assets/architecture-plan-template.md.
User says: “Make our TypeScript monorepo more AI-friendly. It’s hard to find things and tests are slow.”
Actions:
verify loop (typecheck + unit tests) and how to run it per package.index.ts, types.ts).no-restricted-imports.Result: a concrete refactor plan and initial skeletons that can be executed incrementally.
User says: “Auth imports billing and billing imports auth. We keep breaking things.”
Actions:
auth exports getCurrentUser(), requireAuth()billing depends on those interfaces only (no deep imports)shared/ or platform/ module.Result: cycle removed, boundaries enforced, behaviour locked by tests.
Use the template and references to get concrete:
Prioritise greybox contract tests first:
Start with lint rules and path conventions; add architecture tests if needed. See: references/boundary-enforcement.md