# wrathemperor/superdesign-app-compiler architecture

> Architecture diagram of the GitHub repository wrathemperor/superdesign-app-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wrathemperor/superdesign-app-compiler
- Repository: https://github.com/wrathemperor/superdesign-app-compiler

## Overview

#### Purpose and Entry Points
Superdesign is a compiler-style backend that converts a natural-language app request into a validated application blueprint: intent, architecture, database/API/UI/auth schemas, and repairs. The FastAPI service starts at `app/main.py`; orchestration is centralized in `app/pipeline.py`. A separate Vite/React viewer renders generated architecture output from `frontend/src/main.jsx` and `frontend/src/App.jsx`.

#### Request and Pipeline Boundary
The backend accepts a generation request, converts it into typed Pydantic contracts, and returns a complete executable configuration. Shared intermediate and final blueprint types define the stage boundary in `app/models/schemas.py`. `app/pipeline.py` owns ordered execution, parallel schema generation, validation, and retry/repair convergence rather than exposing stages as independent services.

#### 1. Intent Extraction
`app/stages/intent.py` transforms free-form requirements into a structured intermediate representation: inferred product scope, actors, capabilities, and constraints. This is the first LLM-facing normalization boundary; downstream stages consume typed intent rather than raw user text. Its output is enforced through `app/models/schemas.py`.

#### 2. System Design
`app/stages/design.py` converts intent into the high-level application design: domain entities, user flows, and role/permission concepts. This stage bridges business requirements and implementation schemas, giving subsequent generators a common architectural source of truth. It exchanges validated objects defined in `app/models/schemas.py`.

#### 3. Parallel Schema Compilation
`app/stages/schema.py` compiles the design into coordinated DB, API, UI, and authentication configurations. These schemas are intended as generation-ready targets for SQL migrations, OpenAPI-like APIs, frontend component/routing trees, and authorization middleware. The pipeline in `app/pipeline.py` can run schema work concurrently to reduce latency while preserving a single assembled blueprint.

#### 4. Cross-Layer Validation
`app/stages/validate.py` checks structural Pydantic validity and semantic consistency across layers—for example, API fields and endpoints against data entities, or authorization rules against roles and UI pages. This is the primary quality gate between probabilistic LLM output and the externally returned configuration. Validation contracts and error representations reside in `app/models/schemas.py`.

#### 5. Targeted Repair Loop
`app/stages/repair.py` receives validation failures and fixes only the affected configuration segment rather than regenerating the entire blueprint. `app/pipeline.py` revalidates repaired output until it converges or reaches its control limit. This isolates LLM nondeterminism and token cost to invalid artifacts while retaining valid earlier-stage output.

#### LLM and Runtime Infrastructure
The Python 3.10+ backend uses FastAPI/Uvicorn (`app/main.py`) and Pydantic models (`app/models/schemas.py`). LLM invocation, JSON cleanup, constrained structured-output handling, and local mock behavior are encapsulated in `app/utils/llm.py`. Production generation targets Gemini 2.0 Flash via `GEMINI_API_KEY`; `MOCK_LLM=true` provides local, quota-free deterministic demonstration behavior. Container deployment is supported by `Dockerfile` and Google Cloud-oriented ignore rules.

#### Presentation and Evaluation
The React/Vite frontend is a visualization client, not the compiler runtime; its architecture preview is implemented in `frontend/src/components/ArchitecturePreview.jsx`. Evaluation executes the same pipeline over a benchmark suite through `app/eval/evaluate.py` and `app/eval/suite.py`, with persisted results in `data/eval_results.json`.

