CostAffective
Core Design

System Architecture

Explore the internal pipeline that maps, stores, and compresses repository contexts locally.

AI Editor Client (Cursor/Claude)MCP Server transport (stdio)AST Parser & Watchertreesitter static mappingLocal SQLite DBrelational index store

AST Relational Parser & Watcher

Parses files statically using tree-sitter compiler definitions to extract symbols, implementations, and call relationships. Monitored by a background fsnotify watchdog.

Relevant Repository Files
  • internal/watcher/watcher.go
  • internal/watcher/watchdog.go
  • internal/parser/ast.go

Pipeline Subcomponents

1. Tree-sitter AST Parser

Statically parses source code to compile tree nodes. Maps variables, structures, and function bounds to extract symbol-level boundaries.

2. SQLite Knowledge Store

Stores relational data maps including file hashes, tag names, call trees, and references. Optimized index triggers ensure query results return in microseconds.

3. Watchdog Daemon

Passive background file watcher using system notification boundaries. When files are saved, watchdog re-parses only the changed file paths in 8ms.

Execution Flow: Code Sync to Tool Query

This flowchart traces the lifecycle of a code edit and how it translates to token-saving context injection.

1. File Savedfsnotify watchdog2. AST Parsetree-sitter query3. Sync SQLiteincremental write4. Tool Queryfind_symbol call5. Context Sentcompressed (saved 45%)

Relational Index Database Schema

CostAffective maps directory relationships statically into four unified SQLite tables.

TABLE files
  • hash TEXT PRIMARY KEY
  • path TEXT UNIQUE
  • indexed_at TIMESTAMP
TABLE symbols
  • id INTEGER PRIMARY KEY
  • file_path TEXT
  • name TEXT
  • kind TEXT (func, struct, interface)
  • start_line INTEGER
  • end_line INTEGER