Skip to main content

Understanding Existing Code with AI DevKit

Learn how to analyze and document existing codebases using AI DevKit's document-code command

On this page

What is Document Code?#

When joining a new project or working with unfamiliar code, understanding how everything fits together can be overwhelming. The document-code skill analyzes your codebase from any entry point and generates comprehensive documentation with visual diagrams—helping you understand complex systems in minutes instead of hours.

Common scenarios:

  • You just joined a team and need to understand the authentication system
  • You're debugging an issue and need to trace the complete execution flow
  • You're planning a refactor and need to see all dependencies

Prerequisites#

Before using document-code, ensure you have:

  • Completed the machine setup and project initialization in Getting Started
  • An AI editor with skill support

Using the Skill#

Note: Use this directly in your AI editor's chat window, not in the terminal.

In Cursor or Similar Editors#

text
Use the document-code skill to analyze <entry-point>

In Claude Code#

text
Use the document-code skill to analyze <entry-point>

Entry Point Types#

You can analyze code starting from different types of entry points:

Files#

text
Use the document-code skill to analyze src/api/users.ts

Analyzes a specific file and its dependencies.

Folders#

text
Use the document-code skill to analyze src/services/

Analyzes an entire module or directory structure.

Functions#

text
Use the document-code skill to analyze calculateTotalPrice

Analyzes a specific function and its call chain.

API Endpoints#

text
Use the document-code skill to analyze POST:/api/users

Analyzes complete API request/response flow.

What You Get#

Detailed Explanations#

  • Natural language descriptions of how code works
  • Implementation details and design patterns
  • Logic flow and component relationships

Recursive Analysis#

  • Automatically traces all dependencies
  • Maps complete execution paths
  • Identifies external integrations

Visual Diagrams#

  • Flowcharts showing execution paths
  • Sequence diagrams for API flows
  • Architecture diagrams for modules
  • Component relationship maps

Actionable Insights#

  • Performance considerations
  • Security implications
  • Potential improvements
  • Refactoring opportunities

Example Output#

When you ask the agent to document src/services/auth/, the AI generates documentation like this:

docs/ai/knowledge/auth-service.md:

markdown
# Auth Service Analysis

## Overview
The auth service handles user authentication using JWT tokens...

## Architecture Diagram

flowchart TD
    A[Login Request] --> B[Validate Credentials]
    B --> C{Valid?}
    C -->|Yes| D[Generate JWT]
    C -->|No| E[Return 401]

## Key Components
- `AuthController` — Handles HTTP endpoints
- `TokenService` — Manages JWT creation and validation
- `UserRepository` — Database access for user data

Where Results Are Saved#

Generated documentation is saved to docs/ai/knowledge/ in your project:

text
docs/ai/knowledge/
├── auth-service.md       # Analysis of auth module
├── user-api.md           # Analysis of user endpoints
└── diagrams/             # Generated visual diagrams

These files can be committed to version control, making your knowledge base searchable and shareable with your team.

Use Cases#

Use CaseDescription
OnboardingHelp new developers understand complex systems quickly
DocumentationGenerate comprehensive system documentation automatically
DebuggingUnderstand complete execution flows before diving into code
RefactoringGet full context and dependency maps before making changes
Knowledge BaseCreate searchable, versioned documentation for your team

Troubleshooting#

ProblemSolution
Command not recognizedInstall the CLI globally, or prefix the command with npx ai-devkit@latest as described in Getting Started
Analysis seems incompleteTry analyzing a smaller entry point first
Diagrams not renderingEnsure your editor supports Mermaid syntax
Entry point not foundCheck the path is relative to your project root

Next Steps#

  • Debug an issue — Use structured debugging with your captured knowledge for context
  • Plan a refactor — Use your analysis to inform design review decisions
  • Build your knowledge base — Enable Memory to make your captured knowledge searchable
  • Extend capabilities — Install Skills to add more AI capabilities
esc