How mr-sarvesh-surya/agentic-cad-starter works
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: main.py FastAPI service · api.js API client · main_pipeline.py CAD pipeline · planner.py Design planner
Components 18
Browser Client
- React CAD UI · Chat, parameter editing, and design state UI.
frontend/src/App.jsx - API client
frontend/src/api.js - 3D viewer
frontend/src/components/Viewer3D.jsx
API & Sessions
- FastAPI service · Translates browser requests into pipeline operations.
backend/app/main.py - Design sessions · Holds mutable per-user design state and artifacts.
backend/app/session.py
Design Intelligence
- CAD pipeline · Runs intent-to-validated-CAD workflow.
gear_engineering/main_pipeline.py - Intent & routing
gear_engineering/core/intent.py - Design planner
gear_engineering/core/planner.py - OpenAI · Reasoning aid; deterministic processing controls geometry.
- Schemas & design state · Governs component definitions and evolving assemblies.
gear_engineering/core/state_manager.py
CAD & Assembly
- Part generators · Generates shaft, gear, and bearing solids from validated parameters.
gear_engineering/components/gear/gear_cad.py - Gear geometry library · Specialized tooth geometry and gear calculations.
cq_gears/spur_gear.py - Assembly synthesis · Places and combines generated components.
gear_engineering/assembly/assembly_builder.py - Mechanical enrichment · Adds mechanical features and housing geometry.
gear_engineering/assembly/mechanical_enricher.py
State & Outputs
- Design memory
gear_engineering/core/memory.py - Memory database
memory_db.json - CAD exports · Manufacturing formats plus browser-preview geometry.
outputs/agentic_assembly_output.step
Other components
- Archived Streamlit app · Isolated prior implementation.
archive/app.py
Connections 18
- 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