Compiler Architecture
The Prodara compiler processes .prd source files through 15 distinct phases, producing a deterministic Product Graph. Each phase is a separate module with typed inputs and outputs.
Design Principles
- Phase Separation - Each phase has a single responsibility and typed contract
- Diagnostic Accumulation - Errors are collected in a DiagnosticBag, never thrown as exceptions
- Deterministic Output - Same input always produces the same graph (except
compiled_at) - Agent-Friendly - All output is structured JSON with stable contracts
The 15 Phases
Discovery
Scans the file system for .prd source files and resolves module relationships.
Lexer
Tokenizes source text into a stream of typed tokens (keywords, identifiers, literals, punctuation).
Parser
Builds an Abstract Syntax Tree (AST) from the token stream.
Binder
Creates a symbol table linking declarations to their scopes and resolving references.
Type Checker
Validates type compatibility across fields, workflows, and references.
Graph Builder
Constructs the Product Graph from the bound and type-checked AST.
Planner
Diffs graphs and produces incremental plans with impact propagation.
Spec Test Runner
Executes specification-level tests against the Product Graph.
Runtime Resolution
Resolves runtime configurations and environment-specific settings.
Build State
Manages persistent build state for incremental compilation.
Generator Contracts
Produces typed contracts for downstream code generators.
Graph Validator
Validates structural integrity and semantic rules of the Product Graph.
Registry Resolution
Resolves external packages and presets from the registry.
Build Orchestration
Coordinates the full build pipeline and produces the final BuildSummary.
Configuration
Manages compiler configuration and feature flags.
Semantic Node IDs
Every node in the Product Graph has a stable semantic ID following the pattern:
<module>.<kind>.<name>
// Examples:
core.entity.user
billing.workflow.create_invoice
auth.surface.login_formBuild State
The compiler persists build state in a .prodara/ directory for incremental compilation. This includes the previous graph, plan artifacts, and build metadata.
Beyond Compilation
After the core 15-phase pipeline, Prodara runs additional high-level phases:
- Workflow Engine - Orchestrates specify → clarify → plan → implement cycles. See Custom Workflows.
- Reviewer Pipeline - 9 built-in reviewer agents inspect the plan from different perspectives. See Reviewers & Constitution.
- Extension System - Custom generators, validators, and reviewers loaded at build time. See Extensions & Presets.
- Proposal System - Stage changes in isolation for review. See Proposals & Changes.