Skip to content

aflsolutions/wiki-generator

Repository files navigation

Wiki Generator

Transform any GitHub repository into comprehensive, AI-powered documentation with semantic code search.

Built with advanced RAG (Retrieval-Augmented Generation) pipeline, knowledge graph for code relationships, multi-agent system, and vector search for intelligent code discovery.


🎯 What It Does

  1. πŸ“– Wiki Generation - Analyzes GitHub repos and generates feature-focused documentation
  2. 🧠 Knowledge Graph - Discovers complete features by following function calls
  3. πŸ” Semantic Search - Natural language search across all indexed codebases
  4. πŸ€– AI Agents - 4 specialized agents analyze tech stack, features, and architecture
  5. πŸ”— GitHub Integration - Direct links to source code with line numbers

✨ Key Features

Wiki Generation

  • Fetches code from any public GitHub repository
  • Builds knowledge graph from function calls (discovers code relationships)
  • Analyzes tech stack and architecture patterns
  • Identifies user-facing features with complete code flows
  • Generates MDX documentation with code examples
  • Stores wikis in Vercel Blob for instant access

Semantic Code Search

  • Natural language queries ("user authentication", "database queries")
  • AI-powered vector embeddings for semantic understanding
  • Search across all generated wikis
  • View code snippets with GitHub source links
  • Fast results with Upstash Vector

Multi-Agent System

  1. Recon Agent - Identifies tech stack, languages, frameworks, and architecture
  2. Features Agent - Detects user-facing features using knowledge graph (follows function calls to discover complete features)
  3. Architecture Agent - Analyzes architectural patterns and design
  4. Docs Generator - Creates comprehensive documentation with code citations

Knowledge Graph

  • Extracts function calls from code using AST parsing (all languages supported)
  • Builds graph: function A β†’ calls β†’ function B β†’ calls β†’ function C
  • Discovers complete features by finding entry points and traversing the graph
  • Example: login() β†’ discovers validateInput(), findUser(), generateToken() (complete auth flow)

πŸš€ Quick Start

# 1. Clone and install
git clone <your-repo>
cd wiki-generator
npm install

# 2. Set up environment variables
cp .env.local.example .env.local
# Edit .env.local and add:
# - OPENAI_API_KEY
# - UPSTASH_VECTOR_REST_URL
# - UPSTASH_VECTOR_REST_TOKEN

# 3. Run development server
npm run dev

# 4. Visit http://localhost:3000

πŸ“ Project Structure

wiki-generator/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ generate-wiki/      # Wiki generation endpoint
β”‚   β”‚   β”œβ”€β”€ search/             # Semantic search endpoint
β”‚   β”‚   └── workflow-status/    # Workflow status polling
β”‚   β”œβ”€β”€ generate/               # Wiki generation UI
β”‚   β”œβ”€β”€ search/                 # Search UI
β”‚   β”œβ”€β”€ wiki/                   # Wiki display pages
β”‚   └── page.tsx                # Home page
β”‚
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ agents/                 # AI Agent System (4 agents)
β”‚   β”‚   β”œβ”€β”€ recon/              # Tech stack analysis
β”‚   β”‚   β”œβ”€β”€ features/           # Feature detection
β”‚   β”‚   β”œβ”€β”€ architecture/       # Pattern analysis
β”‚   β”‚   β”œβ”€β”€ docs-generator/     # Documentation generation
β”‚   β”‚   └── shared/             # Agent factory & utilities
β”‚   β”œβ”€β”€ rag/                    # RAG Pipeline
β”‚   β”‚   β”œβ”€β”€ chunker.ts          # Code chunking with tree-sitter
β”‚   β”‚   β”œβ”€β”€ embedder.ts         # OpenAI embeddings
β”‚   β”‚   β”œβ”€β”€ index.ts            # RAG orchestration
β”‚   β”‚   └── vector-search.ts    # Vector similarity search
β”‚   β”œβ”€β”€ github/
β”‚   β”‚   └── fetcher.ts          # GitHub API client
β”‚   β”œβ”€β”€ vector-storage.ts       # Upstash Vector integration
β”‚   β”œβ”€β”€ blob-storage.ts         # Vercel Blob wiki storage
β”‚   └── wiki.ts                 # Wiki loading utilities
β”‚
β”œβ”€β”€ workflows/
β”‚   └── wikiGeneration/         # Main workflow
β”‚       β”œβ”€β”€ index.ts            # Orchestration (parallel execution)
β”‚       └── steps/              # Individual steps
β”‚           β”œβ”€β”€ fetchRepo.ts
β”‚           β”œβ”€β”€ buildIndex.ts   # Includes vector storage
β”‚           β”œβ”€β”€ runRecon.ts
β”‚           β”œβ”€β”€ runFeatures.ts
β”‚           β”œβ”€β”€ runArchitecture.ts
β”‚           β”œβ”€β”€ generateDocs.ts
β”‚           └── saveToBlob.ts
β”‚
└── components/                 # UI components (shadcn/ui)