Main entry points: [`app/stages/schema.py`](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/schema.py) (Schema compilation), [`app/pipeline.py`](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/pipeline.py) (Blueprint pipeline), [`app/stages/validate.py`](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/validate.py) (Cross-layer validation), [`app/utils/llm.py`](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/utils/llm.py) (LLM runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Compiler Backend"]
  node_api{{"FastAPI service<br/>HTTP entrypoint<br/>[main.py]"}}
  node_pipeline["Blueprint pipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_contracts["Blueprint contracts<br/>Pydantic models<br/>[schemas.py]"]
  node_llm["LLM runtime<br/>Gemini/mock adapter<br/>[llm.py]"]
end

subgraph group_stages["Compilation Stages"]
  node_intent["Intent extraction<br/>normalization stage<br/>[intent.py]"]
  node_design["System design<br/>design stage<br/>[design.py]"]
  node_schemas["Schema compilation<br/>parallel generator<br/>[schema.py]"]
  node_db_schema[("Database schema<br/>blueprint layer")]
  node_api_schema["API schema<br/>blueprint layer"]
  node_ui_schema["UI schema<br/>blueprint layer"]
  node_auth_schema["Auth schema<br/>blueprint layer"]
  node_validate["Cross-layer validation<br/>quality gate<br/>[validate.py]"]
  node_repair["Targeted repair<br/>repair stage<br/>[repair.py]"]
end

subgraph group_presentation["Viewer and Evaluation"]
  node_viewer_entry{{"Viewer entry<br/>Vite/React entrypoint<br/>[main.jsx]"}}
  node_viewer["Architecture viewer<br/>React client<br/>[App.jsx]"]
  node_preview["Architecture preview<br/>visualization component"]
  node_evaluation["Benchmark evaluation<br/>evaluation runner<br/>[evaluate.py]"]
  node_suite["Benchmark suite<br/>evaluation inputs<br/>[suite.py]"]
  node_results[("Evaluation results<br/>persisted results<br/>[eval_results.json]")]
end

node_api -->|"generation request"| node_pipeline
node_pipeline -->|"raw request"| node_intent
node_intent -->|"typed intent"| node_design
node_design -->|"application design"| node_schemas
node_schemas -->|"compile"| node_db_schema
node_schemas -->|"compile"| node_api_schema
node_schemas -->|"compile"| node_ui_schema
node_schemas -->|"compile"| node_auth_schema
node_schemas -->|"assembled blueprint"| node_validate
node_validate -->|"validated blueprint"| node_pipeline
node_validate -.->|"validation failures"| node_repair
node_repair -.->|"patched segment"| node_validate
node_pipeline -->|"validates stage boundaries"| node_contracts
node_intent -.->|"structured generation"| node_llm
node_design -.->|"structured generation"| node_llm
node_schemas -.->|"parallel generation"| node_llm
node_repair -.->|"targeted correction"| node_llm
node_viewer_entry -->|"mounts"| node_viewer
node_viewer -->|"renders"| node_preview
node_evaluation -->|"loads cases"| node_suite
node_evaluation -->|"executes"| node_pipeline
node_evaluation -->|"persists"| node_results

click node_api "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/main.py"
click node_pipeline "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/pipeline.py"
click node_contracts "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/models/schemas.py"
click node_llm "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/utils/llm.py"
click node_intent "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/intent.py"
click node_design "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/design.py"
click node_schemas "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/schema.py"
click node_validate "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/validate.py"
click node_repair "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/repair.py"
click node_viewer_entry "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/frontend/src/main.jsx"
click node_viewer "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/frontend/src/App.jsx"
click node_preview "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/frontend/src/components/ArchitecturePreview.jsx"
click node_evaluation "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/eval/evaluate.py"
click node_suite "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/eval/suite.py"
click node_results "https://github.com/wrathemperor/superdesign-app-compiler/blob/main/data/eval_results.json"

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_api,node_pipeline,node_contracts,node_llm toneBlue
class node_intent,node_design,node_schemas,node_db_schema,node_api_schema,node_ui_schema,node_auth_schema,node_validate,node_repair toneAmber
class node_viewer_entry,node_viewer,node_preview,node_evaluation,node_suite,node_results toneMint
```

## Components

### Compiler Backend

FastAPI service and blueprint compiler pipeline.

- [FastAPI service](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/main.py): HTTP entrypoint · `app/main.py`
- [Blueprint pipeline](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/pipeline.py): orchestrator · Coordinates generation, parallel compilation, validation, and repair retries. · `app/pipeline.py`
- [Blueprint contracts](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/models/schemas.py): Pydantic models · Typed intermediate, final, validation, and error contracts. · `app/models/schemas.py`
- [LLM runtime](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/utils/llm.py): Gemini/mock adapter · Handles structured output, cleanup, and deterministic mock behavior. · `app/utils/llm.py`

### Compilation Stages

Ordered LLM-assisted transformation and quality stages.

- [Intent extraction](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/intent.py): normalization stage · Converts free-form requests into typed scope, actors, capabilities, and constraints. · `app/stages/intent.py`
- [System design](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/design.py): design stage · Produces entities, flows, and roles from validated intent. · `app/stages/design.py`
- [Schema compilation](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/schema.py): parallel generator · Builds coordinated database, API, UI, and auth configurations. · `app/stages/schema.py`
- **Database schema**: blueprint layer
- **API schema**: blueprint layer
- **UI schema**: blueprint layer
- **Auth schema**: blueprint layer
- [Cross-layer validation](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/validate.py): quality gate · Checks structural validity and consistency across compiled layers. · `app/stages/validate.py`
- [Targeted repair](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/stages/repair.py): repair stage · Fixes only configuration segments identified by validation failures. · `app/stages/repair.py`

### Viewer and Evaluation

Separate visualization client and benchmark runner.

- [Viewer entry](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/frontend/src/main.jsx): Vite/React entrypoint · `frontend/src/main.jsx`
- [Architecture viewer](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/frontend/src/App.jsx): React client · Renders generated architecture output; not part of compiler runtime. · `frontend/src/App.jsx`
- [Architecture preview](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/frontend/src/components/ArchitecturePreview.jsx): visualization component · `frontend/src/components/ArchitecturePreview.jsx`
- [Benchmark evaluation](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/eval/evaluate.py): evaluation runner · Runs the same pipeline over the benchmark suite. · `app/eval/evaluate.py`
- [Benchmark suite](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/app/eval/suite.py): evaluation inputs · `app/eval/suite.py`
- [Evaluation results](https://github.com/wrathemperor/superdesign-app-compiler/blob/main/data/eval_results.json): persisted results · `data/eval_results.json`

## Connections

- FastAPI service → Blueprint pipeline: generation request
- Blueprint pipeline → Intent extraction: raw request
- Intent extraction → System design: typed intent
- System design → Schema compilation: application design
- Schema compilation → Database schema: compile
- Schema compilation → API schema: compile
- Schema compilation → UI schema: compile
- Schema compilation → Auth schema: compile
- Schema compilation → Cross-layer validation: assembled blueprint
- Cross-layer validation → Blueprint pipeline: validated blueprint
- Cross-layer validation → Targeted repair: validation failures
- Targeted repair → Cross-layer validation: patched segment
- Blueprint pipeline → Blueprint contracts: validates stage boundaries
- Intent extraction → LLM runtime: structured generation
- System design → LLM runtime: structured generation
- Schema compilation → LLM runtime: parallel generation
- Targeted repair → LLM runtime: targeted correction
- Viewer entry → Architecture viewer: mounts
- Architecture viewer → Architecture preview: renders
- Benchmark evaluation → Benchmark suite: loads cases
- Benchmark evaluation → Blueprint pipeline: executes
- Benchmark evaluation → Evaluation results: persists
