Skip to content

Architecture

GSD Bot edited this page May 24, 2026 · 1 revision

Architecture

Promptimprover operates as a local stdio MCP server sitting between your AI CLI and the language model. Every prompt passes through the refinement pipeline before reaching the model.

Pipeline Diagram

flowchart LR
    CLI["AI CLI\n(Claude / Cursor)"] -->|"stdio"| PI["Promptimprover\n(prompt-refiner)"]
    subgraph internal["Promptimprover Engine"]
        RAG["RAG Snippets\n(FlexSearch)"]
        Memory["SQLite Memory\n(LocalBrain)"]
        AutoHeal["Auto-Heal\n(BackgroundService)"]
    end
    PI --> RAG
    PI --> Memory
    PI --> AutoHeal
    internal --> Out["Augmented Prompt"]
Loading

Components

PromptRefinerServer

The MCP server entry point (src/core/server.ts). Registers MCP tools, handles refine_prompt tool calls over stdio transport, and coordinates the refinement pipeline. All prompt augmentation logic is triggered from here.

ProjectScout / Detectors

Stack detection layer (src/detectors/project-scout.ts). NodeDetector, PythonDetector, and ArchitecturalScout inspect the project root at startup to identify the tech stack and architectural patterns. This context is injected into every refined prompt.

NeuralSnippets

FlexSearch-based retrieval over the local codebase (src/memory/neural-snippets.ts). Indexes source files and retrieves the most relevant code examples matching each incoming prompt. Provides concrete, project-specific code context rather than generic examples.

LocalBrain

JSON-backed pattern store in .refiner/memory.json (src/memory/local-brain.ts). Accumulates project-specific coding rules and standards patterns learned over time. Grows more accurate as the system observes more prompts and outcomes.

PromptRefiner / PromptOptimizer

Core augmentation logic (src/refiners/prompt-refiner.ts, src/refiners/prompt-optimizer.ts). Applies project context from ProjectScout, learned patterns from LocalBrain, RAG snippets from NeuralSnippets, and any mandates from .gemini-refiner.json to produce the augmented prompt.

BackgroundAutonomyService

chokidar file watcher (src/core/background-service.ts). Monitors the project directory for file changes and triggers commit ingestion and lesson extraction automatically. Keeps the memory and context stores current without requiring manual intervention.

EventStore / CorrelationEngine / LessonExtractor

SQLite-backed history pipeline (src/history/). CommitIngester reads git log; CorrelationEngine links commits to outcomes; LessonExtractor derives actionable lessons. These feed back into LocalBrain for predictive prompt refinement.

CommandCenterDashboard

Local web UI on port 3000 (src/core/dashboard.ts). Displays agent activity logs and AgenticBlackboard state. Not exposed externally — local inspection only.