πŸ›  Tech Stack

Frontend

  • Next.js 15 (App Router)
  • React 19
  • TypeScript (strict mode)
  • Tailwind CSS + shadcn/ui

AI & Embeddings

  • Vercel AI SDK (generateObject)
  • OpenAI GPT-5-mini (agents)
  • OpenAI text-embedding-3-small (1536 dimensions)

Storage & Search

  • Upstash Vector (semantic search, ~2KB/chunk)
  • Vercel Blob (wiki storage, MDX files)
  • Vercel Workflow (orchestration, retries)

Code Analysis

  • tree-sitter (AST parsing for JS/TS/Python/Go/Rust)
  • Knowledge Graph (in-memory graph for code relationships)
  • Octokit (GitHub API)

βš™οΈ Environment Variables

Create a .env.local file:

# Required: OpenAI API
OPENAI_API_KEY=sk-...

# Required: Upstash Vector (for search)
UPSTASH_VECTOR_REST_URL=https://...
UPSTASH_VECTOR_REST_TOKEN=...

# Optional: GitHub API (higher rate limits)
GITHUB_TOKEN=ghp_...

# Auto-added by Vercel (for Blob storage)
BLOB_READ_WRITE_TOKEN=...

Setup Instructions:

  1. OpenAI API Key: https://platform.openai.com/api-keys

  2. Upstash Vector:

  3. GitHub Token (optional):


🎨 How It Works

Wiki Generation Workflow

User enters GitHub URL (e.g., "sindresorhus/is")
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Step 1: Fetch Repository                                β”‚
β”‚  β€’ Clone file tree via GitHub API                        β”‚
β”‚  β€’ Filter out tests, node_modules, build artifacts       β”‚
β”‚  β€’ Fetch up to 300 source files                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Step 2a: Build RAG Index β”‚ Step 2b: Run Recon Agent   β”‚
β”‚  (PARALLEL)                β”‚ (PARALLEL)                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ Parse top 150 chunks    β”‚ β€’ Analyze README            β”‚
β”‚  β€’ Generate embeddings     β”‚ β€’ Detect tech stack         β”‚
β”‚  β€’ Truncate code to 3KB    β”‚ β€’ Identify patterns         β”‚
β”‚  β€’ Save to Upstash Vector  β”‚ β€’ Map directory structure   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Step 3a: Features Agent   β”‚ Step 3b: Architecture Agentβ”‚
β”‚  (PARALLEL)                β”‚ (PARALLEL)                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ Top 50 chunks (3KB max) β”‚ β€’ Top 30 chunks (3KB max)   β”‚
β”‚  β€’ Detect user features    β”‚ β€’ Identify patterns         β”‚
β”‚  β€’ Rate importance (1-10)  β”‚ β€’ Explain data flow         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Step 4: Generate Documentation (Important Features)    β”‚
β”‚  β€’ Filter features: importance >= 4 only (focus quality)β”‚
β”‚  β€’ For each feature: find relevant code chunks          β”‚
β”‚  β€’ Docs Generator creates MDX with examples (3K tokens) β”‚
β”‚  β€’ Include code citations (file:line)                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Step 5: Save Wiki to Vercel Blob                        β”‚
β”‚  β€’ Generate index.mdx (overview)                         β”‚
β”‚  β€’ Generate feature pages (feature-name.mdx)             β”‚
β”‚  β€’ Store as public blobs                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           ↓
    βœ“ Wiki ready at /wiki/repo-name
    βœ“ Searchable via semantic search

