Start here if you are a coding agent working in the
BrainDrivecode repository.
Repo: ~/BrainDrive/
This is the main BrainDrive product implementation repo.
BrainDrive is a user-owned AI system built on the Personal AI Architecture (PAA). This repo contains the running product: gateway, agent loop, auth, memory, web client, MCP tool services, and Docker installer/deployment assets.
This file is the public codebase boot document. It is meant to be sufficient for an agent working only from this repository.
Use this file for codebase orientation. Use README.md, ROADMAP.md, and CONTRIBUTING.md for public product and contribution context.
Do not assume access to any private BrainDrive planning repository, maintainer notes, or internal task tracker.
Read these first:
README.mdCONTRIBUTING.mdROADMAP.mdbuilds/typescript/package.json- The subsystem you are touching
Typical implementation entrypoints:
builds/typescript/gateway/server.ts— main HTTP API and app wiringbuilds/typescript/engine/loop.ts— agent loop and streaming/tool-call flowbuilds/typescript/tools.ts— built-in tool discovery and MCP registrationbuilds/typescript/client_web/src/App.tsx— React app rootbuilds/typescript/client_web/src/components/chat/ChatPanel.tsx— chat UI wiringbuilds/typescript/client_web/src/components/settings/SettingsModal.tsx— settings flowsinstaller/docker/README.md— Docker modes and lifecycle scripts
Top-level directories:
builds/typescript/— main app runtime: gateway, engine, auth, memory, web clientbuilds/mcp_release/— first-party MCP servers used by the runtimeinstaller/docker/— Docker compose, images, lifecycle scripts, deployment wiringdocs/— user and operator documentationclient/— legacy or auxiliary client assets at repo root level; most active UI work is underbuilds/typescript/client_web/
Within builds/typescript/:
gateway/— Fastify server routes and API behaviorengine/— model loop, streaming, approvals, tool executionauth/— local JWT auth, authorization, bootstrap/signup logicmemory/— file-backed memory, export/import/backup/historymemory-tools/— file operation toolsmcp/— MCP server config and registrationsecrets/— vault/master-key handlingclient_web/— React + Vite frontendyour-memory/— local development memory fixture/state
When starting work:
- Read the relevant public docs and the subsystem you are about to change.
- Confirm whether the task is backend, frontend, installer, memory, or MCP-related.
- Prefer existing patterns in the touched subsystem over introducing a new abstraction.
- Run the smallest relevant test set before and after substantial changes.
When making decisions:
- Prefer repo-local evidence over assumptions from older conversations or external summaries.
- Treat
README.md,ROADMAP.md, and the code itself as the source of truth available to public contributors. - If a task appears to depend on private business context, stop treating that context as required and solve from the public repo surface instead.
Keep this mental model:
- The gateway receives UI/client requests and loads runtime/config/auth state.
- The engine runs the model loop, streams assistant text, and executes tool calls.
- Tools operate against file-backed memory and other registered MCP sources.
- The web client talks to the gateway over the local API surface.
- Docker packages the app for local, dev, and prod modes.
Important behavior boundaries:
- BrainDrive supports both
localandmanageddeployment modes. - The UI changes behavior by mode, especially auth, settings, and model/provider flows.
- Memory is file-backed and git-aware. Avoid casual changes to path resolution, backup, restore, import/export, or history semantics.
- Memory template changes are paired work. When changing files in the local test memory fixture (
builds/typescript/your-memory/), make the corresponding starter-pack change underbuilds/typescript/memory/starter-pack/so new users receive the same baseline. When starter-pack defaults change, also account for existing users through the memory update/migration flow, preserving customized owner files and avoiding overwrites unless explicitly approved. - Secrets are handled separately from memory backup/restore.
Common commands:
cd builds/typescript
npm test
npm run dev # MCP sidecars + gateway + web
npm run dev:server # MCP sidecars + gateway onlyWeb client:
cd builds/typescript/client_web
npm test
npm run typecheck
npm run devMCP release package:
cd builds/mcp_release
npm testDocker dev mode:
./scripts/start.sh devFor broader installer and deployment flows, use:
installer/docker/README.md
- Read the local code before assuming the architecture from older docs.
- Prefer narrow, subsystem-local changes over broad cross-cutting edits unless the task requires them.
- Check for deployment-mode effects when changing auth, settings, onboarding, or model configuration.
- Check for backup/restore and migration implications when changing memory or secrets behavior.
- Keep public repo documentation self-contained.
Before finishing a change, run the most relevant tests for the touched area. Minimum common paths:
cd builds/typescript && npm testcd builds/mcp_release && npm testcd builds/typescript/client_web && npm test
If the task is about:
- Chat/runtime behavior:
builds/typescript/engine/andbuilds/typescript/gateway/ - Auth/account flows:
builds/typescript/auth/and auth routes ingateway/server.ts - Memory/files/export/backup:
builds/typescript/memory/,memory-tools/, andgit.ts - Frontend behavior:
builds/typescript/client_web/src/ - Installer/deployment:
installer/docker/ - Tool registration or MCP behavior:
builds/typescript/tools.ts,builds/typescript/mcp/,builds/mcp_release/
README.md— external-facing repo overviewCONTRIBUTING.md— contributor workflow and baseline test commandsROADMAP.md— public roadmapinstaller/docker/README.md— deployment and lifecycle modesbuilds/typescript/client_web/README.md— web client detailsbuilds/mcp_release/README.md— first-party MCP server package
If this file drifts from the real code, update it.