|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## What This Is |
| 6 | + |
| 7 | +BetterCodeWiki auto-generates interactive wikis for GitHub/GitLab/Bitbucket repos. It's a fork of DeepWiki-Open with an overhauled UI, 3D landing page, enhanced diagrams, MCP server, and multi-provider AI support. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +### Frontend (Next.js 15 + React 19) |
| 12 | +```bash |
| 13 | +yarn install # install deps (yarn 1.x — enforced via packageManager) |
| 14 | +yarn dev # dev server on :3000 (turbopack) |
| 15 | +yarn build # production build |
| 16 | +yarn lint # eslint (next/core-web-vitals + next/typescript) |
| 17 | +``` |
| 18 | + |
| 19 | +### Backend (Python — FastAPI) |
| 20 | +```bash |
| 21 | +python -m pip install poetry==2.0.1 && poetry install -C api |
| 22 | +python -m api.main # API server on :8001 |
| 23 | +``` |
| 24 | + |
| 25 | +### Tests (pytest) |
| 26 | +```bash |
| 27 | +pytest test/ # all tests (testpaths = test/) |
| 28 | +pytest test/test_extract_repo_name.py # single test file |
| 29 | +pytest -m unit # by marker: unit, integration, slow, network |
| 30 | +``` |
| 31 | +There's also a `tests/` directory with api/unit/integration subdirs — these are run via `python tests/run_tests.py` or by pointing pytest at them directly. |
| 32 | + |
| 33 | +### Docker |
| 34 | +```bash |
| 35 | +docker-compose up # runs everything (frontend :3000, API :8001, MCP :8008) |
| 36 | +``` |
| 37 | + |
| 38 | +### MCP Server (standalone) |
| 39 | +```bash |
| 40 | +python api/mcp/server.py # stdio mode (Claude Desktop/Code) |
| 41 | +python api/mcp/server.py --http # HTTP mode on :8008 |
| 42 | +mcp dev api/mcp/server.py # browser-based inspector |
| 43 | +``` |
| 44 | + |
| 45 | +## Architecture |
| 46 | + |
| 47 | +### Two-process system |
| 48 | +- **Frontend**: Next.js app in `src/`. Proxies API calls to the backend via `next.config.ts` rewrites (routes like `/api/wiki_cache/*`, `/export/wiki/*`, `/api/auth/*`). |
| 49 | +- **Backend**: FastAPI app in `api/api.py`, entry point `api/main.py`. Handles repo cloning, embedding, wiki generation, RAG chat, and export. |
| 50 | + |
| 51 | +### Wiki generation flow |
| 52 | +1. User submits a repo URL on the landing page (`src/app/page.tsx`) |
| 53 | +2. Frontend navigates to `src/app/[owner]/[repo]/page.tsx` — the main wiki viewer |
| 54 | +3. Backend clones the repo, creates embeddings via adalflow + FAISS, generates wiki pages using the configured AI provider |
| 55 | +4. Wiki data is cached in `~/.adalflow/wikicache/` and served back as JSON |
| 56 | + |
| 57 | +### Real-time communication |
| 58 | +- **WebSocket** (`/ws/chat`): Used for Ask/chat and DeepResearch features. Client in `src/utils/websocketClient.ts`, server handler in `api/websocket_wiki.py`. |
| 59 | +- Wiki generation itself streams via the same WebSocket infrastructure. |
| 60 | + |
| 61 | +### AI provider abstraction |
| 62 | +The backend supports multiple providers through client wrappers in `api/`: |
| 63 | +- `api/config.py` — loads API keys from env, reads JSON configs from `api/config/` |
| 64 | +- Each provider has its own client: `openai_client.py`, `openrouter_client.py`, `azureai_client.py`, `bedrock_client.py`, `dashscope_client.py` |
| 65 | +- Google Gemini uses adalflow's `GoogleGenAIClient` directly |
| 66 | +- Ollama uses adalflow's `OllamaClient` with patches in `ollama_patch.py` |
| 67 | +- Embeddings: configurable via `DEEPWIKI_EMBEDDER_TYPE` env var; implementation in `api/tools/embedder.py` |
| 68 | + |
| 69 | +### RAG pipeline |
| 70 | +`api/rag.py` implements retrieval-augmented generation using adalflow. Prompts live in `api/prompts.py`. The data pipeline (`api/data_pipeline.py`) handles repo file processing and token counting. |
| 71 | + |
| 72 | +### Frontend routing |
| 73 | +- `/` — Landing page with 3D hero (Three.js via `@react-three/fiber`, dynamically imported to avoid SSR) |
| 74 | +- `/[owner]/[repo]` — Wiki viewer (main app surface) |
| 75 | +- `/[owner]/[repo]/slides` — Presentation mode |
| 76 | +- `/[owner]/[repo]/workshop` — Workshop mode |
| 77 | +- `/wiki/projects` — Cached project browser |
| 78 | + |
| 79 | +### Key frontend patterns |
| 80 | +- **Theming**: `next-themes` with `darkMode: 'selector'` in Tailwind. Theme toggle in `src/components/theme-toggle.tsx`. |
| 81 | +- **i18n**: `src/contexts/LanguageContext.tsx` wraps the app. Translations in `src/messages/{locale}.json` (en, ja, zh, es, kr, vi, pt-br, ru, fr, zh-tw). Manual `t()` function in page components, not next-intl's `useTranslations`. |
| 82 | +- **Animations**: GSAP + Framer Motion. GSAP registered in `src/lib/gsap.ts`. Smooth scroll via Lenis (`src/lib/smooth-scroll.ts`). |
| 83 | +- **Mermaid diagrams**: Custom renderer in `src/components/Mermaid.tsx` with fullscreen expand, SVG pan-zoom, and theme-aware styling. |
| 84 | +- **Path alias**: `@/*` maps to `./src/*` |
| 85 | + |
| 86 | +### MCP server |
| 87 | +`api/mcp/server.py` is fully standalone — no imports from the main codebase. Reads cached wikis from `~/.adalflow/wikicache/`. Provides 5 tools: `list_projects`, `get_wiki_overview`, `get_wiki_page`, `search_wiki`, `ask_codebase`. |
| 88 | + |
| 89 | +## Environment |
| 90 | + |
| 91 | +Required env vars depend on which AI provider you use. At minimum set `GOOGLE_API_KEY` or `OPENAI_API_KEY` in `.env` at project root. See README for the full table. The backend defaults to `http://localhost:8001`; override with `SERVER_BASE_URL`. |
0 commit comments