Duration: ~1.5-2 minutes for typical repo (300 files)

Performance Optimizations

  1. Parallel Execution: Recon + Index building run concurrently (saves 9s)
  2. Limited Embeddings: Only top 150 chunks embedded (70% faster, 70% cheaper)
  3. Chunk Truncation: 3KB max per chunk for agents (prevents context overflow)
  4. Parallel Agents: Features + Architecture run concurrently (saves 30s)
  5. Feature Filtering: Only document important features (importance β‰₯ 4)
  6. Increased Parallelism:
    • GitHub fetching: 50 files/batch (was 20)
    • Embeddings: 10 concurrent batches (was 3)

Semantic Search Flow

User types: "user authentication"
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. Generate Query Embedding                             β”‚
β”‚  β€’ OpenAI text-embedding-3-small                         β”‚
β”‚  β€’ 1536-dimensional vector                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  2. Vector Similarity Search                             β”‚
β”‚  β€’ Query Upstash Vector with embedding                   β”‚
β”‚  β€’ Cosine similarity ranking                             β”‚
β”‚  β€’ Returns top 20 matches                                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  3. Display Results                                      β”‚
β”‚  β€’ Code snippet (500 chars)                              β”‚
β”‚  β€’ File path + line numbers                              β”‚
β”‚  β€’ Similarity score (% match)                            β”‚
β”‚  β€’ "View on GitHub" link                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Response time: < 1 second


🎯 Core Principles

  1. KISS - Simple, direct implementations (no over-engineering)
  2. DRY - Reuse through utilities and shared patterns
  3. Type Safety - Strict TypeScript, no any types
  4. User-Focused - Document features, not technical layers
  5. Quality - All code passes lint + type checks

πŸ“Š Architecture Decisions

Why Vector Search Only?

  • βœ… Simple, fast, accurate for semantic queries
  • βœ… Handles typos and synonyms ("auth" finds "authentication")
  • βœ… No complex fusion algorithms needed
  • ❌ Removed BM25 hybrid search (added complexity, minimal benefit)
  • ❌ Removed reranking (128K context makes it unnecessary)

Why Truncate Instead of Compress?

  • βœ… Speed: Instant vs 60s for AI compression (100x faster)
  • βœ… Coverage: 50 chunks Γ— 3KB = 150KB (vs 20 chunks Γ— 2KB = 40KB compressed)
  • βœ… Quality: First 3KB captures function signatures, logic, JSDoc
  • βœ… Cost: Free vs API calls for each chunk
  • ❌ Compression was too slow (code-summarizer agent took 60s for 20 chunks)
  • ❌ Agents need breadth (many examples) > depth (complete implementations)
  • πŸ“ Trade-off: Agents see truncated code, but full code still in Vector for search

Why Snippet-Only in Search?

  • βœ… Upstash Vector has 48KB metadata limit
  • βœ… Full code (10KB+) exceeds limit
  • βœ… 500-char snippets sufficient for preview
  • βœ… "View on GitHub" provides full context
  • πŸ“ Future: Hybrid storage (Vector + Blob) for full code on-demand

