Skip to main content
IntermediateCoding

Codebase Self-Optimization

Audit a project's codebase, architecture, and conventions — then produce an optimized AI configuration and architecture map for future sessions.

Prompt

You are performing a codebase self-optimization audit. Your job is to understand this project's patterns, anti-patterns, architectural decisions, stack conventions, and failure modes — then produce configuration and documentation that makes every future AI session more effective.

You are performing two parallel functions:
1. Self-optimization — auditing project-level AI configuration, documentation accuracy, and supporting tooling.
2. Architecture cartography — producing a visual map of the system's components, relationships, dependencies, and data flows.

PHASE 1 — RECONNAISSANCE
Audit the project systematically. For each area, cite specific files and line numbers:
- Stack, framework, language, and version choices (read package.json / pyproject.toml / Cargo.toml)
- Directory structure and architectural patterns (annotated tree)
- Naming conventions, code style, import patterns (with examples of violations)
- Test strategy (framework, count by running tests, coverage, where tests live)
- Build and deployment pipeline (CI/CD config files)
- Git patterns (branch strategy from recent history, commit style, PR conventions)
- Existing documentation and its gaps (verify claims in README/docs against actual code)
- Services, data stores, API boundaries, auth flow, third-party integrations

PHASE 2 — CONFIGURATION GENERATION
Produce or upgrade project documentation containing:
- Project identity (stack, architecture in 2-3 lines)
- Execution standards (commit style, test requirements, code conventions)
- File/directory map (what lives where, what not to touch)
- Anti-pattern registry: for each, provide the file path, what's wrong, and what the correct pattern is
- Import/dependency conventions with correct and incorrect examples
- Testing and build/run/deploy commands (verified by checking package.json scripts)

PHASE 3 — ARCHITECTURE MAP
Produce Mermaid diagrams for:
- System topology (services, data stores, external integrations)
- Data flow for each major feature path (request → processing → storage)
- Dependency direction between architectural layers

Also produce a component inventory table covering: services, data stores, API routes, external deps. Tag every component with confidence: verified, inferred, or uncertain.

PHASE 4 — VERIFICATION
- Spot-check 5+ documentation claims against actual code (show the claim, the file inspected, and whether it's accurate, stale, or wrong)
- Verify architecture map covers all discoverable services, routes, and data stores
- Verify data flows match actual import chains by tracing 3+ paths

PHASE 5 — HEALTH SCORE & QUICK WINS
Rate the project's AI-readiness on a scale of 1-10 with justification.

Produce a prioritized "Top 5 Quick Wins" table:
| # | Fix | File | Effort | Impact |

These should be fixes that take under 30 minutes each and have the highest impact on project health or developer experience.

CONSTRAINTS:
- Do not modify any application source code, tests, or configuration
- Every anti-pattern must be evidenced from codebase or git history, not speculation
- Keep documentation concise — most critical rules first
- Verify version numbers and test counts by actually checking (do not trust existing docs)

PROJECT TO AUDIT:
{{Paste the project path or describe the project you want to optimize}}

How to Use

How to Use

Paste this prompt into an AI coding assistant (Claude Code, Cursor, etc.) while inside your project directory. The AI will audit the codebase and produce documentation and an architecture map that makes every future session more effective.

Tips & Warnings

Tips

Run this as the first prompt in any new project. The output becomes the foundation for all future AI-assisted work. Re-run periodically as the project evolves.

The architecture map is most valuable when kept up to date. Consider running the audit after major refactors or dependency changes.

devopsarchitecturecodebase-auditself-optimizationdocumentation