Skip to content

Codebase Analysis

Full-codebase static analysis. Powers the architecture-expert subagent and the get_architecture_knowledge tool. Ask about your project’s structure and get answers grounded in real analysis instead of the LLM guessing.

CodeBuddy: Analyze Codebase & Answer Questions (Cmd/Ctrl + Shift + 6)

Progress notification during the scan. Once done, ask things like:

  • “What architectural patterns does this project use?”
  • “Show me all API endpoints”
  • “What are the most-imported modules?”
  • “Are there any circular dependencies?”

Tree-sitter analysis for 7 languages:

LanguageExtensions
JavaScript.js, .jsx, .mjs, .cjs
TypeScript.ts, .tsx, .mts, .cts
Python.py
Java.java
Go.go
Rust.rs
PHP.php, .phtml

Plus config files (package.json, tsconfig.json, requirements.txt, pyproject.toml, go.mod, Cargo.toml, pom.xml, build.gradle, composer.json) and schema files (*.sql, schema.prisma) for dependency + model info.

For each supported language, Tree-sitter pulls out classes / interfaces / structs / traits / enums (with methods, properties, decorators), functions (parameters, return types, export/async flags), imports + exports, React components (in JSX/TSX), and API endpoints via framework detection.

Framework endpoint detection:

LanguageFrameworks
JavaScript / TypeScriptExpress, NestJS, Fastify, Hono
PythonFastAPI, Flask, Django
JavaSpring (@GetMapping etc.), JAX-RS
GoGin, Chi, Echo, net/http
RustActix, Axum, Rocket
PHPLaravel, Symfony

NestJS decorators are parsed via the TypeScript compiler API for accurate parameter + return type extraction.

ArchitectureDetector examines file-path patterns to identify layers and match patterns.

Layers detected: controllers, services, repositories, models, middleware, views, config, utils, tests.

Patterns matched with confidence scores:

PatternCriteria
Layered architectureControllers + services + repositories
MVCControllers + models + views
MicroservicesMultiple service directories
Frontend SPAComponents + views directories
Full-stack web appPages + components + API routes
CLI toolcmd/ or commands/ directories
Library / SDKsrc/ with no framework indicators
REST APIAPI endpoints + no frontend components

Each detection includes confidence: “Layered Architecture (85% confidence)”.

Import/dependency graph → extract:

  • Node + edge counts (total modules + import relationships)
  • Dependency hubs — most-imported modules (up to 8)
  • Entry points — modules not imported by anything (up to 8)
  • Circular dependencies — detected cycles (up to 5)

For web apps:

  • Auth strategies (JWT, OAuth, session-based, API key)
  • Middleware chain — ordered pipeline (up to 10)
  • Auth flows — login, register, token refresh (up to 5)
  • Error handlers — count + source files

Results cached in SQLite:

  • Git state tracking — branch name + commit hash + diff hash stored with each analysis.
  • Change detection — subsequent runs check git state; only re-analyze if significantly changed.
  • Worker thread — analysis runs in a worker_threads Worker; UI stays responsive.
  • File limit — up to 1000 files per run.
  • Cancellation — long analyses can be cancelled via the progress notification.

Excluded dirs: node_modules, dist, build, .git, .codebuddy, coverage, .next, .nuxt.

CommandBehavior
Show Cache StatusPanel with cache status, last analysis date, branch, file count, snapshot count, DB size
Clear CacheDelete all snapshots (with confirmation)
Refresh AnalysisForce a fresh analysis regardless of cache state

The get_architecture_knowledge tool accepts a section:

SectionReturns
overviewProject type, entry points, frameworks, file count
patternsArchitectural patterns with confidence scores
call-graphImport graph stats, hubs, circular deps
middlewareAuth strategies, middleware chain, error handlers
endpointsAPI routes with method + source file
modelsData models with property names
allEverything (capped at 12 000 chars)

No data yet? The tool suggests running the analyze command first.

CodeBuddy watches .git/HEAD. When you switch branches:

Branch changed to feature/auth. Analyze now? [Analyze Now] · [Later]