# Project Structure
This document describes the organization of the MCP Codebase Index project.
---
## π Directory Structure
```
mcp-codebase-index/
β
βββ π docs/ # All documentation
β βββ README.md # Main documentation
β βββ SETUP.md # Setup guide
β βββ QUICK_REF.md # Quick reference
β βββ CHANGELOG.md # Version history
β βββ NAVIGATION.md # Navigation guide
β βββ COPILOT_INSTRUCTIONS.md # Copilot usage guide
β β
β βββ guides/ # Detailed guides
β β βββ QDRANT_CLOUD_SETUP.md # Qdrant setup
β β βββ mcp-server-guide.md # MCP development
β β βββ TEST_SEARCH.md # Testing guide
β β
β βββ planning/ # Development planning
β βββ IMPROVEMENT_PLAN.md # Roadmap
β βββ RAGxplore.md # Research notes
β βββ issues/ # Issue documentation
β βββ issue-1-implementation.md
β βββ issue-2-rate-limiting.md
β βββ ...
β
βββ π» src/ # Source code
β βββ README.md # Source code documentation
β β
β βββ core/ # Core business logic
β β βββ indexer.ts # Code parsing & chunking
β β βββ embedder.ts # Gemini embedding
β β βββ fileWatcher.ts # File monitoring
β β
β βββ storage/ # Storage layer
β β βββ qdrantClient.ts # Qdrant vector DB
β β
β βββ enhancement/ # Prompt enhancement
β β βββ promptEnhancer.ts # Enhancement logic
β β βββ templates.ts # Enhancement templates
β β
β βββ visualization/ # Vector visualization
β β βββ visualizer.ts # Main visualizer
β β βββ reducer.ts # UMAP dimensionality reduction
β β βββ vectorRetriever.ts # Vector fetching
β β βββ exporter.ts # Format exporters
β β βββ types.ts # Visualization types
β β
β βββ mcp/ # MCP server layer
β β βββ server.ts # MCP server orchestration (1237 lines)
β β βββ handlers/ # Modular handler functions
β β β βββ search.handler.ts # Search functionality (74 lines)
β β β βββ enhancement.handler.ts # Prompt enhancement (131 lines)
β β β βββ visualization.handler.ts # Visualizations (296 lines)
β β β βββ indexing.handler.ts # Index management (544 lines)
β β βββ templates/ # HTML templates
β β β βββ visualization.template.ts # Modern HTML UI
β β βββ types/ # Handler types
β β βββ handlers.types.ts # Context interfaces
β β
β βββ types/ # Type definitions
β β βββ index.ts # All TypeScript types
β β
β βββ index.ts # Entry point
β
βββ βοΈ config/ # Configuration files
β βββ README.md # Config documentation
β βββ vscode_settings.example.json # VS Code settings example
β
βββ π¦ .data/ # Runtime data (gitignored)
β βββ memory/ # Index state & metadata
β βββ vector_storage/ # Local vector cache
β
βββ ποΈ dist/ # Build output (gitignored)
β βββ (compiled JavaScript files)
β
βββ π Root Files
β βββ README.md # Project overview
β βββ PROJECT_STRUCTURE.md # This file
β βββ package.json # NPM package config
β βββ package-lock.json # NPM lock file
β βββ tsconfig.json # TypeScript config
β βββ .gitignore # Git ignore rules
β βββ .env.example # Environment variables example
β βββ vscode_settings.local.json # Local VS Code settings
β
βββ π¦ node_modules/ # Dependencies (gitignored)
```
---
## π― Design Principles
### 1. **Separation of Concerns**
Each directory has a clear, single responsibility:
- `docs/` - All documentation
- `src/core/` - Business logic
- `src/storage/` - Data persistence
- `src/enhancement/` - Optional features
- `src/visualization/` - Vector visualization
- `src/mcp/` - Protocol layer
- `handlers/` - Modular handler functions
- `templates/` - HTML templates
- `types/` - Handler-specific types
- `src/types/` - Shared type definitions
### 2. **Modular Handler Architecture (v1.5.4-beta.19)**
The MCP server uses a **context injection pattern** for clean handler separation:
**Structure:**
```typescript
// Server orchestrates
class CodebaseIndexMCPServer {
private async handleSearch(args: any) {
const context: SearchHandlerContext = {
embedder: this.embedder,
vectorStore: this.vectorStore
};
return await handleSearch(args, context);
}
}
// Handler executes
export async function handleSearch(
args: any,
context: SearchHandlerContext
) {
// Implementation with injected dependencies
}
```
**Benefits:**
- **Testability**: Handlers can be tested in isolation
- **Maintainability**: Clear dependencies via context interfaces
- **Scalability**: Easy to add new handlers
- **Readability**: Reduced from 2060 to 1237 lines in server.ts
**Handler Modules:**
- `search.handler.ts` - Search functionality (74 lines)
- `enhancement.handler.ts` - Prompt enhancement (131 lines)
- `visualization.handler.ts` - Vector visualizations (296 lines)
- `indexing.handler.ts` - Index management (544 lines)
### 3. **Clean Root Directory**
Only essential files at root level:
- Package management: `package.json`, `package-lock.json`
- Configuration: `tsconfig.json`, `.gitignore`, `.env.example`
- Documentation: `README.md`, `PROJECT_STRUCTURE.md`
### 4. **Documentation First**
- Every major directory has a README.md
- Navigation guide helps users find what they need
- Examples and guides for common tasks
### 5. **Scalability**
- Easy to add new features (create new folder in `src/`)
- Easy to add new handlers (create new handler file)
- Easy to add new docs (add to `docs/guides/`)
- Easy to find files (logical grouping)
---
## π Key Files
### Entry Points
| File | Purpose |
|------|---------|
| `src/index.ts` | Application entry point |
| `README.md` | Project overview |
| `docs/README.md` | Main documentation |
### Configuration
| File | Purpose |
|------|---------|
| `tsconfig.json` | TypeScript compiler config |
| `package.json` | NPM package config |
| `.env.example` | Environment variables template |
| `config/vscode_settings.example.json` | VS Code MCP config |
### Documentation
| File | Purpose |
|------|---------|
| `docs/SETUP.md` | Installation guide |
| `docs/NAVIGATION.md` | Find any doc quickly |
| `docs/QUICK_REF.md` | Command reference |
| `src/README.md` | Source code guide |
---
## π Import Paths
After restructuring, import paths follow this pattern:
```typescript
// From src/index.ts
import { CodebaseIndexMCPServer } from './mcp/server.js';
// From src/mcp/server.ts
import { CodeIndexer } from '../core/indexer.js';
import { CodeEmbedder } from '../core/embedder.js';
import { QdrantVectorStore } from '../storage/qdrantClient.js';
import { PromptEnhancer } from '../enhancement/promptEnhancer.js';
import { VectorVisualizer } from '../visualization/visualizer.js';
import { IndexerConfig } from '../types/index.js';
// Import handlers (v1.5.4-beta.19+)
import { handleSearch, SearchHandlerContext } from './handlers/search.handler.js';
import { handleEnhancePrompt, handleEnhancementTelemetry, EnhancementHandlerContext } from './handlers/enhancement.handler.js';
import { handleVisualizeCollection, handleVisualizeQuery, handleExportVisualizationHtml, VisualizationHandlerContext } from './handlers/visualization.handler.js';
import { handleIndexingStatus, handleCheckIndex, handleRepairIndex, IndexingHandlerContext } from './handlers/indexing.handler.js';
// From handlers
import { CodeEmbedder } from '../../core/embedder.js';
import { QdrantVectorStore } from '../../storage/qdrantClient.js';
import { VectorVisualizer } from '../../visualization/visualizer.js';
// From src/core/indexer.ts
import { CodeChunk } from '../types/index.js';
```
**Note:** Always use `.js` extension (required for ES modules)
---
## ποΈ File Organization Rules
### Source Code (`src/`)
- **One class per file** (e.g., `CodeIndexer` in `indexer.ts`)
- **One handler per function** (e.g., `handleSearch` in `search.handler.ts`)
- **Group by domain** (core, storage, enhancement, visualization, mcp)
- **Handlers in mcp/handlers/** (modular functions with context injection)
- **Types in separate folder** (`types/index.ts` for shared, `mcp/types/` for handlers)
### Handler Files (`src/mcp/handlers/`)
- **Export context interface** (e.g., `SearchHandlerContext`)
- **Export handler function** (e.g., `handleSearch`)
- **Pure functions** (no state, dependencies via context)
- **Descriptive names** (e.g., `search.handler.ts`, `indexing.handler.ts`)
### Documentation (`docs/`)
- **Main docs at root** (README, SETUP, CHANGELOG)
- **Guides in guides/** (detailed tutorials)
- **Planning in planning/** (roadmap, issues)
### Configuration (`config/`)
- **Example files only** (actual configs are gitignored)
- **One config per file** (clear purpose)
---
## π« Gitignored Directories
These directories are created at runtime and not tracked by git:
```
.data/ # Runtime data
βββ memory/ # Index state & metadata
βββ vector_storage/ # Local vector cache
dist/ # Build output
node_modules/ # Dependencies
```
---
## π File Count by Type
| Type | Count | Location |
|------|-------|----------|
| TypeScript Source | 9 | `src/` |
| Documentation | 20+ | `docs/` |
| Configuration | 3 | `config/`, root |
| Build Output | Auto-generated | `dist/` |
---
## π Finding Files
### "Where is the MCP server implementation?"
β `src/mcp/server.ts`
### "Where is the indexing logic?"
β `src/core/indexer.ts`
### "Where is the setup guide?"
β `docs/SETUP.md`
### "Where are the type definitions?"
β `src/types/index.ts`
### "Where is the Qdrant client?"
β `src/storage/qdrantClient.ts`
### "Where is prompt enhancement?"
β `src/enhancement/promptEnhancer.ts`
### "Where are the enhancement templates?"
β `src/enhancement/templates.ts`
---
## π οΈ Build Process
```
src/ β tsc β dist/
βββ core/ βββ core/
βββ storage/ βββ storage/
βββ enhancement/ βββ enhancement/
βββ mcp/ βββ mcp/
βββ types/ βββ types/
βββ index.ts βββ index.js
```
**Command:** `npm run build`
**Output:** JavaScript files in `dist/` with source maps and type declarations
---
## π Adding New Features
### 1. Add Source Code
```
src/
βββ new-feature/
βββ featureLogic.ts
βββ featureTypes.ts (if needed)
```
### 2. Add Documentation
```
docs/
βββ planning/issues/
β βββ issue-N-new-feature.md
βββ guides/
βββ new-feature-guide.md (if needed)
```
### 3. Update Types
```typescript
// src/types/index.ts
export interface NewFeatureConfig {
// ...
}
```
### 4. Integrate
```typescript
// src/mcp/server.ts
import { NewFeature } from '../new-feature/featureLogic.js';
```
---
## π Learning the Codebase
**Recommended reading order:**
1. **[README.md](./README.md)** - Project overview
2. **[docs/SETUP.md](./docs/SETUP.md)** - How to set up
3. **[src/README.md](./src/README.md)** - Code structure
4. **[src/index.ts](./src/index.ts)** - Entry point
5. **[src/mcp/server.ts](./src/mcp/server.ts)** - Main server logic
6. **[src/types/index.ts](./src/types/index.ts)** - Type definitions
7. **Individual components** - Dive into specific features
---
## π Questions?
- **Documentation:** [docs/NAVIGATION.md](./docs/NAVIGATION.md)
- **Issues:** [GitHub Issues](https://github.com/NgoTaiCo/mcp-codebase-index/issues)
- **Email:** ngotaico.flutter@gmail.com
---
**Last Updated:** 2024-11-10