FastAPI backend for AI chat with MCP tool orchestration.
- Choose the approach that produces the cleanest, simplest, most maintainable result.
- If a rewrite is clearly better than patching, rewrite.
- Avoid layered fixes that preserve messy structure.
When changing or replacing behavior:
- Do not leave old code behind (no commented-out code, unused modules, dead branches).
- Remove obsolete files, configs, scripts, routes, flags, and assets.
- Repo-wide sweep for old names, config keys, dead references in docs/tests, unused imports.
- Prefer deletion over preservation when something is no longer needed.
- Avoid parallel implementations of the same concept.
- Update tests to reflect new design; remove tests for removed behavior.
- Keep docs short and correct. One source of truth per topic — don't duplicate.
- Update docs every time behavior changes. All substantial docs live under
docs/.
- Never commit secrets, credentials, tokens, real
.env, private keys, local DBs, logs. - If uncertain whether a file is safe to commit: assume it is not.
src/backend/— FastAPI application sourcefrontend/— Main web UI (Svelte 5)frontend-kiosk/— Kiosk display interfacefrontend-voice/— Voice interaction PWAfrontend-cli/— Terminal chat client (Python)data/— Runtime mutable data (preferences, DBs, tokens, uploads) — never in gitsrc/backend/data/clients/— Bundled default settings (read-only fallback)docs/— Documentation (source of truth)scripts/— Automation / deployment toolingtests/— Test suite
- Use
./scripts/deploy.sh "commit message"for all frontend changes — cleans, builds, verifies, commits, pushes, deploys - Backend Python changes auto-reload — just
git pushthen pull on server - Server is LXC 111 at
192.168.1.111— no direct SSH; access via Proxmox host (192.168.1.11) usingpct exec 111 - Service user
backend, public URLhttps://chat.jackshome.com - See
docs/PROXMOX_DEPLOYMENT.mdfor manual deployment steps and access patterns
The backend service runs as User=backend. After any git pull or git reset --hard on the server, files created by git operations will be owned by root. The runtime data/ directory must remain writable by the service user.
Every deployment must include:
chown -R backend:backend /opt/backend-fastapi/data/The deploy script handles this automatically. If deploying manually, always run the chown. Symptoms of ownership problems: 500 errors on PUT/POST endpoints that write to data/, PermissionError in server logs.
- MCP tools are external (LXC 110, ports 9001–9015) — never embed tool logic in backend
ChatOrchestratorcoordinates streaming, tools, persistenceStreamingHandlermanages SSE events and tool execution loops- Frontends build to
src/backend/static/— server does NOT build them - Runtime data lives in
data/at project root (notsrc/backend/data/)
- Python ≥3.11 with
from __future__ import annotations - Use async for all I/O with explicit timeouts
- Type hints on all signatures; Pydantic for schemas
- Ruff for formatting, linting, import sorting
- Frontend: Svelte 5 — use modern syntax (
onclick,onchange, not legacyon:click) - Prefer clarity over cleverness; avoid unnecessary abstractions
- Never commit
.env,credentials/,certs/, ordata/tokens/ - Server-only files that differ from local:
data/mcp_servers.json,.env - Check
.env.examplefor required environment variables
- Old code removed (no dead paths, no duplicate implementations)
- Repo-wide search for leftovers (names, config keys, references)
- Tests updated and irrelevant tests removed
- Docs updated in
docs/(concise, non-duplicative) -
.gitignoreupdated for any new sensitive/local artifacts
docs/PROXMOX_DEPLOYMENT.md— Server setup, deploy workflows, troubleshootingdocs/AI_PLAYBOOK.md— Detailed coding guidelines for AI assistantsdocs/DEVELOPMENT_ENVIRONMENT.md— Local dev setup