Cairnmind
Getting Started 5 min read Source: docs/ARCHITECTURE.md ↗

How Cairnmind Is Built

System architecture: ArcadeDB storage, Hybrid RAG + GraphRAG, Tree-sitter + SCIP code graph, local models, and repository layout.

How it works

Interfaces:
  - POSIX tmux + Textual workspace / native Windows standalone Textual workspace (PAL)
  - Loopback-only React Web Cockpit (`cairnmind ui`, bundled in wheels, per-launch session + CSRF auth)
  - CLI (`cairnmind ...`) and MCP stdio server (`cairnmind mcp`)
                           │
                           ▼
             Codex CLI / Claude Code / API agent / Copilot SDK / external MCP clients
                           │ MCP: resume / ACK / ask / plans / checkpoints
                           ▼
                 Local Cairnmind service (FastAPI)
                  │                                   │
       knowledge agent (Ollama / HTTPS, optional)  independent archiving,
       + quote healing                            pulse, serverless scan
                  │                                   │
          Hybrid RAG + GraphRAG ◄─────────────────────┘
                  │
       Sealed StorageBackend DAL (no raw SQL outside storage/)
         ├── ArcadeDB (native Java 21, Docker, remote HTTPS / Kubernetes)
         └── Embedded SQLite (WAL + FTS5 + cosine / optional sqlite-vec)
  • Storage: configurable dual-backend storage behind a sealed StorageBackend data-access layer (src/cairnmind/storage/). Users choose per installation via storage_backend (arcade or sqlite):
    • ArcadeDB (ArcadeDB): pinned single engine holding documents, the code dependency graph, full-text and HNSW vector indexes; run natively with Java 21, in a managed Docker container (INSTALL.md), or connect-only on a remote server or Kubernetes (connect-only installations).
    • Embedded SQLite (--backend sqlite, cairnmind try): zero-service local store (state.db) using SQLite WAL mode, FTS5 full-text search, temporary-table bound queries (safe beyond SQLITE_MAX_VARIABLE_NUMBER), and C-accelerated cosine search (plus optional cairnmind[vec] / sqlite-vec). Migrate losslessly to ArcadeDB at any time with cairnmind migrate --to server.
  • Platform Abstraction Layer (pal/): isolates OS-specific file locking (flock / LockFileEx), private file permissions (0600/0700 / NTFS Protected DACLs), process tree control (killpg / Win32 Job Objects), case-insensitive path identity, and person-proof IPC (POSIX tmux server key / owner-only Windows Named Pipe) so Cairnmind runs natively on Linux, macOS, and Windows 10/11 without WSL2.
  • Retrieval & verification: full-text search, vector similarity and graph traversal, fused and re-checked verbatim against current source content (quote_healing tracks harmless formatting shifts without altering confirmed statuses). cairnmind pulse runs a read-only consistency micro-audit (< 500 ms) and cairnmind scan --diff checks symbol-anchored drift serverlessly in CI.
  • Knowledge agent: qwen3.5:9b through Ollama with a 16k-token working context, and qwen3-embedding:0.6b embeddings, by default. cairnmind models set can put either role on another Ollama or a server with the OpenAI-compatible API; a server on another computer needs HTTPS and your explicit consent, and receives only the sensitivity classes you allow (API.md). Both models are optional: without them Cairnmind works in deterministic-only mode (INSTALL.md). Coding assistants are chosen independently.
  • Code graph: tree-sitter analysis of Python, JavaScript and TypeScript, plus multi-language SCIP indexing for Go, Rust, Java, Kotlin, C, C++, C#, PHP and Ruby (scip-go, rust-analyzer, scip-java, scip-clang, scip-dotnet, scip-php, scip-ruby). SCIP indexers run on request (cairnmind scip index), or in a dedicated background worker only for a project a person turned on with cairnmind scip enable (never by default; scip_mode "off" stops even those), write into the configured storage backend's code graph (defines, imports, calls, references, test_imports, external_module), and are also importable offline via cairnmind scip import. Other languages remain searchable as text.
  • Local Web Cockpit (cairnmind ui): loopback-only React + TypeScript inspector bundled into release wheels under cairnmind/ui_dist/ (no Node.js required for end users). Standalone launches print a one-time bootstrap ticket (valid two minutes, never logged), which issues an HttpOnly; SameSite=Strict session cookie plus per-session CSRF token (X-Cairnmind-UI-Token), enforce strict Host/Origin/Sec-Fetch-Site checks, and never confirm, supersede or rewrite what a person decided (the cockpit stores only proposals through the Store; review is made in the workspace); mounted inside the main service, /api/ui/* is strictly read-only.
  • Memory & plans: versioned records, symbol-anchored AST fingerprints (syntax-v4), independent source snapshots (including uncommitted code), one shared inference queue prioritizing live questions, and atomic plans with deterministic next steps per project and worktree.

The way memory and agents are organized is inspired by SynapCores. Cairnmind is an independent implementation of the knowledge layer; it is not a copy of that product or of its database engine.

Built with

Cairnmind stands on other people's work. In one place:

The coding assistants it works with, Codex CLI and Claude Code among them, are not part of Cairnmind; it starts them and keeps their project memory.

Repository layout

Path Contents
src/cairnmind/ The Python package: 6 top-level facades (__init__, __main__, config, cli, store, service) over 9 domain subpackages (pal/, storage/, ui/, cli_cmds/, terminal/, mcp/, memory/, agents/, scip/) with acyclic imports enforced by tests/test_import_graph.py.
ui/ React + TypeScript + Vite frontend for cairnmind ui, tested with Vitest and bundled into cairnmind/ui_dist/ when building release wheels (CAIRNMIND_BUILD_UI=1).
tests/ Automated tests and architectural guards (DAL isolation, import graph, Windows/UTF-8, HTTPX TLS, contract fixtures); see CONTRIBUTING.md for the tiers and a code map.
docs/ Guides and implementation contracts.
scripts/ Installers (install-wsl.sh, install-windows.ps1) and release/contract helpers.
deploy/ The database image, a Compose file and Kubernetes manifests (docs/DEPLOYMENT.md).
pilot/ Material for a hand-off pilot between coding assistants.

Development

# .python-version pins Python 3.12, the version the lock file and CI cover
uv sync --locked --extra dev
uv run ruff check src tests scripts hatch_build.py
uv run pyright
uv run pytest -m "not arcade and not tmux"   # fast tier, no database or tmux
uv run pytest                                # full suite, needs Java 21 and tmux
uv run pytest -n 4                           # the full suite in 4 parallel processes

# Frontend (`ui/`)
cd ui && npm ci && npm run typecheck && npm test && npm run build

The automated tests need no Ollama, no models and no signed-in coding clients; those are used only by the explicit evaluations. Test modules that need the real ArcadeDB engine are marked arcade, and those that drive a real tmux server are marked tmux. CI runs Ruff + Pyright lint, frontend typecheck/Vitest/wheel ui_dist checks, the fast tier on Linux, macOS and Windows, and the full ArcadeDB suite on every pull request and push to main.