Why Filter Test Files?

  • βœ… Focus on implementation code
  • βœ… Faster processing (skip 30-40% of files)
  • βœ… Better feature detection (tests don't represent features)
  • βœ… Reduced API costs

πŸ’° Cost Analysis

Per Large Repository (~300 files)

GitHub API:        Free (60 req/hour w/o token, 5000/hour with)
Embeddings:        150 chunks Γ— $0.00002 = $0.003 (70% reduction!)
Agent calls:       ~6 calls Γ— $0.15 = $0.90
Total per wiki:    ~$0.90

Monthly costs (10 wikis/month):
OpenAI:            ~$9/month
Upstash Vector:    Free tier (up to 10K vectors)
Vercel Blob:       ~$0.15/month (1GB storage)
Total:             ~$9.15/month

Performance: 3.5 min β†’ 1.5 min (57% faster)

⚠️ Known Limitations

Current Constraints:

  1. No Incremental Updates - Must regenerate entire wiki for changes
  2. Snippet-Only Search - 500-char limit (full code on GitHub)
  3. Truncated Code for Agents - Chunks limited to 3KB to fit context windows
    • Trade-off: Speed & reliability > complete code visibility
    • First 3KB captures signatures, logic, JSDoc (usually sufficient)
  4. Important Features Only - Only generates docs for importance β‰₯ 4
    • Trade-off: Quality & speed > comprehensive coverage
  5. No Authentication - All wikis are public
  6. No Rate Limiting - Can be abused
  7. No Caching - Same repo re-analyzed costs same amount
  8. Single Model - No fallback if OpenAI is down

Future Improvements:

  • Incremental updates with Merkle trees (90% cost reduction)
  • Full code storage (Blob + Vector hybrid)
  • Authentication & user workspaces
  • Caching layer (Redis) for embeddings and agents
  • Model fallbacks (Anthropic, Gemini)
  • Private repo support (user GitHub tokens)
  • Smart code completion for truncated chunks
    • Current: Hard truncate at 3KB (fast, predictable)
    • Future: Intelligent truncation at semantic boundaries (end of function/class)
    • Or: Dynamic chunk sizing based on available context budget

πŸ§ͺ Development

Commands

# Development
npm run dev              # Start dev server (http://localhost:3000)
npm run build            # Production build
npm run start            # Start production server

# Quality checks (must pass before commit)
npm run lint             # ESLint (0 errors allowed)
npx tsc --noEmit        # TypeScript checking

# Testing
npm run test:rag         # Test RAG pipeline
npm run test:github      # Test GitHub fetcher
npm run test:docs        # Test docs generation

Code Quality Standards

  • βœ… All code passes ESLint (0 errors, 0 warnings)
  • βœ… All code passes TypeScript type checking
  • βœ… No any types (use unknown or specific types)
  • βœ… Proper error handling with try/catch
  • βœ… Clear, concise comments

Agent Development Pattern

Each agent follows strict 4-file structure:

lib/agents/[agent-name]/
β”œβ”€β”€ schema.ts      # Zod validation schema
β”œβ”€β”€ types.ts       # Input/Output TypeScript types
β”œβ”€β”€ prompt.ts      # System + User message builders
└── index.ts       # Agent definition with defineAgent()

Example:

// schema.ts
export const myAgentSchema = z.object({
  result: z.string(),
  confidence: z.number(),
});

// types.ts
export type MyAgentOutput = z.infer<typeof myAgentSchema>;
export interface MyAgentInput { context: RepoContext; }

// prompt.ts
export const SYSTEM_MESSAGE = `You are an expert...`;
export function buildUserMessage(input: MyAgentInput): string { ... }

// index.ts
export const myAgent = defineAgent({
  name: 'my-agent',
  schema: myAgentSchema,
  systemMessage: SYSTEM_MESSAGE,
  buildUserMessage,
});

🚒 Deployment

Vercel (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

# Set environment variables in dashboard:
# - OPENAI_API_KEY
# - UPSTASH_VECTOR_REST_URL
# - UPSTASH_VECTOR_REST_TOKEN
# - GITHUB_TOKEN (optional)

Other Platforms

Requires:

  • Node.js 20+
  • Support for Vercel Workflow (or alternative orchestration)
  • Environment variables configured

πŸ“ License

MIT


Built with ❀️ using AI-powered development

About

Automatically generate comprehensive documentation from code. Analyzes repositories using semantic chunking and hybrid search to create feature-driven wikis with inline code citations. Say goodbye to outdated docs.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors