# mr-sarvesh-surya/agentic-cad-starter architecture

> Architecture diagram of the GitHub repository mr-sarvesh-surya/agentic-cad-starter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mr-sarvesh-surya/agentic-cad-starter
- Repository: https://github.com/mr-sarvesh-surya/agentic-cad-starter

## Overview

#### Purpose and Entry Points
Agentic CAD Intelligence Platform converts natural-language mechanical design requests into validated parametric CAD components and assemblies, then exports STEP/STL/GLB assets. Runtime entry points are the FastAPI service at `backend/app/main.py`, React application at `frontend/src/main.jsx`, and core orchestration pipeline at `gear_engineering/main_pipeline.py`. The prior Streamlit-style implementation is isolated under `archive/app.py`.

#### Client and API Boundary
The browser UI is a Vite/React application composed around chat input, a 3D model viewer, and parameter inspection/editing. `frontend/src/App.jsx` coordinates UI state; `frontend/src/api.js` is the frontend/backend boundary; `frontend/src/components/Viewer3D.jsx` renders generated GLB geometry. The frontend submits intent and edits to FastAPI, then consumes model metadata and export URLs/assets.

#### Backend Session and Request Control
FastAPI exposes the CAD workflow and holds per-user/session design state through `backend/app/main.py` and `backend/app/session.py`. This layer is responsible for translating HTTP requests into pipeline operations and returning generated component/assembly data to the UI. It separates stateless browser interaction from mutable design sessions and filesystem-backed generated artifacts.

#### Intent-to-Design Pipeline
The central control flow is implemented in `gear_engineering/main_pipeline.py`: natural language is interpreted, routed, planned, parameterized, and converted into CAD work. Core stages are represented by `gear_engineering/core/intent.py`, `gear_engineering/core/router.py`, and `gear_engineering/core/planner.py`. The pipeline can use LLM reasoning through `gear_engineering/core/llm_client.py`, while deterministic parameter and state processing prevents the LLM from directly defining arbitrary geometry.

#### State, Schemas, and Design Intelligence
Component definitions and evolving assembly state are governed by `gear_engineering/core/component_schemas.py`, `gear_engineering/core/component_registry.py`, and `gear_engineering/core/state_manager.py`. Parsing modules under `gear_engineering/core/parser/` extract component-specific dimensions from requests; `gear_engineering/core/state_merger.py` reconciles changes. Persistent conversational/design memory is represented by `gear_engineering/core/memory.py` and repository-level `memory_db.json`.

#### Deterministic CAD Generation
Individual mechanical parts are generated by CadQuery-oriented component modules, including `gear_engineering/components/shaft/shaft_cad.py`, `gear_engineering/components/gear/gear_cad.py`, and `gear_engineering/components/bearing/bearing_cad.py`. Gear calculations and tooth geometry are specialized in `gear_engineering/components/gear/gear_math.py` and the separate `cq_gears/` library, such as `cq_gears/spur_gear.py`. This is the key boundary between interpreted intent/parameters and manufacturable solid geometry.

#### Assembly, Enrichment, and Outputs
Multi-part designs flow through assembly synthesis and placement in `gear_engineering/assembly/assembly_builder.py`, with mechanical additions and housing generation in `gear_engineering/assembly/mechanical_enricher.py` and `gear_engineering/assembly/housing_generator.py`. Generated solids are exported as STEP, STL, and GLB under `outputs/`, allowing the UI to preview GLB while retaining manufacturing/CAD interchange formats. Docker Compose (`docker-compose.yml`) runs the Python/FastAPI/CadQuery backend and Node/Vite frontend; OpenAI is the material external service, configured via `OPENAI_API_KEY`.

