Skip to content

Repository files navigation

πŸ—ΊοΈ Branchdeck

Understand large codebases in hours, not weeks.

License: MIT TypeScript Next.js FastAPI Python PRs Welcome


Branchdeck is a developer intelligence platform that parses your codebase with tree-sitter, builds a live dependency graph backed by PostgreSQL + pgvector, and surfaces four AI-powered features β€” Project Map, Visual Call Flow, Impact Analysis, and Story Mode β€” all from a Next.js web app and a VS Code extension.


Table of Contents


✨ Features

Feature Description Status
πŸ—ΊοΈ AI Project Map Generates a dependency graph of your entire codebase, colour-coded by layer (UI, API, DB, worker, external, service) βœ… Live
πŸ”€ Visual Call Flow Renders an interactive node graph of function call chains up to 3 hops deep, sourced from real AST data βœ… Live
πŸ’₯ Impact Analysis Runs a CTE query on the graph to find every downstream node that would be affected by changing a symbol βœ… Live
πŸ“– Story Mode AI-generated narrative walkthrough of architecture paths, powered by Gemini (with a local rules narrator fallback) βœ… Live
πŸ’¬ Codebase Q&A Natural-language queries against the dependency graph 🟑 Demo

βš™οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      User Browser                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Next.js Frontend (Port 3000)                  β”‚
β”‚   page.tsx Β· /api/analyze Β· /api/callflow               β”‚
β”‚            /api/impact Β· /api/story                     β”‚
β”‚                                                         β”‚
β”‚  Fallback: ts-morph local AST parser (offline mode)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚  JWT-authenticated proxy
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           FastAPI Engine (Port 8000)                    β”‚
β”‚   /api/analyze Β· /api/impact Β· /api/callflow            β”‚
β”‚   /api/story Β· Pydantic validation Β· JWT verification   β”‚
β”‚                                                         β”‚
β”‚   tree-sitter parser.py  Β·  database.py ORM            β”‚
β”‚   Gemini API (optional)  Β·  JSON structured logging     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     PostgreSQL + pgvector (Port 5432)                   β”‚
β”‚  repos Β· commits Β· code_nodes Β· code_edges Β· file_cache β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Request flow at a glance

  1. /api/analyze β€” Proxies to FastAPI β†’ tree-sitter parses files β†’ graph written to Postgres. Falls back to ts-morph if FastAPI is offline.
  2. /api/callflow β€” Queries code_nodes / code_edges with a BFS up to depth 3.
  3. /api/impact β€” Executes a recursive CTE (get_downstream_impact) on the graph.
  4. /api/story β€” Traces graph paths β†’ Gemini API narrative (or local rules narrator if GEMINI_API_KEY is absent).

πŸ“ Project Structure

Branchdeck/
β”œβ”€β”€ backend/                  # FastAPI engine
β”‚   β”œβ”€β”€ main.py               # All API routes, BFS, CTE queries, story generation
β”‚   β”œβ”€β”€ parser.py             # tree-sitter AST β†’ code_nodes / code_edges
β”‚   β”œβ”€β”€ database.py           # SQLAlchemy ORM, schema, pgvector setup
β”‚   β”œβ”€β”€ secure_file_handler.py
β”‚   β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ test_api.py           # Integration + security tests (testcontainers)
β”‚   β”œβ”€β”€ test_parser.py
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── Dockerfile
β”‚
β”œβ”€β”€ webapp/                   # Next.js frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx      # Main dashboard (66 KB β€” all four features)
β”‚   β”‚   β”‚   β”œβ”€β”€ api/          # Next.js route handlers (proxy + fallback)
β”‚   β”‚   β”‚   └── layout.tsx
β”‚   β”‚   β”œβ”€β”€ components/       # React component library
β”‚   β”‚   └── lib/
β”‚   β”‚       └── server-analyzer.ts  # ts-morph fallback AST parser
β”‚   β”œβ”€β”€ package.json
β”‚   └── Dockerfile
β”‚
β”œβ”€β”€ extension/                # VS Code extension
β”‚   β”œβ”€β”€ src/                  # Extension source
β”‚   β”œβ”€β”€ media/                # Icons
β”‚   β”œβ”€β”€ package.json          # Commands, menus, activation events
β”‚   └── branchdeck-vscode-*.vsix
β”‚
β”œβ”€β”€ landing/                  # Static marketing site
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ style.css
β”‚   └── app.js
β”‚
β”œβ”€β”€ docker-compose.yml        # Full-stack: db + backend + webapp
β”œβ”€β”€ ARCHITECTURE_AS_BUILT.md  # Detailed verified architecture notes
└── RUNBOOK.md                # Step-by-step setup guide

