Codebase analysis

From sequenzia/agent-alchemy · View interactive version

Codebase analysis is an AI agent skill from the GitHub repository sequenzia/agent-alchemy. Produce a structured codebase analysis report with architecture overview, critical files, patterns, and actionable recommendations. Use when asked to "analyze codebase", "explore codebase", "understand this codebase", "map the codebase", "give me an overview of this project", "what does this codebas

How to use this skill

Skill file

Codebase Analysis Workflow

Execute a structured 3-phase codebase analysis workflow to gather insights.

Phase Overview

  1. Deep Analysis — Explore and synthesize codebase findings via the deep-analysis skill
  2. Reporting — Present structured analysis to the user
  3. Post-Analysis Actions — Save, document, or retain analysis insights

Phase 1: Deep Analysis

Goal: Explore the codebase and synthesize findings.

  1. Determine analysis context:
  1. Check for cached results:
  1. Run deep-analysis workflow:
  1. Verify results and capture metadata:

Phase 2: Reporting

Goal: Present a structured analysis to the user.

  1. Load diagram guidance:
  1. Present the analysis using the report template below:

Structure the report with these sections:

  1. Proceed immediately to Phase 3.

Do NOT stop here. Do NOT wait for user input. The report is presented, but the workflow requires Post-Analysis Actions. Continue directly to Phase 3 now.


Report Template

# Codebase Analysis Report

**Analysis Context**: {What was analyzed and why}
**Codebase Path**: {Path analyzed}
**Date**: {YYYY-MM-DD}

{If the report exceeds approximately 100 lines, add a **Table of Contents** here linking to each major section.}

---

## Executive Summary

{Lead with the most important finding. 2-3 sentences covering: what was analyzed, the key architectural insight, and the primary recommendation or risk.}

---

## Architecture Overview

{2-3 paragraphs describing:}
- How the codebase is structured (layers, modules, boundaries)
- The design philosophy and architectural style
- Key architectural decisions and their rationale

{Include a Mermaid architecture diagram (flowchart or C4 Context) showing the major layers/components. Use `classDef` with `color:#000` for all node styles.}

---

## Tech Stack

| Category | Technology | Version (if detected) | Role |
|----------|-----------|----------------------|------|
| Language | {e.g., TypeScript} | {e.g., 5.x} | Primary language |
| Framework | {e.g., Next.js} | {e.g., 16} | Web framework |

