Evidence-backed repository intelligence, AST code archaeology, and project lineage platform.
Investigate unfamiliar codebases, debug silent regressions, trace causal PR links, uncover true domain experts, and preserve audit-ready evidence—with zero hallucinations.
- Executive Summary & Purpose
- The Real-World Problem
- What CodeForensics Solves
- Core Workbenches & Features
- System Architecture & Ingestion Flow
- Monorepo Structure
- Prerequisites
- Quickstart: Local Development
- Environment Configuration Reference
- Authentication Architecture (Firebase Auth)
- GitHub App Integration Setup
- Database Schema & Prisma Migrations
- Redis & Background Job Worker (BullMQ)
- Full REST API Specification
- Security, Sandboxing & Threat Model
- Mathematical Contributor Scoring Formula
- Testing & Quality Assurance
- Troubleshooting Common Issues
- Production Deployment Guidelines
- License & Acknowledgments
- Demo Video & Walkthrough
Modern software repositories contain far more critical context than the current HEAD commit reveals. The rationale behind architectural decisions is often fragmented across abandoned issue threads, deleted branches, squash-merged pull requests, and subtle bug regressions.
CodeForensics connects source code, Abstract Syntax Trees (AST), issues, pull requests, commit graphs, and contributor activity into an explainable, navigable evidence graph. It distinguishes provider facts from inferences, presents explicit confidence ratings, and eliminates guesswork by providing verifiable citations for every claim.
Software development teams, security auditors, and open-source maintainers routinely struggle with four systemic challenges:
git blameonly tells you who touched a line last, not why it was introduced.- In modern enterprise repositories using squash merges, automated refactors, and formatting passes (e.g. Prettier, Biome), up to 80% of lines point to non-informative commits (
"chore: reformat","squash merge PR #1420"). - When a critical regression occurs, engineers spend hours searching through dozens of GitHub tabs trying to determine:
- Which issue originally reported this bug?
- Was this function designed to handle nested concurrent transitions?
- Did an intermediate commit fix tearing, only to be reverted in a subsequent hotfix?
- Standard LLM coding assistants generate convincing, highly fluent explanations of legacy code.
- However, when context is missing, LLMs confidently hallucinate architectural intent, fabricating explanations of why code was written.
- In mission-critical production outages, compliance audits, or vulnerability analyses, relying on unverified AI text creates catastrophic regressions and liability risks.
- Traditional contribution metrics rely on naive line churn (lines added/deleted) or raw commit counts.
- A developer who renames a directory, updates third-party dependencies, or runs an automated codemod appears as the "top contributor", while the true domain architect who designed the state machine or concurrency logic remains invisible.
- When key maintainers transition off a project, teams are left vulnerable with unidentified single points of failure (bus factor risk).
- Once a PR branch is merged and deleted, the chronological sequence of intermediate commits, discarded hypotheses, and reviewer feedback vanishes from standard git logs.
- When an edge-case regression re-emerges 18 months later, engineers have to restart the entire forensic investigation from scratch.
CodeForensics transforms disjointed software artifacts into a cohesive, evidence-backed forensic platform:
| Dimension | Legacy Tools & AI Chatbots | CodeForensics Evidence Platform |
|---|---|---|
| Code Reasoning | Confidently hallucinates why code exists. | Provable Citations: Every claim links to an issue, PR, commit SHA, or AST line span. |
| Uncertainty & Ambiguity | Flattens missing data and guesses conclusions. | Calibrated Confidence: Returns FACT, INFERENCE, UNKNOWN with HIGH, MEDIUM, or LOW ratings. |
| Code Safety & Sandboxing | Runs untrusted build scripts or package hooks. | Static In-Memory AST: Analyzes source code using TypeScript Compiler API without executing repository scripts. |
| Contributor Ownership | Naive line-churn counts (distorted by refactors). | Weighted Impact Scoring: Balances PR merges, commit cadence, line churn, reviews, and time decay. |
| Investigation Persistence | Scattered notes, Slack threads, mental state. | Evidence Vault: Persists hypotheses, observations, code citations, and verified case findings. |
| Ingestion Experience | Blocking syncs that lock up the interface. | Multi-Tier Background Pipeline: BullMQ + Redis delivers instant Tier 1 stats while streaming deep crawls. |
An interactive, 5-stage visual onboarding guide that walks new engineers through connecting a repository, searching symbols via AST, tracing PR lineage, identifying domain experts, and filing evidence-backed investigations.
Global repository health dashboard displaying synchronized work items, causal relationship counts, sync progress metrics, and direct links into deep forensic views.
A unified data grid tracking all issues, pull requests, authors, and states (OPEN, CLOSED, MERGED). Includes a slide-over detail drawer exposing the complete chronological thread, causal links (ADDRESSES, SUPERSEDES, FIXED_BY), and direct GitHub links.
Identifies true subsystem experts using our mathematical impact formula. Categorizes maintainers into Domain Experts, Active Maintainers, Historical Contributors, and Occasional Reviewers, while flagging single-point-of-failure risks.
Uses the official TypeScript AST Compiler in memory (ts.createSourceFile) to extract functions, classes, and React hooks with exact 1-indexed line spans. Pinpoints which commits and pull requests modified an exact symbol over the project's lifetime.
A structured research workspace for diagnosing bugs, auditing pull requests, and benchmarking subsystems. Allows engineers to formulate testable hypotheses, log observations, attach immutable citations (commit SHAs, AST lines, PR links), and publish verified findings.
Directly integrated in the TopBar and accessible via modal dialog: allows users to update their display name, change their password, view authentication provider credentials, and manage account sessions.
A comprehensive, 10-chapter developer reference covering architecture, REST API contracts, database schemas, scoring formulas, and troubleshooting procedures.
CodeForensics follows an event-driven, decoupled monorepo architecture:
graph TD
User([Browser Client]) -->|HTTPS / Port 5173| Web[apps/web: Vite React SPA]
Web -->|ID Token Auth| FirebaseClient[Firebase Auth Service]
Web -->|REST API / Port 4000| API[apps/api: Fastify Gateway]
API -->|Verify Bearer ID Token| FirebaseAdmin[Firebase Admin SDK]
API -->|Query & Persist| Postgres[(PostgreSQL 16+ Database)]
API -->|Enqueue Ingestion Jobs| Redis[(Redis 7+ Queue Broker)]
API -->|Repo Metadata & Webhooks| GitHubApp[GitHub App REST/GraphQL]
Worker[apps/worker: BullMQ Worker] -->|Poll Sync Jobs| Redis
Worker -->|Stream Issues/PRs/Commits| GitHubApp
Worker -->|Store Entities & Relationships| Postgres
- Repository Authorization: The user selects or authorizes a GitHub repository via the GitHub App.
- Job Enqueueing: Fastify enqueues a
repository-syncjob in Redis via BullMQ. - Tier 1 Quick Ingestion: The worker immediately fetches recent issues and PRs, saving them to PostgreSQL so the user can begin investigating within seconds.
- Tier 2 Deep Background Crawl: The worker transparently streams historical commits, comment threads, and code revisions without blocking client interaction.
- AST Symbol Indexing: When an engineer searches for a symbol, CodeForensics reads the target source file and parses its AST in memory, mapping line spans to commit SHAs.
codeforensics/
├── apps/
│ ├── api/ # Fastify 5 REST API gateway (port 4000)
│ │ ├── src/auth/ # Firebase Admin token verification & authorization
│ │ ├── src/routes/ # REST API route handlers (repos, issues, archaeology, investigations)
│ │ └── src/services/# Database access and business logic
│ ├── web/ # React 18 SPA built with Vite 6 (port 5173)
│ │ ├── src/pages/ # Overview, Workflow, Archaeology, Issues, Contributions, Investigations
│ │ ├── src/context/ # AuthContext (Firebase Auth) & RepositoryContext
│ │ └── src/components/ # Design system components, modals, drawers
│ └── worker/ # BullMQ background consumer for GitHub data ingestion
│ └── src/ingestion/ # Multi-tier GitHub API streaming pipeline
├── packages/
│ └── shared/ # Universal TypeScript types, Zod schemas, claim taxonomy
├── prisma/
│ ├── schema.prisma # PostgreSQL relational schema and compound unique indexes
│ └── migrations/ # Version-controlled SQL migrations
├── docs/ # In-depth architectural documentation
├── docker-compose.yml # PostgreSQL 16 and Redis 7 local orchestration
├── setup.md # End-to-end setup and deployment guide
└── package.json # Monorepo workspaces manifest
- Node.js:
v20.xor higher (LTS recommended) - npm:
v10.xor higher - Docker Desktop (or locally running PostgreSQL 16+ and Redis 7+)
- Git
git clone https://github.com/Manas-5461X/CodeForensics.git
cd CodeForensics
npm install# Starts PostgreSQL 16 (port 5432) and Redis 7 (port 6379)
docker compose up -d
# Verify container health
docker ps# Copy example configuration template
cp .env.example .env(Review Section 9 below to configure your .env credentials).
# Generate Prisma Client and apply migrations
npm run db:generate
npm run db:migrateOpen separate terminal tabs or use the individual scripts:
npm run dev:api # Fastify REST API -> http://localhost:4000
npm run dev:worker # BullMQ background worker
npm run dev:web # React Vite workbench -> http://localhost:5173Visit http://localhost:5173 to launch the CodeForensics Workbench.
The root .env file governs all monorepo workspaces:
# ==============================================================================
# SERVER API & NETWORKING
# ==============================================================================
NODE_ENV=development
PORT=4000
HOST=127.0.0.1
CORS_ORIGIN=http://localhost:5173
# ==============================================================================
# DATABASE & BACKGROUND QUEUE
# ==============================================================================
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/codeforensics_dev?schema=public"
REDIS_URL="redis://localhost:6379"
# ==============================================================================
# FRONTEND FIREBASE AUTHENTICATION (Public - Bundled into Client)
# ==============================================================================
VITE_API_BASE_URL="http://localhost:4000"
VITE_FIREBASE_API_KEY="your-firebase-api-key"
VITE_FIREBASE_AUTH_DOMAIN="your-app.firebaseapp.com"
VITE_FIREBASE_PROJECT_ID="your-project-id"
# ==============================================================================
# BACKEND FIREBASE ADMIN (Server Only - Never Expose to Client)
# ==============================================================================
FIREBASE_PROJECT_ID="your-project-id"
FIREBASE_SERVICE_ACCOUNT_PATH="./secrets/firebase-service-account.json"
# ==============================================================================
# GITHUB APP INTEGRATION (Server Only)
# ==============================================================================
GITHUB_APP_ID="123456"
GITHUB_CLIENT_ID="Iv1.xxxxxxxxxxxx"
GITHUB_CLIENT_SECRET="your-client-secret"
GITHUB_WEBHOOK_SECRET="your-32-char-random-secret"
GITHUB_PRIVATE_KEY_PATH="./secrets/github-private-key.pem"For complete documentation on every variable, see docs/environment-variables.md.
CodeForensics utilizes Firebase Authentication for secure client sessions and Firebase Admin SDK for server-side cryptographic token verification.
- Open the Firebase Console and create a project.
- In Build > Authentication > Sign-in method, enable Email/Password, Google, and GitHub.
- Under Project Settings > General > Your apps, register a Web App and paste the configuration into the
VITE_FIREBASE_*variables in.env. - Under Project Settings > Service accounts, click Generate new private key. Save the downloaded JSON file as:
secrets/firebase-service-account.json - In Authentication > Settings > Authorized domains, ensure
localhostis listed.
CodeForensics interfaces with GitHub via an official GitHub App, providing higher rate limits and fine-grained permissions:
- In GitHub, go to Settings > Developer settings > GitHub Apps > New GitHub App.
- Configure URLs:
- Homepage URL:
http://localhost:5173 - Callback URL:
http://localhost:4000/auth/github/callback - Webhook URL:
http://localhost:4000/webhooks/github(optional for local dev)
- Homepage URL:
- Set Repository Permissions:
Issues: Read-onlyPull requests: Read-onlyContents: Read-onlyMetadata: Read-only
- Generate a Private Key (
.pemfile) and save it as:secrets/github-private-key.pem - Install the GitHub App on your user account or organization.
For detailed configuration steps, see docs/github-integration.md.
The relational schema in prisma/schema.prisma models software repositories, issues, PRs, comments, commits, and user investigations:
# Inspect relational models in browser
npx prisma studio
# Generate client code
npm run db:generate
# Apply pending schema migrations
npm run db:migrateKey models include:
Repository: Metadata, sync tier states, and synchronization progress.WorkItem: Normalized issues and pull requests with resolution states and labels.WorkItemComment: Chronological discussion threads for lineage analysis.Relationship: Explicit causal connections (ADDRESSES,SUPERSEDES,FIXED_BY) with confidence ratings.Investigation: User-owned research records with hypotheses, observations, and citations.
The worker process (apps/worker) processes background tasks from the repository-sync queue:
# Launch worker process
npm run dev:worker- Rate-Limit Resilience: Detects GitHub API rate limit thresholds and applies exponential backoff.
- Log Sanitization: Redacts sensitive OAuth tokens, private keys, and user credentials.
- Automatic Cleanup: Cleans temporary disk workspaces after completing static analysis.
All JSON responses follow a standardized API envelope ({ success: boolean, data?: T, error?: ApiError, meta?: ApiMeta }):
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Liveness probe reporting database and Redis connection states |
GET |
/ready |
Readiness probe for container orchestrators and load balancers |
GET |
/api/v1/auth/me |
Returns authenticated user profile and token claims |
GET |
/api/v1/repositories |
Lists accessible repositories with sync statuses |
POST |
/api/v1/repositories/:owner/:repo/sync |
Triggers or reschedules background repository sync |
GET |
/api/v1/repositories/:owner/:repo/items |
Lists issues and PRs with filters (state, author, search) |
GET |
/api/v1/repositories/:owner/:repo/relationships |
Returns detected cross-entity relationships and confidence |
GET |
/api/v1/repositories/:owner/:repo/contributions |
Returns ranked contributors and single-point-of-failure risks |
GET |
/api/v1/repositories/:owner/:repo/archaeology/trace |
AST symbol catalog, line spans, and commit history |
GET |
/api/v1/investigations |
Lists saved investigations owned by caller |
POST |
/api/v1/investigations |
Creates a new forensic investigation record |
GET |
/api/v1/investigations/:id |
Retrieves investigation details with verification |
PATCH |
/api/v1/investigations/:id |
Updates investigation status, hypotheses, or findings |
DELETE |
/api/v1/investigations/:id |
Permanently deletes an investigation |
For complete payload schemas and error codes, see docs/api.md.
CodeForensics is engineered with strict defensive security principles:
- Zero Arbitrary Execution: Repository source code is strictly treated as untrusted data. Build scripts (
npm run build), package installation hooks (postinstall), and tests are never executed. - Static AST Parsing: Files are parsed in memory using the official TypeScript Compiler API (
ts.createSourceFile) as text ASTs. - Path Traversal Defense: File paths are validated by
sanitizeFilePath. Absolute paths, parent directory sequences (..), and null bytes (\0) are rejected. - File Size Bounds: Source code analysis is strictly capped at 1MB per file to mitigate algorithmic complexity attacks.
- Strict User Isolation: Object-level authorization guarantees that investigations can only be created, read, or modified by the authenticated owner (
userId === token.uid). - Hardened HTTP Headers: Fastify enforces
X-Content-Type-Options: nosniff,X-Frame-Options: DENY, andReferrer-Policy: strict-origin-when-cross-origin.
For the complete security architecture, see docs/security.md.
To prevent distorted rankings caused by automated formatting passes or dependency bumps, the Contribution Finder applies a balanced multi-signal formula:
-
$w_{\text{pr}} = 25$ : High weight awarded to merged pull requests that passed code review. -
$w_{\text{commit}} = 15$ : Weight awarded to individual commits in the default branch. -
$w_{\text{churn}} = 10$ : Logarithmic dampening ($\ln(1 + \text{LinesChanged})$) prevents automated renames or large asset updates from dominating the score. -
$w_{\text{review}} = 20$ : Recognizes architectural guidance, reviews, and mentorship. -
$\text{FreshnessDecay}$ : Exponential time-decay ($e^{-\lambda t}$ ) rewards current, active maintainers over contributors who left years ago.
CodeForensics maintains automated test suites across all monorepo workspaces:
# Run all automated tests
npm test
# Run strict type checking across all workspaces
npm run typecheck
# Run linting rules
npm run lint
# Run specific workspace tests
npm test --workspace=@codeforensics/api
npm test --workspace=@codeforensics/web| Issue / Error | Likely Root Cause | Solution |
|---|---|---|
auth/invalid-api-key |
Placeholder Firebase key in .env. |
Add your real Firebase API key to VITE_FIREBASE_API_KEY in .env and restart Vite. |
Can't reach database server at 5432 |
PostgreSQL container is stopped. | Run docker compose up -d postgres and verify health with docker ps. |
Sync job remains in QUEUED |
Background worker is not running. | Run npm run dev:worker in a separate terminal. |
GitHub App not configured (401/403) |
Missing PEM file or incorrect App ID. | Verify GITHUB_APP_ID and secrets/github-private-key.pem match your registered GitHub App. |
Port 4000 or 5173 already in use |
Zombie process from previous run. | Kill the occupying process: npx kill-port 4000 5173 or restart your terminal. |
For extended diagnostics, see docs/troubleshooting.md.
Before deploying CodeForensics to production:
- Frontend: Deploy
apps/webto Vercel or Cloudflare Pages. Configure environment variables (VITE_API_BASE_URL,VITE_FIREBASE_*). - Backend API & Worker: Deploy
apps/apiandapps/workeras Node containers on Render, Fly.io, or AWS ECS. - Database & Queue: Provision managed PostgreSQL 16+ (e.g. Neon, Supabase) and managed Redis (e.g. Upstash). Run
npx prisma migrate deployin your CI/CD pipeline. - Domain Configuration: Add your production domain to Firebase Authorized Domains and update GitHub App Webhook URLs.
For full deployment scripts and recipes, see setup.md.
- License: Released under the MIT License.
- Core Technologies: Built with Fastify, React, Vite, Prisma, BullMQ, Tailwind CSS, TypeScript Compiler API, and Firebase.
Watch the complete CodeForensics product demo showing multi-tier repository synchronization, AST Code Archaeology, issue/PR lineage tracing, contributor impact scoring, and the forensic investigations vault:
- Product Demo Video: Watch Demo on Google Drive (Replace with your public drive recording link or view via the live web platform)