# asolarlez/sketch-backend architecture

> Architecture diagram of the GitHub repository asolarlez/sketch-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/asolarlez/sketch-backend
- Repository: https://github.com/asolarlez/sketch-backend

## Overview

SKETCH backend is a CEGIS-based program synthesizer. Users provide a sketch and options; the backend parses and represents the program as a Boolean DAG, encodes constraints, searches for candidate implementations, and checks them through counterexamples until it can return a result. The tree also shows a numerical synthesis branch with Boolean abstraction, evaluation, and optimization. The README identifies the product but gives little runtime detail; several connections below are therefore marked unverified rather than treated as confirmed call flow.

Main entry points: [`src/SketchSolver/InputParser/CEGISSolver.cpp`](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISSolver.cpp) (CEGIS control), [`src/SketchSolver/InputParser/CegisMain.cpp`](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CegisMain.cpp) (CLI entry), [`src/SketchSolver/InputParser/BooleanDAG.h`](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/BooleanDAG.h) (Boolean DAG), [`src/SketchSolver/InputParser/NodesToSolver.cpp`](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/NodesToSolver.cpp) (Constraint encoding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and DAG"]
  node_entry["CLI entry<br/>[CegisMain.cpp]"]
  node_options["CLI options<br/>[CommandLineArgs.h]"]
  node_reader["Input reader<br/>[InputReader.cpp]"]
  node_dag["Boolean DAG<br/>[BooleanDAG.h]"]
  node_nodes["DAG nodes<br/>[BooleanNodes.h]"]
  node_transforms["DAG transforms<br/>[DagOptim.cpp]"]
end

subgraph group_cegis["CEGIS search"]
  node_cegis["CEGIS control<br/>[CEGISSolver.cpp]"]
  node_finder["Candidate search<br/>[CEGISFinder.cpp]"]
  node_checker["Candidate checking<br/>[CEGISChecker.cpp]"]
  node_counterexample["Counterexamples"]
  node_result["Synthesis result<br/>[CEGISSolver.cpp]"]
end

subgraph group_sat["SAT solving"]
  node_constraints["Constraint encoding<br/>[NodesToSolver.cpp]"]
  node_cnf["Boolean to CNF<br/>[BooleanToCNF.h]"]
  node_satinterface["SAT interface<br/>[SATSolver.h]"]
  node_minisat["MiniSat engine<br/>[MSolver.h]"]
  node_synth["Synthesis solver<br/>[SynthInSolver.h]"]
end

subgraph group_numeric["Numerical synthesis"]
  node_abstraction["Boolean abstraction<br/>[BoolAbstractor.cpp]"]
  node_suggestions["Candidate suggestions"]
  node_evaluation["Symbolic evaluation"]
  node_optimizer["Numerical optimizer<br/>[SnoptWrapper.h]"]
end

node_user(("Sketch user"))

node_user -.->|"submits sketch"| node_entry
node_entry -.->|"reads options"| node_options
node_entry -.->|"loads input"| node_reader
node_reader -.->|"builds DAG"| node_dag
node_dag -->|"represents nodes"| node_nodes
node_dag -.->|"optimizes DAG"| node_transforms
node_entry -.->|"starts solving"| node_cegis
node_cegis -.->|"seeks candidate"| node_finder
node_cegis -.->|"checks candidate"| node_checker
node_cegis -.->|"requests counterexample"| node_counterexample
node_finder -.->|"encodes constraints"| node_constraints
node_constraints -->|"uses encoding"| node_cnf
node_constraints -->|"reads settings"| node_options
node_cnf -->|"uses solver interface"| node_satinterface
node_satinterface -.->|"dispatches solving"| node_minisat
node_minisat -->|"hosts synthesis"| node_synth
node_abstraction -->|"uses encoding"| node_cnf
node_suggestions -->|"evaluates candidates"| node_evaluation
node_suggestions -->|"uses optimization"| node_optimizer
node_checker -.->|"returns outcome"| node_result
node_cegis -.->|"produces result"| node_result

click node_entry "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CegisMain.cpp"
click node_options "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CommandLineArgs.h"
click node_reader "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/InputReader.cpp"
click node_dag "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/BooleanDAG.h"
click node_nodes "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/BooleanNodes.h"
click node_transforms "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/DagOptim.cpp"
click node_cegis "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISSolver.cpp"
click node_finder "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISFinder.cpp"
click node_checker "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISChecker.cpp"
click node_counterexample "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CounterexampleFinder.cpp"
click node_constraints "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/NodesToSolver.cpp"
click node_cnf "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/BooleanToCNF.h"
click node_satinterface "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/SolverInterfaces/SATSolver.h"
click node_minisat "https://github.com/asolarlez/sketch-backend/blob/master/src/MiniSat/core/MSolver.h"
click node_synth "https://github.com/asolarlez/sketch-backend/blob/master/src/MiniSat/core/SynthInSolver.h"
click node_abstraction "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/BoolAbstraction/BoolAbstractor.cpp"
click node_suggestions "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/SuggestionGenerators/SuggestionGeneratorUsingMax.h"
click node_evaluation "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/SymbolicEvaluators/SimpleEvaluator.cpp"
click node_optimizer "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/Optimizers/SnoptWrapper.h"
click node_result "https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISSolver.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_options,node_reader,node_dag,node_nodes,node_transforms,node_user toneBlue
class node_cegis,node_finder,node_checker,node_counterexample,node_result toneAmber
class node_constraints,node_cnf,node_satinterface,node_minisat,node_synth toneMint
class node_abstraction,node_suggestions,node_evaluation,node_optimizer toneRose
```

## Components

### Input and DAG

- [CLI entry](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CegisMain.cpp): `src/SketchSolver/InputParser/CegisMain.cpp`
- [CLI options](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CommandLineArgs.h): `src/SketchSolver/InputParser/CommandLineArgs.h`
- [Input reader](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/InputReader.cpp): `src/SketchSolver/InputParser/InputReader.cpp`
- [Boolean DAG](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/BooleanDAG.h): `src/SketchSolver/InputParser/BooleanDAG.h`
- [DAG nodes](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/BooleanNodes.h): `src/SketchSolver/InputParser/BooleanNodes.h`
- [DAG transforms](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/DagOptim.cpp): `src/SketchSolver/InputParser/DagOptim.cpp`

### CEGIS search

- [CEGIS control](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISSolver.cpp): `src/SketchSolver/InputParser/CEGISSolver.cpp`
- [Candidate search](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISFinder.cpp): `src/SketchSolver/InputParser/CEGISFinder.cpp`
- [Candidate checking](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISChecker.cpp): `src/SketchSolver/InputParser/CEGISChecker.cpp`
- [Counterexamples](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CounterexampleFinder.cpp): `src/SketchSolver/InputParser/CounterexampleFinder.cpp`
- [Synthesis result](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/CEGISSolver.cpp): `src/SketchSolver/InputParser/CEGISSolver.cpp`

### SAT solving

- [Constraint encoding](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/InputParser/NodesToSolver.cpp): `src/SketchSolver/InputParser/NodesToSolver.cpp`
- [Boolean to CNF](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/BooleanToCNF.h): `src/SketchSolver/BooleanToCNF.h`
- [SAT interface](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/SolverInterfaces/SATSolver.h): `src/SketchSolver/SolverInterfaces/SATSolver.h`
- [MiniSat engine](https://github.com/asolarlez/sketch-backend/blob/master/src/MiniSat/core/MSolver.h): `src/MiniSat/core/MSolver.h`
- [Synthesis solver](https://github.com/asolarlez/sketch-backend/blob/master/src/MiniSat/core/SynthInSolver.h): `src/MiniSat/core/SynthInSolver.h`

### Numerical synthesis

- [Boolean abstraction](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/BoolAbstraction/BoolAbstractor.cpp): `src/SketchSolver/NumericalSynthesis/BoolAbstraction/BoolAbstractor.cpp`
- [Candidate suggestions](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/SuggestionGenerators/SuggestionGeneratorUsingMax.h): `src/SketchSolver/NumericalSynthesis/SuggestionGenerators/SuggestionGeneratorUsingMax.h`
- [Symbolic evaluation](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/SymbolicEvaluators/SimpleEvaluator.cpp): `src/SketchSolver/NumericalSynthesis/SymbolicEvaluators/SimpleEvaluator.cpp`
- [Numerical optimizer](https://github.com/asolarlez/sketch-backend/blob/master/src/SketchSolver/NumericalSynthesis/Optimizers/SnoptWrapper.h): `src/SketchSolver/NumericalSynthesis/Optimizers/SnoptWrapper.h`

### Other components

- **Sketch user**

## Connections

- Sketch user → CLI entry: submits sketch
- CLI entry → CLI options: reads options
- CLI entry → Input reader: loads input
- Input reader → Boolean DAG: builds DAG
- Boolean DAG → DAG nodes: represents nodes (evidence: `src/SketchSolver/InputParser/BooleanDAG.h`)
- Boolean DAG → DAG transforms: optimizes DAG
- CLI entry → CEGIS control: starts solving
- CEGIS control → Candidate search: seeks candidate
- CEGIS control → Candidate checking: checks candidate
- CEGIS control → Counterexamples: requests counterexample
- Candidate search → Constraint encoding: encodes constraints
- Constraint encoding → Boolean to CNF: uses encoding (evidence: `src/SketchSolver/BooleanToCNF.h`)
- Constraint encoding → CLI options: reads settings (evidence: `src/SketchSolver/InputParser/NodesToSolver.cpp`)
- Boolean to CNF → SAT interface: uses solver interface (evidence: `src/SketchSolver/BooleanToCNF.h`)
- SAT interface → MiniSat engine: dispatches solving
- MiniSat engine → Synthesis solver: hosts synthesis (evidence: `src/MiniSat/core/MSolver.h`)
- Boolean abstraction → Boolean to CNF: uses encoding
- Candidate suggestions → Symbolic evaluation: evaluates candidates (evidence: `src/SketchSolver/NumericalSynthesis/SuggestionGenerators/SuggestionGeneratorUsingMax.h`)
- Candidate suggestions → Numerical optimizer: uses optimization (evidence: `src/SketchSolver/NumericalSynthesis/SuggestionGenerators/SuggestionGeneratorUsingMax.h`)
- Candidate checking → Synthesis result: returns outcome
- CEGIS control → Synthesis result: produces result