πŸ“‹ Prerequisites

Requirement Version Notes
Node.js β‰₯ 18 For the Next.js webapp
Python β‰₯ 3.12 For the FastAPI backend
PostgreSQL β‰₯ 16 with pgvector Or use Docker Compose
Docker & Docker Compose Any recent Optional β€” for one-command full-stack startup
Git Any Required for repo analysis

πŸ› οΈ Local Development

1. Database

Start a local Postgres + pgvector instance (the quickest way):

docker compose up db -d

Or point DATABASE_URL to any existing PostgreSQL 16+ server with pgvector enabled.


2. Backend (FastAPI)

cd backend

# Create and activate a virtual environment
python -m venv venv

# Windows (PowerShell)
.\\venv\\Scripts\\Activate.ps1
# macOS / Linux
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Configure environment (see Environment Variables below)
# Start the server with live reload
uvicorn main:app --reload --port 8000

Interactive API docs are available at http://localhost:8000/docs.


3. Frontend (Next.js)

In a new terminal:

cd webapp
npm install
npm run dev

Open http://localhost:3000 in your browser. The Next.js API routes automatically proxy backend requests to FastAPI on port 8000.

Offline mode: If the FastAPI backend is unreachable, the frontend transparently falls back to local TypeScript AST parsing using ts-morph. You'll still get a working project map β€” without database persistence.


🐳 Docker (Full Stack)

Spin up the entire stack β€” database, backend, and webapp β€” with a single command:

# Copy and fill in your secrets first
cp .env.example .env   # or set the variables below manually

docker compose up --build

Services:

Service Port URL
webapp (Next.js) 3000 http://localhost:3000
backend (FastAPI) 8000 http://localhost:8000/docs
db (PostgreSQL + pgvector) 5432 localhost:5432

πŸ”‘ Environment Variables

Backend (backend/)

Variable Description Default
DATABASE_URL PostgreSQL connection string postgresql://postgres:postgres@localhost:5432/postgres
GEMINI_API_KEY Enables AI-generated Story Mode narratives Optional β€” falls back to local rule narrator
SUPABASE_JWT_SECRET Secret used to verify JWT tokens from Next.js dev_jwt_secret_change_me_in_prod_32chars
ALLOWED_ORIGINS CORS allowed origins (comma-separated) http://localhost:3000
GITHUB_TOKEN GitHub API token for private repository access Optional

⚠️ Fail-fast: The backend will refuse to start if DATABASE_URL contains postgresql:// but the server is unreachable. Silent SQLite fallback is intentionally disabled to prevent environment drift.

Webapp (webapp/)

Variable Description
BACKEND_URL Internal URL of the FastAPI backend (used by Next.js server-side proxy)
NEXT_PUBLIC_SUPABASE_URL Supabase project URL (for future auth integration)
NEXT_PUBLIC_SUPABASE_ANON_KEY Supabase anon key
SUPABASE_JWT_SECRET Must match the backend secret

πŸ§ͺ Running Tests

Backend (Python)

Runs the full integration and security test suite against a real PostgreSQL container:

cd backend
pytest

Requires Docker to be running β€” tests use testcontainers-postgres to spin up an isolated database automatically. No silent SQLite fallback.

