ChatCrystal Development Guide

April 29, 2026 · View on GitHub

English | 简体中文

This guide covers repository structure, architecture, development commands, testing, and release workflows.

Project Overview

ChatCrystal is a local-first AI conversation crystallization tool. It imports conversations from AI coding tools, generates structured notes with LLMs, builds embeddings for semantic search, and exposes both UI and MCP workflows.

Monorepo Layout

ChatCrystal/
├── shared/                  # Shared TypeScript types
├── server/                  # Fastify backend, CLI, MCP server
├── client/                  # React SPA
├── electron/                # Electron main and preload processes
├── skills/                  # Publishable ChatCrystal agent skills
├── docs/                    # Maintainer and user documentation
├── scripts/                 # Release and utility scripts
└── site/                    # Project website

Tech Stack

LayerTechnology
BackendNode.js, Fastify v5, TypeScript
FrontendVite v8, React 19, Tailwind CSS v4, TanStack React Query v5
DesktopElectron, electron-builder
Databasesql.js WASM SQLite
LLMVercel AI SDK v6
Embeddingsvectra local vector index
Queuep-queue
File watchingchokidar

Development Commands

npm run dev                   # Server 3721 + client 13721
npm run build                 # Build server and client
npm start                     # Production server
npm run lint                  # Biome + client ESLint
npm run lint:fix              # Apply safe lint fixes
npm run test -w server        # Server tests
npm run dev:electron          # Electron dev mode
npm run build:electron        # Build Windows installer
npm run pack:electron         # Build unpacked Electron app
npm run eval:experience -w server

npm run eval:experience -w server runs the offline calibration suite for the experience quality gate.

Runtime Data

Runtime data is stored in config.json and chatcrystal.db under the active data directory.

Default data directory:

  • CLI, MCP, npm package, repository checkout, and Electron: ~/.chatcrystal/data
  • Explicit override: DATA_DIR

Electron sets ELECTRON=true, DATA_DIR, and ELECTRON_PACKAGED when applicable.

Data Flow

AI tool conversation files
  -> SourceAdapter scan/parse
  -> Import service deduplication
  -> SQLite conversations/messages
  -> Summarization queue
  -> LLM structured note generation
  -> Embedding generation
  -> vectra semantic index
  -> REST API, UI, CLI, MCP

Summarization Pipeline

ChatCrystal uses turn-based transcript preparation before summarization:

  1. Split messages into user-assistant turns.
  2. Keep the user instruction plus the first and last substantial assistant replies in each turn.
  3. Score turns by instruction length and assistant engagement.
  4. Always include the first turn and final turns.
  5. Fill the remaining budget with high-value middle turns.
  6. Compress skipped turns into one-line previews.

Structured output uses Vercel AI SDK generateObject() with Zod schemas. This avoids fragile JSON extraction and lets schema validation retry invalid model output.

Source Adapters

Add a new source by implementing SourceAdapter:

interface SourceAdapter {
  name: string;
  displayName: string;
  detect(): Promise<SourceInfo | null>;
  scan(): Promise<ConversationMeta[]>;
  parse(meta: ConversationMeta): Promise<ParsedConversation>;
}

Built-in adapters:

AdapterData SourceFormat
claude-code~/.claude/projects/**/*.jsonlJSONL conversation log
codex~/.codex/sessions/**/rollout-*.jsonlJSONL event stream
cursorCursor workspaceStorage/state.vscdbSQLite KV store
traeTrae workspaceStorage/state.vscdbSQLite KV store
copilotVS Code workspaceStorage/chatSessions/*.jsonlJSONL snapshots

Create the adapter under server/src/parser/adapters/ and register it in server/src/parser/index.ts.

API Surface

Key REST endpoints:

MethodPathDescription
GET/api/statusServer status and statistics
GET/api/configCurrent config with secrets redacted
POST/api/configUpdate provider config
POST/api/import/scanTrigger import
GET/api/conversationsList conversations
GET/api/conversations/:idConversation detail
POST/api/conversations/:id/summarizeSummarize one conversation
POST/api/summarize/batchBatch summarization
GET/api/notesList notes
GET/api/notes/:idNote detail
GET/api/search?q=...&expand=trueSemantic search
GET/api/relations/graphKnowledge graph data
GET/api/queue/statusQueue status

Knowledge Graph

The relation system supports these relation types:

RelationMeaning
CAUSED_BYCausation
LEADS_TOLeads to
RESOLVED_BYResolved by
SIMILAR_TOSimilar topic
CONTRADICTSContradiction
DEPENDS_ONDependency
EXTENDSExtension
REFERENCESReference

Relations can be discovered by LLM, added manually, or followed during semantic search expansion.

Testing

Primary verification:

npm run test -w server
npm run build
npm run lint
npm run eval:experience -w server

Use focused server tests while iterating, then run the full commands before committing.

Release

npm run release
npm run release -- minor
npm run release -- major
npm run release -- 1.0.0

The release script bumps version, creates a git tag, and pushes so CI can build and publish artifacts.