Interactive demo — every person, company, and deal is fictional. Changes you make are real but reset periodically.AboutREADMEArchitecture
Siryous CRM
← About

Siryous CRM — Architecture

This document describes the architecture of the production system, then notes what the public demo substitutes. Names, data, and examples here are fictional.

Design goals

  1. Local-first, single source of truth. One SQLite file on one machine. No cloud service, no accounts, no sync protocol — and therefore no staleness: every client reads and writes the same rows.
  2. AI drafts, human confirms. Model output never mutates the database directly. Every AI feature terminates in a review screen; the confirm action is an ordinary form post handled by an ordinary server action.
  3. Private by default, least privilege when not. Drafting runs on a local model, so contacts and notes stay on the machine. When the outside world is needed, Claude runs with the minimum read-only tool grant for that one step — and private mail and the open web never share a run.
  4. Boring web tech. Server components render from the database on every request; forms are plain HTML posting to server actions. No client state libraries, no ORM, no API layer between the UI and the data.

System overview

┌─────────────┐   ┌────────────────────┐   ┌────────────────┐
│   Web app   │   │   Claude Desktop   │   │  Claude Code   │
│  (Next.js)  │   │  via MCP server    │   │  sessions in   │
│  127.0.0.1  │   │  (CRM tools)       │   │  the repo      │
└──────┬──────┘   └─────────┬──────────┘   └───────┬────────┘
       │                    │                      │
       ▼                    ▼                      ▼
              ┌───────────────────────────┐
              │    data/crm.db (SQLite)   │
              │  WAL mode · single writer │
              │      source of truth      │
              └───────────────────────────┘
                     ▲
       ┌─────────────┴───────────────────────────────────────┐
       │  Built-in AI features (web app)                     │
       │  write: local model via Ollama (Claude optional)    │
       │  fetch: claude -p, streamed, read-only tool grants  │
       │  ◎ Coach   → no tools (CRM data only)               │
       │  ✨ Intake  → web search/fetch (optional)            │
       │  ✎ Log     → Zoom read OR Drive read (Meet) OR Gmail │
       │  📥 Inbox   → Gmail read (polls the CRM address)     │
       │  🗓 Prep    → Calendar+Gmail, then web (separate run) │
       │  📰 News    → web search only (daily)                │
       └─────────────────────────────────────────────────────┘

Components

Web app (Next.js App Router)

  • Rendering: React Server Components; every page is force-dynamic and queries SQLite synchronously at request time (better-sqlite3 is synchronous, which suits per-request server rendering well).
  • Writes: server actions — complete/reopen action items, log interactions (which bump last_touch), edit profile sections in place, move pipeline stages, create people/companies/deals, dismiss news, confirm drafts.
  • Read layer: typed query functions (roster ordering, follow-up scoring, dashboard aggregation, cross-entity search, map data, the news feed, open inbox items).
  • Schema: people, companies, interactions, action_items (with real due dates), opportunities, connections, outreach, plus AI working tables (intake_drafts, log_drafts, briefs, coach_sessions, coach_messages, coach_proposals, inbox_messages, news_items, news_checks) and a key/value settings table. Idempotent CREATE TABLE IF NOT EXISTS plus tolerant column migrations at startup.
  • Vocabulary (statuses, buckets, stages, opportunity kinds, cadences) is configurable; a kind can be marked separate — the built-in job opportunity kind is listed after business-development work on a tinted card.
  • Access: the server binds to 127.0.0.1 and every browser needs a private sign-in link (a token cookie).

MCP server (Claude Desktop path)

A small stdio MCP server registered with Claude Desktop exposes the CRM over the same database: search, full profile reads, agenda ("what's overdue?"), pipeline listing and updates, interaction logging, profile building/updating with arbitrary markdown sections, action-item management, and deal management.

Built-in AI features

Each feature is split into fetch and write steps. Fetch steps spawn the locally installed Claude Code CLI in headless mode (claude -p --output-format stream-json, the owner's Claude subscription, no API key) with an explicit --allowedTools list. Write steps run on a local model through Ollama by default (configurable in Settings, with Claude as an optional provider or fallback), queued one at a time.

Feature Fetch (Claude, read-only) Write Output
Coach none local model or Claude Markdown advice; chat turns return a reply plus proposed CRM changes the owner ticks to record
Intake web search/fetch (optional) local model JSON: person, company, profile sections, connections, interaction, suggested actions, confidence flags
Log Zoom, Drive (Meet transcripts / Gemini notes) or Gmail readers, per source local model JSON: dated entries per contact, next-action updates, resolved item ids, unmatched participants
Inbox Gmail readers, on a schedule local model (Log / Intake drafts) Emails routed locally: roster contacts → Log draft, new person → Intake draft
Prep Calendar + Gmail; web in a separate run local model Markdown brief with source attribution; downloadable Word doc
News Feed web search/fetch only, daily, ~10 contacts per run Claude Stories about roster people and companies, de-duplicated, dismissable

Runs stream every tool call and thinking step into the draft row's progress column, which the page polls to render a live activity feed; finished reviews keep a collapsed recap. Two safety properties hold everywhere: tool grants are read-only, and external content (emails, transcripts, web pages) is treated as data, never as instructions. Splitting Prep's private-mail run from its web run means a web page can never steer the model into the inbox.

Backups & export

The web app and the MCP server each ensure a daily online-backup snapshot of the database (newest 30 kept, folder configurable in Settings). A separate script regenerates a human-readable markdown archive on demand.

Data model highlights

  • Status pipeline shared by people and companies: New → Exploring → Active → On hold → Client → Won / Lost / Dormant, each with a free-text status note.
  • Urgency buckets plus due dates for action items (overdue / log-gap / this-week / awaiting / high-potential / keep-warm / venture / data-gap); any dated item past its due date counts as overdue. The dashboard renders what is late or due within a week and folds older backlog away.
  • Cadence scoring: each person can carry cadence_days; Keep Warm computes days_since_last_touch − cadence and sorts by how overdue a touch is.
  • Connections are person-to-person labeled edges ("made intro", "owed intro", "colleague") rendered by the force-directed map.
  • Profile sections are markdown columns (relationship_intel, business_context, engagement_strategy, notes, extra_sections), editable in place.

What the public demo substitutes

Concern Production This demo
Code — The production source tree, with a thin overlay listed in DEMO.md
Storage SQLite file (better-sqlite3), WAL In-memory SQLite with the same schema, seeded from lib/seed.ts + lib/demoSeed.ts; resets when the serverless instance recycles
AI runs Ollama + headless Claude CLI Switched off at the runner and in each server action; entry pages show a 🔒 panel linking to finished examples
Drafts and briefs Produced live Seeded: an Intake draft and a Log draft (via the Inbox), a prep brief, a closed coach session — their review screens and confirm actions are real
News Feed / Inbox Daily web search; mailbox polling Seeded fictional stories (example.com links) and forwarded emails
Word-doc briefs markdown → docx Identical code path — this one is real
Sign-in, backups, MCP server Included Not included
Data Real relationships Entirely fictional dataset (17 people, 11 companies, 11 deals) with dates relative to "now"