PlanToCode Architecture
How the desktop shell, background workflows, and shared services are organised.
PlanToCode is a Tauri desktop application with a React front end. The UI renders implementation plans, terminals, and configuration controls, while the Rust backend exposes commands for workflows, token estimation, and persistent terminal sessions. This overview summarises how those pieces fit together.
System map snapshot
This diagram depicts the PlanToCode system architecture as four interconnected layers arranged vertically. Top Layer - Desktop Frontend: A React/Next.js box containing components (Plan Viewer, Terminal Panel, Session Manager) connected via labeled arrows "invoke()" and "listen()" to the Tauri IPC bridge. Second Layer - Rust Backend: WorkflowOrchestrator (scheduling multi-stage jobs), TerminalSessionManager (PTY lifecycle), and job processors (FileDiscovery, PlanGeneration, TextImprovement, DeepResearch). Third Layer - Persistence: SQLite tables for sessions, background_jobs, and terminal_sessions with read/write arrows. Fourth Layer - External Services: Server routes under /api/llm/* and /api/auth with provider icons (OpenAI, Anthropic, Google, OpenRouter). Data flows run down through the layers; streaming responses and job events flow back up to the UI.
Frontend surface
The desktop UI is built with React components. Implementation plan content is displayed through a Monaco-based viewer that virtualises large plans, detects languages, and supports copy actions so reviewers can examine plan text without performance issues. Terminal sessions render inside a buffered view that attaches to PTY output and shows connection status updates.
Shared providers handle notifications, runtime configuration, and plan state. The Implementation Plans panel keeps plan metadata, manages modal visibility, and requests token estimates or prompt content as needed.
Key React components:
- ImplementationPlansProvider - Plan state and modal management
- PlanViewer (Monaco) - Virtualized plan rendering
- TerminalSurface - PTY output streaming
- TaskDescriptionEditor - Task input with voice integration
- WorkflowTracker - Job progress visualization
Tauri commands and services
The Rust side of the application exposes commands for workflows, terminal sessions, and model tooling. The workflow commands start background jobs through the Workflow Orchestrator, validating inputs and emitting progress events as the file discovery pipeline runs. Token estimation commands calculate prompt sizes for the currently selected model.
Terminal commands manage PTY processes, track remote clients, and verify whether supported CLI binaries are available before launching a session. Health checks combine PTY status with database records to report whether a session is still alive.
Command categories (35+ modules):
- workflow_commands, job_commands - Orchestration
- session_commands, terminal_commands - State management
- implementation_plan_commands - Plan generation
- audio_commands, video_analysis_commands - Media processing
- device_commands, auth0_commands - Connectivity
- config_commands, settings_commands - Configuration
IPC bridge and event streaming
The desktop UI calls Rust commands through the Tauri IPC bridge for workflows, terminal sessions, token estimation, and configuration updates.
Commands are invoked from React and results stream back via event listeners so the UI can update job progress, terminal output, and session state in real time.
IPC event types:
- job:status-changed, job:stream-progress - Job updates
- workflow-status, workflow-stage - Workflow progress
- terminal:output, terminal:status - PTY streaming
- session:updated - Session state changes
- orchestrator:initialized - System ready
Workflow orchestrator
Multi-stage workflows (file discovery, research, plan generation) are defined in JSON and executed by the Workflow Orchestrator.
Each stage maps to a Rust processor; intermediate results are persisted to SQLite and forwarded to the next stage with progress events emitted to the UI.
Workflow definitions:
- file_finder_workflow.json - 4-stage file discovery
- web_search_workflow.json - 2-stage research
- Embedded via embedded_workflows.rs
Persistence and configuration
Terminal output and session metadata are stored in SQLite via the terminal sessions repository. Each record includes identifiers, timestamps, working directories, environment variables, and the accumulated log so that restarts can recover prior output. The same repository emits events when session state changes.
Model defaults live in the application configuration table. Each task defines a default model, a list of allowed alternatives, token budgets, and optional copy-button presets. The React layer reads these settings to populate the model selector and guardrails.
State synchronization
React providers treat SQLite as the source of truth for plans, jobs, and terminal sessions, rehydrating state on startup.
Tauri events update in-memory state as jobs run, while repositories ensure plan history and session output survive restarts.
Voice transcription pipeline
Voice transcription is implemented as a React hook that coordinates media permissions, microphone selection, and transcription requests. The hook integrates with the plan terminal and prompt editors, inserting recognised text directly into the active component and surfacing notifications if transcription fails.
Server layer
The server handles provider configuration (API keys from env/config and provider/model mappings), routes proxy requests by provider prefix, enforces rate limits, and records usage/cost for billing. It also serves system prompt defaults and runtime model configuration to clients.
Server components:
- Actix-Web framework with PostgreSQL + Redis
- JWT + API Key authentication with RLS
- LLM proxy: OpenAI, Anthropic, Google, X.AI, OpenRouter
- WebSocket relay for desktop/mobile device linking
- Stripe billing with credit-based usage tracking
Data flows
Tasks, plans, jobs, and sessions flow between components: (1) Task refinement: React UI → TextImprovementPopover → Tauri command → WorkflowOrchestrator → text_improvement prompt → SQLite → React provider replaces text. (2) File discovery: Implementation Plans panel → Tauri command → 4 sequential jobs → progress events → SQLite → UI display. (3) Implementation plans: File discovery → Generate Plan → Tauri command → LLM streaming → SQLite → Monaco viewer → review/approve → export. (4) Terminal execution: PTY session → command execution → output streaming → SQLite → voice transcription injection → attention indicators.
LLM routing and provider normalization
Model requests are sent to the server proxy, which routes by provider prefix and normalizes payloads and streaming responses.
The proxy tracks usage and cost per user or API key, enforces rate limits, and routes specific providers through OpenRouter when configured (for example, Anthropic streaming or DeepSeek mappings).
Key source directories
Desktop (Tauri + React)
- desktop/src - React UI
- desktop/src-tauri/src/commands - IPC commands
- desktop/src-tauri/src/jobs - Job processors
- desktop/src-tauri/src/db_utils - Repositories
- desktop/src-tauri/migrations - SQLite schema
Server (Actix-Web)
- server/src/handlers - Request handlers
- server/src/clients - Provider clients
- server/src/services - Business logic
- server/src/db - PostgreSQL access
- server/src/streaming - SSE adapters
Explore specific subsystems
Dive into the desktop internals, server API, or background jobs to understand each layer in detail.