System Architecture & Design
2Brain System Architecture
Core Architectural Invariants
- Perpetual Longevity: Plaintext Git Markdown catalogs and standard SQLite storage.
- Device-Agnostic Access: Accessible globally behind Cloudflare Zero Trust (SSO + hardware 2FA).
- Zero-Knowledge Security: Browser Web Crypto
AES-256-GCMwith PBKDF2 key derivation (100,000 iterations); edge and database store only ciphertext payloads. - Agent-First Operability: Standard Model Context Protocol (MCP) server for autonomous AI coding agents (Antigravity, Cursor, Claude Code).
- Zero Infrastructure Cost: Designed to run indefinitely on Cloudflare Pages, D1, Vectorize, Workers AI, AI Gateway, and R2 free tiers.
Architectural Decision Records (ADRs)
- ADR-01: Git-Backed Plaintext Source of Truth: Plaintext Markdown with YAML frontmatter in
/projects/. - ADR-02: Cloudflare Pages + Zero Trust Identity: Worldwide CDN edge delivery locked behind Google/GitHub OAuth with mandatory 2FA.
- ADR-03: Client-Side Zero-Knowledge Encrypted Secret Vault: Web Crypto AES-256-GCM + PBKDF2 in Cloudflare D1.
- ADR-04: Static Knowledge Graph via Graphify: Build-time graph compilation into static
graph.jsonand interactivegraph.html. - ADR-05: Hybrid Retrieval Engine: Tri-layer retrieval via Pagefind, SQLite FTS5, and Cloudflare Vectorize.
- ADR-06: Cloudflare AI Gateway with Multi-Tier Fallback: Primary Google Gemini Flash with Cloudflare Workers AI fallback.
- ADR-07: Model Context Protocol (MCP) Edge Server: Native JSON-RPC endpoint for AI coding agents.