Main entry points: [`backend/app/main.py`](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/backend/app/main.py) (FastAPI service), [`frontend/src/api.js`](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/frontend/src/api.js) (API client), [`gear_engineering/main_pipeline.py`](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/main_pipeline.py) (CAD pipeline), [`gear_engineering/core/planner.py`](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/planner.py) (Design planner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_react_app["React CAD UI<br/>Vite/React<br/>[App.jsx]"]
  node_frontend_api["API client<br/>frontend boundary<br/>[api.js]"]
  node_viewer["3D viewer<br/>GLB renderer<br/>[Viewer3D.jsx]"]
end

subgraph group_api["API &amp; Sessions"]
  node_fastapi["FastAPI service<br/>HTTP API<br/>[main.py]"]
  node_sessions[("Design sessions<br/>session state<br/>[session.py]")]
end

subgraph group_pipeline["Design Intelligence"]
  node_pipeline["CAD pipeline<br/>orchestrator<br/>[main_pipeline.py]"]
  node_intent["Intent &amp; routing<br/>interpretation<br/>[intent.py]"]
  node_planner["Design planner<br/>planning<br/>[planner.py]"]
  node_llm{{"OpenAI<br/>external LLM"}}
  node_design_state[("Schemas &amp; design state<br/>registry/state<br/>[state_manager.py]")]
end

subgraph group_cad["CAD &amp; Assembly"]
  node_components["Part generators<br/>CadQuery components<br/>[gear_cad.py]"]
  node_gear_library["Gear geometry library<br/>cq_gears<br/>[spur_gear.py]"]
  node_assembly["Assembly synthesis<br/>assembly builder"]
  node_enrichment["Mechanical enrichment<br/>housing/mechanics"]
end

subgraph group_artifacts["State &amp; Outputs"]
  node_memory[("Design memory<br/>persistent memory<br/>[memory.py]")]
  node_memory_db[("Memory database<br/>JSON store<br/>[memory_db.json]")]
  node_exports["CAD exports<br/>STEP/STL/GLB artifacts"]
end

node_legacy["Archived Streamlit app<br/>legacy entry point<br/>[app.py]"]

node_react_app -->|"submits intent and edits"| node_frontend_api
node_frontend_api -->|"HTTP"| node_fastapi
node_fastapi -->|"loads and updates"| node_sessions
node_fastapi -->|"invokes workflow"| node_pipeline
node_pipeline -->|"interprets request"| node_intent
node_intent -->|"routes design work"| node_planner
node_planner -.->|"reasoning"| node_llm
node_planner -->|"validates parameters"| node_design_state
node_pipeline -->|"reads and records context"| node_memory
node_memory -->|"persists"| node_memory_db
node_design_state -->|"validated component specs"| node_components
node_components -->|"tooth geometry"| node_gear_library
node_components -->|"part solids"| node_assembly
node_assembly -->|"assembled design"| node_enrichment
node_enrichment -->|"exports STEP/STL/GLB"| node_exports
node_fastapi -->|"returns metadata and assets"| node_exports
node_frontend_api -->|"model metadata/assets"| node_viewer
node_viewer -->|"loads GLB"| node_exports

click node_react_app "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/frontend/src/App.jsx"
click node_frontend_api "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/frontend/src/api.js"
click node_viewer "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/frontend/src/components/Viewer3D.jsx"
click node_fastapi "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/backend/app/main.py"
click node_sessions "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/backend/app/session.py"
click node_pipeline "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/main_pipeline.py"
click node_intent "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/intent.py"
click node_planner "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/planner.py"
click node_design_state "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/state_manager.py"
click node_memory "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/memory.py"
click node_memory_db "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/memory_db.json"
click node_components "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/components/gear/gear_cad.py"
click node_gear_library "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/cq_gears/spur_gear.py"
click node_assembly "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/assembly/assembly_builder.py"
click node_enrichment "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/assembly/mechanical_enricher.py"
click node_exports "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/outputs/agentic_assembly_output.step"
click node_legacy "https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/archive/app.py"

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_react_app,node_frontend_api,node_viewer toneBlue
class node_fastapi,node_sessions toneAmber
class node_pipeline,node_intent,node_planner,node_llm,node_design_state toneMint
class node_components,node_gear_library,node_assembly,node_enrichment toneRose
class node_memory,node_memory_db,node_exports toneIndigo
class node_legacy toneNeutral
```

## Components

### Browser Client

- [React CAD UI](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/frontend/src/App.jsx): Vite/React · Chat, parameter editing, and design state UI. · `frontend/src/App.jsx`
- [API client](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/frontend/src/api.js): frontend boundary · `frontend/src/api.js`
- [3D viewer](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/frontend/src/components/Viewer3D.jsx): GLB renderer · `frontend/src/components/Viewer3D.jsx`

### API & Sessions

- [FastAPI service](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/backend/app/main.py): HTTP API · Translates browser requests into pipeline operations. · `backend/app/main.py`
- [Design sessions](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/backend/app/session.py): session state · Holds mutable per-user design state and artifacts. · `backend/app/session.py`

### Design Intelligence

- [CAD pipeline](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/main_pipeline.py): orchestrator · Runs intent-to-validated-CAD workflow. · `gear_engineering/main_pipeline.py`
- [Intent & routing](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/intent.py): interpretation · `gear_engineering/core/intent.py`
- [Design planner](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/planner.py): planning · `gear_engineering/core/planner.py`
- **OpenAI**: external LLM · Reasoning aid; deterministic processing controls geometry.
- [Schemas & design state](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/state_manager.py): registry/state · Governs component definitions and evolving assemblies. · `gear_engineering/core/state_manager.py`

### CAD & Assembly

- [Part generators](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/components/gear/gear_cad.py): CadQuery components · Generates shaft, gear, and bearing solids from validated parameters. · `gear_engineering/components/gear/gear_cad.py`
- [Gear geometry library](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/cq_gears/spur_gear.py): cq_gears · Specialized tooth geometry and gear calculations. · `cq_gears/spur_gear.py`
- [Assembly synthesis](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/assembly/assembly_builder.py): assembly builder · Places and combines generated components. · `gear_engineering/assembly/assembly_builder.py`
- [Mechanical enrichment](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/assembly/mechanical_enricher.py): housing/mechanics · Adds mechanical features and housing geometry. · `gear_engineering/assembly/mechanical_enricher.py`

### State & Outputs

- [Design memory](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/gear_engineering/core/memory.py): persistent memory · `gear_engineering/core/memory.py`
- [Memory database](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/memory_db.json): JSON store · `memory_db.json`
- [CAD exports](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/outputs/agentic_assembly_output.step): STEP/STL/GLB artifacts · Manufacturing formats plus browser-preview geometry. · `outputs/agentic_assembly_output.step`

### Other components

- [Archived Streamlit app](https://github.com/mr-sarvesh-surya/agentic-cad-starter/blob/main/archive/app.py): legacy entry point · Isolated prior implementation. · `archive/app.py`

## Connections

- React CAD UI → API client: submits intent and edits
- API client → FastAPI service: HTTP
- FastAPI service → Design sessions: loads and updates
- FastAPI service → CAD pipeline: invokes workflow
- CAD pipeline → Intent & routing: interprets request
- Intent & routing → Design planner: routes design work
- Design planner → OpenAI: reasoning
- Design planner → Schemas & design state: validates parameters
- CAD pipeline → Design memory: reads and records context
- Design memory → Memory database: persists
- Schemas & design state → Part generators: validated component specs
- Part generators → Gear geometry library: tooth geometry
- Part generators → Assembly synthesis: part solids
- Assembly synthesis → Mechanical enrichment: assembled design
- Mechanical enrichment → CAD exports: exports STEP/STL/GLB
- FastAPI service → CAD exports: returns metadata and assets
- API client → 3D viewer: model metadata/assets
- 3D viewer → CAD exports: loads GLB
