33## Code Style
44
55### General
6- - NO emojis anywhere - not in code, comments, docs, or commit messages
6+ - NO emojis anywhere -- not in code, comments, docs, or commit messages
77- Prefer files under 200 lines. Larger files allowed when logically cohesive.
88- Comments explain WHY, not WHAT. Keep them brief.
99- No decorative headers or ASCII art
10- - Casual tone in comments - write like a human, not a robot
10+ - Casual tone in comments -- write like a human, not a robot
1111
1212### JSDoc Policy
1313- JSDoc allowed for public API functions and exported hooks
14- - Keep JSDoc minimal - document params and return types, not obvious behavior
15- - Approved files using JSDoc: ` frontend/src/services/playground-api.ts ` , ` frontend/src/config/api.ts ` , ` frontend/src/hooks/useViewTransition.ts `
14+ - Keep JSDoc minimal -- document params and return types, not obvious behavior
1615
1716### Large File Exceptions
1817These files exceed 200 lines but are approved due to logical cohesion:
1918- ` backend/routes/playground.py `
2019- ` backend/services/dna_extractor.py `
21- - ` frontend/src/components/DependencyGraph/index.tsx `
20+ - ` backend/services/dependency_analyzer.py `
21+ - ` frontend/src/components/DependencyGraph/GraphView/index.tsx `
22+ - ` frontend/src/components/DependencyGraph/MatrixView/index.tsx `
2223
2324### Frontend (TypeScript/React)
2425- Package manager: ** Bun only** . Never npm, never yarn.
@@ -27,42 +28,108 @@ These files exceed 200 lines but are approved due to logical cohesion:
2728- Use shadcn/ui components over custom UI
2829- Tailwind for styling, no CSS files
2930- Functional components with hooks, no class components
31+ (ErrorBoundary is the only exception -- React requires class for error boundaries)
32+ - Use React Query (` useQuery ` ) for all server data fetching, never raw fetch in useEffect
33+ - Custom hooks go in ` frontend/src/hooks/ ` with ` use ` prefix
34+ - Shared types go in ` frontend/src/types.ts `
35+ - Keep components focused -- one concern per file
36+
37+ ### React Patterns
38+ - Derive state during render when possible, don't sync with useEffect
39+ - Define components at module scope, never inside other components (causes remounts)
40+ - Use stable keys (item.id), not array indices, for lists that change
41+ - Colocate state with the component that uses it, lift only when needed
42+ - Use ` cn() ` from ` @/lib/utils ` for conditional class merging
43+
44+ ### Testing
45+ - Vitest + happy-dom for unit/component tests
46+ - Tests live in ` frontend/src/test/ ` using ` @/ ` alias imports
47+ - Run with ` bun run test ` , runs in CI on every PR
48+ - Test file naming: ` ComponentName.test.tsx ` or ` hookName.test.ts `
49+ - Smoke tests for critical paths: does it render, does the hook return correct data
50+ - Backend tests: pytest in ` backend/tests/ ` , run with ` cd backend && pytest tests/ -v `
3051
3152### Backend (Python)
3253- Python 3.11+ required
3354- Type hints on all function signatures
3455- Async/await for I/O operations
3556- PEP 8 style, max 120 char lines
3657- Use existing patterns from ` services/ ` directory
58+ - All new services should follow the singleton pattern used in ` dependency_analyzer.py `
59+ - Startup validation in ` config/startup_checks.py ` -- add new required/optional env vars there
3760
3861### Commits
3962- Format: ` type: description ` (e.g., ` fix: remove broken link ` )
4063- Types: feat, fix, docs, refactor, test, chore
4164- No emojis in commit messages
42- - Keep commits focused - one change per commit
65+ - Keep commits focused -- one change per commit
66+ - PR scope: one concern per PR. Don't mix bug fixes with features.
67+
68+ ### Code Review
69+ - All PRs go through CodeRabbit automated review
70+ - Fix real findings (bugs, type safety, missing deps). Skip nitpicks unless trivial.
71+ - PRs target ` OpenCodeIntel/opencodeintel:main ` from your fork
4372
4473## Architecture
4574
4675### Project Structure
47- ``` plaintext
48- backend/ # FastAPI, Python 3.11+
49- frontend/ # React 18, TypeScript, Vite, Bun
50- mcp-server/ # MCP protocol server
76+ ``` text
77+ backend/ # FastAPI, Python 3.11+
78+ config/ # API config, startup checks
79+ middleware/ # Auth, rate limiting
80+ routes/ # API endpoints (all use /api/v1/ prefix)
81+ services/ # Business logic (singleton services)
82+ tests/ # pytest test files
83+ frontend/ # React 18, TypeScript, Vite, Bun
84+ src/
85+ components/ # UI components (one concern per file)
86+ dashboard/ # Sidebar, TopNav, DashboardHome, RepoListView, RepoDetailView
87+ DependencyGraph/ # GraphView (Sigma.js), MatrixView (DSM), ImpactPanel
88+ ui/ # shadcn/ui primitives
89+ landing/ # Marketing pages
90+ docs/ # Documentation components
91+ hooks/ # Custom React hooks (useCachedQuery, useRepos, etc.)
92+ contexts/ # React contexts (AuthContext)
93+ config/ # API URL config, demo repos
94+ pages/ # Route-level page components
95+ test/ # Vitest test files
96+ types.ts # Shared TypeScript interfaces
97+ mcp-server/ # MCP protocol server for Claude/Cursor
5198```
5299
53100### API Versioning
54101- All endpoints use ` /api/v1/ ` prefix
55102- Version config in ` backend/config/api.py `
56103
104+ ### Data Flow
105+ - Frontend fetches via React Query hooks in ` hooks/useCachedQuery.ts `
106+ - Dual-layer caching: React Query (memory) + localStorage (persistence)
107+ - Backend caches dependency graphs and DNA in Supabase
108+ - Real-time indexing progress via WebSocket
109+
57110### Key Services
58- - ` indexer_optimized.py ` - Code parsing and embedding
59- - ` dependency_analyzer.py ` - Import graph extraction
60- - ` style_analyzer.py ` - Convention detection
61- - ` dna_extractor.py ` - Architectural pattern extraction
111+ - ` indexer_optimized.py ` -- Code parsing and embedding (tree-sitter + OpenAI/Voyage)
112+ - ` dependency_analyzer.py ` -- Import graph extraction (tree-sitter AST)
113+ - ` style_analyzer.py ` -- Convention detection
114+ - ` dna_extractor.py ` -- Architectural pattern extraction + team rules detection
115+ - ` supabase_service.py ` -- Database operations (uses service role key)
116+ - ` auth.py ` -- JWT verification (uses anon key + JWT secret)
117+
118+ ### Environment Variables
119+ - Root ` .env.example ` is the source of truth for all env vars
120+ - Docker passes vars via ` docker-compose.yml ` environment block
121+ - Frontend vars must be prefixed with ` VITE_ `
122+ - New required vars: add to ` config/startup_checks.py ` REQUIRED_VARS
123+ - New optional vars: add to ` config/startup_checks.py ` OPTIONAL_VARS
62124
63125## What NOT to Do
64126
65- - Don't use npm (use Bun)
127+ - Don't use npm or yarn (use Bun)
66128- Don't add emojis
67129- Don't write verbose comments
68130- Don't add "AI-looking" badges or decorations
131+ - Don't define components inside other components
132+ - Don't use raw fetch in useEffect (use React Query)
133+ - Don't put inline types when a shared interface exists in types.ts
134+ - Don't create PRs with multiple unrelated concerns
135+ - Don't merge PRs without CI passing
0 commit comments