|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +### Setup |
| 8 | +```bash |
| 9 | +./setup.sh # Bootstrap: creates .venv, installs deps, installs Playwright |
| 10 | +source .venv/bin/activate |
| 11 | +``` |
| 12 | + |
| 13 | +### Run (Development) |
| 14 | +```bash |
| 15 | +./start-dev.sh # Starts backend (port 5001) + frontend (port 3001) together |
| 16 | + |
| 17 | +# Or manually: |
| 18 | +# Terminal 1 - Backend: |
| 19 | +source .venv/bin/activate && cd backend && python app.py |
| 20 | + |
| 21 | +# Terminal 2 - Frontend: |
| 22 | +cd frontend && npm run dev |
| 23 | +``` |
| 24 | + |
| 25 | +### Run (Production / Docker) |
| 26 | +```bash |
| 27 | +docker build -t quart-react-demo . |
| 28 | +docker run -p 5001:5001 quart-react-demo |
| 29 | +# Quart serves both API + built frontend on port 5001 |
| 30 | +``` |
| 31 | + |
| 32 | +### Tests |
| 33 | +```bash |
| 34 | +# E2E tests (Playwright - requires both servers running or auto-started) |
| 35 | +npm run test:e2e # Run all E2E tests (chromium, firefox, webkit) |
| 36 | +npm run test:e2e:ui # Interactive UI mode |
| 37 | +npm run test:e2e:report # View last HTML report |
| 38 | +npx playwright test tests/e2e/workbench.spec.js --project=chromium # Single file + browser |
| 39 | + |
| 40 | +# Backend unit tests (pytest) |
| 41 | +cd backend |
| 42 | +pytest # All backend tests |
| 43 | +pytest agent_builder/tests/ # 132 agent framework tests |
| 44 | +pytest test_agents.py -v # Single file, verbose |
| 45 | +``` |
| 46 | + |
| 47 | +### Frontend Build |
| 48 | +```bash |
| 49 | +cd frontend && npm install && npm run build # Outputs to frontend/dist/ |
| 50 | +``` |
| 51 | + |
| 52 | +## Architecture |
| 53 | + |
| 54 | +### Overview |
| 55 | +Full-stack teaching app: **Quart** (async Python ASGI, port 5001) + **React/Vite** (port 3001 in dev). In development, Vite proxies `/api/*` to the Quart backend. In production, Quart serves the built frontend statically. |
| 56 | + |
| 57 | +### Backend (`backend/`) |
| 58 | + |
| 59 | +**Key pattern — Unified Operation System** (`api_decorators.py`): |
| 60 | +```python |
| 61 | +@operation("create_task", "Create a task", http_method="POST", mcp_enabled=True) |
| 62 | +def op_create_task(data: TaskCreate) -> Task: |
| 63 | + return TaskService.create_task(data) |
| 64 | +``` |
| 65 | +The `@operation` decorator auto-generates: REST endpoint, MCP JSON-RPC method, JSON schema, and LangChain `StructuredTool`. Define once, used everywhere. Operations are registered in `operations.py`. |
| 66 | + |
| 67 | +**Deep module pattern**: Business logic consolidated into service classes (`TaskService`, `WorkbenchService`, `CSVTicketService`, `KBAService`) rather than scattered thin functions. |
| 68 | + |
| 69 | +**Key files:** |
| 70 | +- `app.py` — Quart app, route/blueprint registration, SSE streams, LLM config |
| 71 | +- `api_decorators.py` — `@operation` decorator implementation |
| 72 | +- `operations.py` — All operation definitions |
| 73 | +- `tasks.py` — SQLModel task models + `TaskService` (SQLite via `data/tasks.db`) |
| 74 | +- `csv_data.py` — `CSVTicketService`: loads CSV (`CSV/data.csv`), date parsing (German format `DD.MM.YYYY HH:MM:SS`), filtering, pagination |
| 75 | +- `tickets.py` — Pydantic ticket models + enums (Status, Priority, Urgency, Impact) |
| 76 | +- `agent_builder/` — Full agent lifecycle: `service.py` (WorkbenchService), `engine/` (ReAct loop), `persistence/` (SQLite repos), `tools/` (ToolRegistry, MCP adapters), `routes.py` (Blueprint at `/api/workbench/*`) |
| 77 | +- `kba_service.py` — Knowledge Base Article generation pipeline |
| 78 | + |
| 79 | +**LLM config**: LiteLLM is default (works with GitHub Copilot, no key needed); OpenAI is optional override. Config via `.env`. |
| 80 | + |
| 81 | +**MCP**: Backend exposes both REST and MCP JSON-RPC from the same `@operation` handlers. `mcp_handler.py` routes JSON-RPC to operations. |
| 82 | + |
| 83 | +### Frontend (`frontend/src/`) |
| 84 | + |
| 85 | +**Feature-first structure**: `features/<name>/` contains page component, subcomponents, utils, and local state. All backend calls go through `services/api.js`. |
| 86 | + |
| 87 | +**Key features:** |
| 88 | +- `workbench/` — Agent Fabric: create/run/inspect ReAct agents with live schema editor |
| 89 | +- `csvtickets/` — Browse/filter/sort/paginate the CSV ticket dataset |
| 90 | +- `tickets/` — Nivo chart visualizations (bar, sankey, stream) |
| 91 | +- `usecase-demo/` — Pre-built demo agent runs with custom result renderers |
| 92 | +- `kba-drafter/` — KBA generation UI (draft list, editor, audit trail) |
| 93 | +- `dashboard/` — Real-time updates via Server-Sent Events (`/api/time-stream`) |
| 94 | +- `agent/` — One-shot agent chat interface |
| 95 | + |
| 96 | +**UI**: FluentUI v9 (`@fluentui/react-components`) throughout. Charts via `@nivo/*`. |
| 97 | + |
| 98 | +### Testing |
| 99 | + |
| 100 | +E2E tests (`tests/e2e/`) use Playwright. `playwright.config.js` auto-starts backend + frontend via `webServer`. Tests use `data-testid` attributes. Three browser projects: chromium, firefox, webkit. |
| 101 | + |
| 102 | +Backend tests use pytest. `agent_builder/tests/` has 132 tests covering the agent framework. |
| 103 | + |
| 104 | +## Environment |
| 105 | + |
| 106 | +Copy `.env.example` to `.env`. Key variables: |
| 107 | +``` |
| 108 | +# LiteLLM (default — no key required if using GitHub Copilot) |
| 109 | +LITELLM_MODEL=github_copilot/gpt-4o |
| 110 | +
|
| 111 | +# OpenAI (optional override) |
| 112 | +OPENAI_API_KEY=sk-proj-... |
| 113 | +OPENAI_MODEL=gpt-4o-mini |
| 114 | +
|
| 115 | +# KBA publishing path |
| 116 | +KB_FILE_BASE_PATH=./kb_published |
| 117 | +``` |
| 118 | + |
| 119 | +## Ports |
| 120 | +- Backend (Quart): `http://localhost:5001` |
| 121 | +- Frontend dev (Vite): `http://localhost:3001` |
| 122 | +- In production: single port `5001` (Quart serves everything) |
| 123 | + |
| 124 | +## Docs |
| 125 | +- `docs/QUICKSTART.md` — 5-minute setup |
| 126 | +- `docs/AGENT_BUILDER.md` — Agent framework architecture with diagrams |
| 127 | +- `docs/UNIFIED_ARCHITECTURE.md` — REST + MCP integration patterns |
| 128 | +- `docs/LEARNING.md` — Design principles (Grokking Simplicity, deep modules) |
| 129 | +- `docs/TROUBLESHOOTING.md` — Common issues |
0 commit comments