The security test suite (test_api.py) explicitly verifies:

  • Expired JWT tokens are rejected
  • alg: none exploit attempts are blocked
  • Incorrect signature algorithms are rejected
  • Cross-tenant queries return 403 Forbidden

Frontend (TypeScript)

Type-check the entire webapp without emitting:

cd webapp
npx tsc --noEmit

🧩 VS Code Extension

Branchdeck ships a VS Code extension that embeds all four features directly in your editor.

Install from .vsix

code --install-extension extension/branchdeck-vscode-0.1.5.vsix

Or install via the VS Code Extensions panel β†’ Install from VSIX… β†’ select extension/branchdeck-vscode-0.1.5.vsix.

Commands

Command How to trigger Description
Branchdeck: Show AI Project Map Command Palette Renders the full codebase dependency graph
Branchdeck: Visual Call Flow (Selected Function) Right-click any selection Shows the call chain from the selected function
Branchdeck: Analyze Impact Scope Right-click any selection Shows all code affected if this symbol changes
Branchdeck: Architecture Walkthrough Command Palette Generates an AI Story Mode walkthrough

πŸ“– API Reference

All endpoints are on the FastAPI backend (port 8000). Next.js /api/* routes proxy to these with JWT-authenticated headers.

POST /api/analyze

Clones or scans a repository, parses all files with tree-sitter, and persists the dependency graph.

Request body:

{
  "repoUrl": "https://github.com/owner/repo",
  "branch": "main"
}

GET /api/callflow

Returns a call graph for a specific function up to 3 hops deep.

Query params: nodeId, commitSha

POST /api/impact

Returns all downstream nodes impacted by a change to a specific symbol.

Request body:

{
  "targetNodeId": "repo_id:sha:file_path",
  "commitSha": "abc123",
  "symbolName": "processPayment"
}

GET /api/story

Generates an AI narrative walkthrough for traced graph paths. Uses Gemini API if configured; runs a local rule-based narrator otherwise.

Query params: commitSha, repoId

Full interactive documentation: http://localhost:8000/docs


πŸ”’ Security

  • JWT verification is enabled on all FastAPI endpoints. Every request must carry a Authorization: Bearer <token> header signed with SUPABASE_JWT_SECRET.
  • Tenant isolation: All queries filter by the verified owner from the JWT claim. Cross-tenant access raises 403 Forbidden.
  • Pydantic validation enforces the API contract on every inbound payload.
  • Structured correlation IDs (X-Correlation-ID) propagate from Next.js proxy to FastAPI for end-to-end request tracing.

⚠️ Dev placeholder: The 'local' org claim in the current Next.js proxy is a development placeholder. Full multi-tenant isolation requires integrating a real auth provider (Supabase Auth or Clerk) on the frontend.


🀝 Contributing

Contributions are welcome! Areas of particular interest:

  • Real auth provider integration β€” wiring Supabase Auth or Clerk to replace the 'local' dev placeholder
  • Codebase Q&A β€” replacing the client-side regex simulation with a real pgvector semantic search
  • Additional language support β€” extending the tree-sitter parser beyond TypeScript/JavaScript
  • Viem/ethers signer β€” production wallet integration for any payment features
  • Performance β€” async graph indexing (current implementation is synchronous, blocking the request)

Development workflow

git clone https://github.com/dragon486/Branchdeck.git
cd Branchdeck

# Start the database
docker compose up db -d

# Backend
cd backend && python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload --port 8000

# Frontend (new terminal)
cd webapp && npm install && npm run dev

# Tests
cd backend && pytest
cd webapp && npx tsc --noEmit

See RUNBOOK.md for the full operations guide and ARCHITECTURE_AS_BUILT.md for a verified deep-dive into the system design.


πŸ“„ License

MIT Β© dragon486


Built to make large codebases human-scale.

GitHub Β· Issues Β· VS Code Extension

Releases

Packages

Contributors

Languages