# File Structure & Organization
> **Quick Reference**: [Directory Layout](#-directory-layout) | [File Naming](#-file-naming) | [Path Utilities](#-path-utilities)
## π Directory Layout
### Project Root Structure
```
project-root/
βββ .spec-workflow/ # All MCP workflow data
β βββ specs/ # Specification documents
β β βββ feature-name/ # Individual specification
β β βββ requirements.md # Phase 1: Requirements
β β βββ design.md # Phase 2: Design
β β βββ tasks.md # Phase 3: Tasks
β βββ steering/ # Project guidance documents
β β βββ product.md # Product vision & strategy
β β βββ tech.md # Technical standards
β β βββ structure.md # Code organization
β βββ approvals/ # Approval workflow data
β β βββ spec-name/ # Per-spec approvals
β β βββ approval-id.json # Individual approval data
β βββ archive/ # Completed/archived specs
β β βββ specs/ # Archived specification docs
β βββ config.toml (optional) # Project-specific configuration
βββ [your existing project files] # Your actual project
βββ package.json # Your project dependencies
βββ README.md # Your project documentation
```
### MCP Server Source Structure
**Core Implementation Files** (locations confirmed from codebase analysis):
| File Path | Purpose | Key Features |
|-----------|---------|--------------|
| `src/server.ts:74-85` | MCP server initialization | Tool registration, project registry |
| `src/core/path-utils.ts:12-35` | Cross-platform paths | Windows/Unix path handling |
| `src/core/project-registry.ts:96-114` | Project registration | Global project tracking |
| `src/dashboard/approval-storage.ts:20-45` | Human approval system | JSON file persistence |
| `src/dashboard/multi-server.ts:45-200` | Multi-project dashboard | WebSocket, file watching |
**Template System** (static content, no AI generation):
```
src/
βββ core/ # Core business logic
β βββ archive-service.ts # Spec archiving functionality
β βββ parser.ts # Spec parsing & analysis
β βββ path-utils.ts # Cross-platform path handling
β βββ project-registry.ts # Global project tracking
β βββ task-parser.ts # Task management & parsing
βββ tools/ # MCP tool implementations
β βββ index.ts # Tool registry & dispatcher
β βββ spec-workflow-guide.ts # Workflow instructions
β βββ steering-guide.ts # Steering doc instructions
β βββ create-spec-doc.ts # Spec document creation
β βββ create-steering-doc.ts # Steering doc creation
β βββ get-spec-context.ts # Load spec context
β βββ get-steering-context.ts # Load steering context
β βββ get-template-context.ts # Load templates
β βββ spec-list.ts # List all specifications
β βββ spec-status.ts # Get spec status
β βββ manage-tasks.ts # Task management
β βββ request-approval.ts # Create approval requests
β βββ get-approval-status.ts # Check approval status
β βββ delete-approval.ts # Clean up approvals
βββ dashboard/ # Dashboard backend
β βββ multi-server.ts # Multi-project Fastify server
β βββ project-manager.ts # Project lifecycle management
β βββ approval-storage.ts # Approval persistence
β βββ parser.ts # Dashboard-specific parsing
β βββ watcher.ts # File system watching
β βββ utils.ts # Dashboard utilities
β βββ public/ # Static assets
β βββ claude-icon.svg # Light mode icon
β βββ claude-icon-dark.svg # Dark mode icon
βββ dashboard_frontend/ # React dashboard frontend
β βββ src/
β β βββ modules/
β β β βββ api/ # API communication layer
β β β βββ app/ # Main application component
β β β βββ approvals/ # Approval UI components
β β β βββ editor/ # Markdown editor
β β β βββ markdown/ # Markdown rendering
β β β βββ modals/ # Modal dialog components
β β β βββ notifications/ # Toast notifications
β β β βββ pages/ # Main page components
β β β βββ theme/ # Styling & themes
β β β βββ ws/ # WebSocket integration
β β βββ main.tsx # React application entry
β β βββ App.tsx # Root application component
β βββ index.html # HTML template
β βββ vite.config.ts # Vite build configuration
β βββ tailwind.config.js # Tailwind CSS config
βββ markdown/ # Document templates
β βββ templates/
β βββ requirements-template.md # Requirements document template
β βββ design-template.md # Design document template
β βββ tasks-template.md # Tasks document template
β βββ product-template.md # Product vision template
β βββ tech-template.md # Technical standards template
β βββ structure-template.md # Code structure template
βββ server.ts # Main MCP server class
βββ index.ts # CLI entry point & argument parsing
βββ types.ts # TypeScript type definitions
```
### VS Code Extension Structure
```
vscode-extension/
βββ src/
β βββ extension.ts # Extension entry point
β βββ extension/
β β βββ providers/ # VS Code providers
β β β βββ SidebarProvider.ts # Sidebar webview provider
β β βββ services/ # Business logic services
β β β βββ ApprovalCommandService.ts # Approval commands
β β β βββ ApprovalEditorService.ts # Approval editor integration
β β β βββ ArchiveService.ts # Archive functionality
β β β βββ CommentModalService.ts # Comment modal handling
β β β βββ FileWatcher.ts # File system watching
β β β βββ SpecWorkflowService.ts # Main workflow service
β β βββ types.ts # Extension type definitions
β β βββ utils/ # Utility functions
β β βββ colorUtils.ts # Color manipulation
β β βββ logger.ts # Logging functionality
β β βββ taskParser.ts # Task parsing for extension
β βββ webview/ # Webview components (React)
β βββ App.tsx # Main webview application
β βββ components/ # Reusable UI components
β βββ hooks/ # React hooks
β βββ lib/ # Utility libraries
β βββ main.tsx # Webview entry point
βββ webview-assets/ # Static webview assets
β βββ sounds/ # Audio notification files
β βββ approval-pending.wav # Approval request sound
β βββ task-completed.wav # Task completion sound
βββ icons/ # Extension icons
β βββ activity-bar-icon.svg # Activity bar icon
β βββ spec-workflow.svg # General extension icon
βββ package.json # Extension manifest & dependencies
βββ README.md # Extension documentation
```
## π File Naming Conventions
### Specification Names
- **Format**: `kebab-case` (lowercase with hyphens)
- **Examples**: β
`user-authentication`, `payment-flow`, `admin-dashboard`
- **Invalid**: β `UserAuth`, `payment_flow`, `Admin Dashboard`
### Document Files
- **Requirements**: `requirements.md`
- **Design**: `design.md`
- **Tasks**: `tasks.md`
- **Product**: `product.md`
- **Tech**: `tech.md`
- **Structure**: `structure.md`
### Approval Files
- **Format**: `{spec-name}-{document}-{timestamp}.json`
- **Example**: `user-auth-requirements-20241215-143022.json`
- **Auto-generated**: System creates these automatically
## π οΈ Path Utilities
### Cross-Platform Path Handling
The system uses `PathUtils` class for consistent path handling across Windows, macOS, and Linux:
```typescript
export class PathUtils {
// Get workflow root directory
static getWorkflowRoot(projectPath: string): string {
return normalize(join(projectPath, '.spec-workflow'));
}
// Get spec directory path
static getSpecPath(projectPath: string, specName: string): string {
return normalize(join(projectPath, '.spec-workflow', 'specs', specName));
}
// Get steering documents path
static getSteeringPath(projectPath: string): string {
return normalize(join(projectPath, '.spec-workflow', 'steering'));
}
// Convert to platform-specific path
static toPlatformPath(path: string): string {
return path.split('/').join(sep);
}
// Convert to Unix-style path (for JSON/API)
static toUnixPath(path: string): string {
return path.split(sep).join('/');
}
}
```
### Common Path Operations
```typescript
// Examples of PathUtils usage
// Get spec path
const specPath = PathUtils.getSpecPath('/project', 'user-auth');
// Result: /project/.spec-workflow/specs/user-auth
// Get requirements file path
const reqPath = join(specPath, 'requirements.md');
// Result: /project/.spec-workflow/specs/user-auth/requirements.md
// Get relative path for API responses
const relativePath = PathUtils.toUnixPath(reqPath.replace(projectPath, ''));
// Result: .spec-workflow/specs/user-auth/requirements.md
```
## π Directory Creation & Management
### Auto-Created Directories
The system automatically creates these directories as needed:
```typescript
// Directories created during initialization
const directories = [
'.spec-workflow/',
'.spec-workflow/specs/',
'.spec-workflow/steering/',
'.spec-workflow/archive/',
'.spec-workflow/archive/specs/'
];
// Directories created on-demand
const onDemandDirectories = [
'.spec-workflow/approvals/',
'.spec-workflow/approvals/{spec-name}/',
'.spec-workflow/specs/{spec-name}/'
];
```
### Directory Validation
```typescript
export async function validateProjectPath(projectPath: string): Promise<string> {
// Resolve to absolute path
const absolutePath = resolve(projectPath);
// Check if path exists
await access(absolutePath, constants.F_OK);
// Ensure it's a directory
const stats = await stat(absolutePath);
if (!stats.isDirectory()) {
throw new Error(`Project path is not a directory: ${absolutePath}`);
}
return absolutePath;
}
```
### Cleanup & Maintenance
```typescript
// Archive completed specifications
export class SpecArchiveService {
async archiveSpec(specName: string): Promise<void> {
const sourceDir = PathUtils.getSpecPath(this.projectPath, specName);
const archiveDir = PathUtils.getArchiveSpecPath(this.projectPath, specName);
// Move spec to archive
await fs.rename(sourceDir, archiveDir);
// Clean up approvals
const approvalsDir = PathUtils.getSpecApprovalPath(this.projectPath, specName);
await fs.rm(approvalsDir, { recursive: true, force: true });
}
}
```
## π File Permissions & Security
### Required Permissions
```bash
# Minimum required permissions
.spec-workflow/ # 755 (rwxr-xr-x)
βββ specs/ # 755 (rwxr-xr-x)
βββ steering/ # 755 (rwxr-xr-x)
βββ approvals/ # 755 (rwxr-xr-x)
βββ archive/ # 755 (rwxr-xr-x)
```
### Security Considerations
**File Access Restrictions**:
- β
Read/Write: Only within `.spec-workflow/` directory
- β
Read-Only: Project files (for analysis)
- β Forbidden: System directories, parent directory traversal
**Path Traversal Prevention**:
```typescript
// All paths are normalized and validated
const safePath = normalize(join(projectPath, '.spec-workflow', userInput));
// Ensure path stays within project
if (!safePath.startsWith(projectPath)) {
throw new Error('Path traversal attempt detected');
}
```
## π Storage Considerations
### File Size Limits
| File Type | Typical Size | Max Recommended |
|-----------|-------------|-----------------|
| Requirements | 5-20 KB | 100 KB |
| Design | 10-50 KB | 200 KB |
| Tasks | 5-30 KB | 150 KB |
| Steering Docs | 5-20 KB | 100 KB |
| Approval Data | < 1 KB | 5 KB |
| Session Data | < 1 KB | 2 KB |
### Disk Usage Estimation
```typescript
// Typical project disk usage
interface DiskUsage {
singleSpec: '50-200 KB'; // All 3 documents
steeringDocs: '20-100 KB'; // All steering documents
approvalData: '1-10 KB'; // Per approval workflow
sessionData: '< 1 KB'; // Session tracking
totalTypical: '100-500 KB'; // For small-medium project
totalLarge: '1-5 MB'; // For large project with many specs
}
```
### Cleanup Strategies
```bash
# Manual cleanup commands
# Remove completed approvals (older than 30 days)
find .spec-workflow/approvals -name "*.json" -mtime +30 -delete
# Archive old specifications
# (Move specs with all tasks completed to archive/)
# Full reset (nuclear option)
rm -rf .spec-workflow/
```
---
**Next**: [Dashboard System β](dashboard.md)