{Include only technologies actually detected in config files or code. Omit categories that don't apply.}

---

## Critical Files

{Limit to 5-10 most important files}

| File | Purpose | Relevance |
|------|---------|-----------|
| `path/to/file` | Brief description | High/Medium |

### File Details

#### `path/to/critical-file`
- **Key exports**: What this file provides to others
- **Core logic**: What it does
- **Connections**: What depends on it and what it depends on

---

## Patterns & Conventions

### Code Patterns
- **Pattern**: Description and where it's used

### Naming Conventions
- **Convention**: Description and examples

### Project Structure
- **Organization**: How files and directories are organized

---

## Relationship Map

{Describe how key components connect — limit to 15-20 most significant connections. Use Mermaid flowcharts for both data flows and dependency maps.}

---

## Challenges & Risks

| Challenge | Severity | Impact |
|-----------|----------|--------|
| {Description} | High/Medium/Low | {What could go wrong} |

---

## Recommendations

1. **{Recommendation}** _(addresses: {Challenge name})_: {Brief rationale}
2. **{Recommendation}** _(addresses: {Challenge name})_: {Brief rationale}

---

## Analysis Methodology

- **Exploration agents**: {Number} agents with focus areas: {list}
- **Synthesis**: Findings merged and critical files read in depth
- **Scope**: {What was included and what was intentionally excluded}
- **Cache status**: {Fresh analysis / Cached results from YYYY-MM-DD}
- **Config files detected**: {List of config files found during reconnaissance}
- **Gap-filling**: {Whether direct investigation was needed after synthesis, and what areas were filled}
Report Section Guidelines

Executive Summary: Lead with the most important finding, not a generic overview. Keep to 2-3 sentences. Include at least one actionable insight.

Critical Files: Limit to 5-10 files — these should be the files someone must understand. Include both the "what" (purpose) and "why" (relevance).

Patterns & Conventions: Only include patterns that are consistently applied (not one-off occurrences). Note deviations from patterns.

Relationship Map: Focus on the most important connections, not an exhaustive dependency graph. Use directional language (calls, depends on, triggers, reads from). Cap at 15-20 connections.

Challenges & Risks: Rate severity based on likelihood and impact combined. Include specific details, not vague warnings.

Recommendations: Make recommendations actionable. Each recommendation must reference the specific challenge it addresses using the format: _(addresses: {Challenge name})_. Limit to 3-5 recommendations.

Adapting the Report

For Feature-Focused Analysis: Emphasize integration points and files that would need modification. Include a "Feature Implementation Context" section before Recommendations. Focus Challenges on implementation risks.

For General Codebase Understanding: Broader Architecture Overview with layer descriptions. More extensive Patterns & Conventions section. Focus Recommendations on areas for improvement.

For Debugging/Investigation: Emphasize the execution path and data flow. Include a "Relevant Execution Paths" section. Focus Critical Files on the suspected problem area.


Phase 3: Post-Analysis Actions

Goal: Let the user save, document, or retain analysis insights from the report through a multi-step interactive flow.

Step 1: Select actions

Prompt the user with multiple selection:

If the user selects no actions, the workflow is complete. Thank the user and end.

Step 2: Execute selected actions

Process selected actions in the following fixed order. Complete all sub-steps for each action before moving to the next.

Action: Save Codebase Analysis Report

Step 2a-1: Prompt for file location

Step 2a-2: Generate and save the report

Action: Save Custom Report

Step 2b-1: Gather report requirements

Step 2b-2: Prompt for file location

Step 2b-3: Generate and save the custom report

Action: Update Project Documentation

Step 2c-1: Select documentation files and gather directions

Prompt the user with multiple selection:

Then prompt: "What content from the analysis should be added or updated? Provide general directions or specific sections to focus on (applies across all selected files, or specify per-file directions)."

Step 2c-2: Generate and approve documentation drafts

For each selected file, read the existing file and generate a draft based on the user's directions and Phase 2 analysis data:

Present all drafts together in a single output, clearly labeled by file. Then prompt the user:

If approved, apply updates.

Action: Keep Insights in Memory

Step 3: Actionable Insights Follow-up

Condition: This step always executes after Step 2 completes. The Phase 2 analysis is available in conversation context regardless of whether a report file was saved.

Prompt the user:

If the user selects "Skip", proceed to Step 4.

If the user selects "Address actionable insights":

Step 3a: Extract actionable items from the report

Parse the Phase 2 report (in conversation context) to extract items from:

If no actionable items are found, inform the user and skip to Step 4.

Step 3b: Present severity-ranked item list

Present items sorted High to Medium to Low, each showing:

Prompt the user with multiple selection to choose which items to address. If no items selected, skip to Step 4.

Actionable Insights Processing Guidelines

Severity Assignment:

Complexity Assessment:

Deduplication: Merge items that target the same file/component, have significant keyword overlap in titles, or where one item is a superset of another. Keep the higher severity.

Conflict Detection: Before starting fixes, scan selected items for same-file modifications, contradictory changes, or ordering dependencies. If conflicts are detected, present them to the user and suggest a processing order.

Step 3c: Process each selected item in priority order (High to Medium to Low)

For each item:

  1. Assess complexity: Simple, Complex (architectural), or Complex (investigation)
  2. Plan the fix:
  1. Present proposal: Show files to modify, specific changes, and rationale
  2. User approval:

Step 3d: Summarize results

Present a summary covering:

Step 4: Complete the workflow

Summarize which actions were executed and confirm the workflow is complete.


Error Handling

General

If any phase fails:

  1. Explain what went wrong
  2. Ask the user how to proceed:

Documentation Update Failures (Step 2c)

If a file edit or write fails when applying documentation updates:

  1. Retry the operation once
  2. If still failing, present the drafted content to the user inline and suggest they apply it manually
  3. Continue with the remaining selected files

Agent Launch Failures (Step 3c)

If a code-architect or code-explorer agent fails during actionable insight processing:

  1. Fall back to direct investigation using file reading and searching
  2. Propose a simpler fix based on available information
  3. If the item is too complex to address without agent assistance, inform the user and offer to skip

Agent Coordination

Exploration and synthesis agent coordination is handled by the deep-analysis skill in Phase 1, which uses agent teams with hub-and-spoke coordination. Deep-analysis performs reconnaissance, composes a team plan (auto-approved when invoked by another skill), assembles the team, and manages the exploration/synthesis lifecycle. See that skill for team setup, approval flow, and failure handling details.


Integration Notes

What this component does: Orchestrates a 3-phase codebase analysis workflow: deep exploration via the deep-analysis skill, structured report presentation, and interactive post-analysis actions (save report, update docs, address findings).

Capabilities needed: All capabilities from deep-analysis (agent teams, task management, messaging), plus file writing (for report saving), file editing (for documentation updates), user prompting (for interactive action selection).

Adaptation guidance: The reporting phase is mostly output formatting and can be adapted to any presentation mechanism. The post-analysis actions involve interactive multi-step flows with user selection — map these to the host platform's interaction model. The actionable insights processing can launch code-architect or code-explorer sub-agents for complex fixes.

Configurable parameters: Inherits all deep-analysis configuration parameters. No additional configuration specific to codebase-analysis.

Sub-agent capabilities:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.