# Where to Find Text-to-CAD Source Code: Repository Structure and Core Components Explained

> Find the text-to-CAD source code in the earthtojake/text-to-cad GitHub repository. Explore the monorepo structure and discover core components for generation, viewer backend, and frontend.

- Repository: [earthtojake/text-to-cad](https://github.com/earthtojake/text-to-cad)
- Tags: architecture
- Published: 2026-09-13

---

**The Text-to-CAD source code is hosted in the `earthtojake/text-to-cad` GitHub repository as a monorepo, with the core Python generation library located in [`packages/cadgen/src/cadgen/generation.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/generation.py), the Flask viewer backend in [`packages/cadgen/src/cadgen/viewer/main.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/viewer/main.py), and the React frontend in [`apps/viewer/src/App.jsx`](https://github.com/earthtojake/text-to-cad/blob/main/apps/viewer/src/App.jsx).**

The earthtojake/text-to-cad project provides an open-source implementation of text-to-CAD generation with support for STEP, GLB, and URDF output formats. Developers seeking to modify the generation pipeline, customize the web viewer, or integrate CAD automation into existing tools can access the complete Text-to-CAD source code directly from GitHub. The repository follows a monorepo architecture that separates the core generation engine from the viewer application and shared JavaScript utilities.

## Monorepo Structure Overview

The repository root at `https://github.com/earthtojake/text-to-cad/tree/main` contains several top-level directories that separate concerns between the generation engine, viewer application, and tooling.

- **`packages/cadgen/`** – Houses the core Python library that implements the CAD generation pipeline.
- **`packages/cadgen-js/`** – Contains framework-agnostic JavaScript utilities for CAD rendering.
- **`apps/viewer/`** – The React-based web application for viewing generated models.
- **`models/examples/`** – Sample Python scripts demonstrating how to drive the generator.
- **`scripts/`** – Utility scripts for testing, bundling, and releasing the package.

## Core CAD Generation Library (Python)

The heart of the Text-to-CAD source code resides in `packages/cadgen/src/cadgen/`. This directory implements the full pipeline for converting text descriptions into manufacturable CAD files.

### Primary Generation API

The main entry point for programmatic CAD generation is [`packages/cadgen/src/cadgen/generation.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/generation.py). This module exposes the public Python API through functions like `generate_step()`, `generate_glb()`, and `generate_urdf()`.

To generate a STEP file from a model script, import the high-level API and invoke the appropriate function:

```python
from cadgen import generate_step, generate_glb, generate_urdf

# Generate a STEP file from a model script

generate_step("models/examples/src/print_in_place_hinge.py", out_path="out/hinge.step")

```

### Model Storage Layer

CAD model persistence and path management are handled in the `packages/cadgen/src/cadgen/store/` subdirectory. Key files include [`store/paths.py`](https://github.com/earthtojake/text-to-cad/blob/main/store/paths.py) for filesystem abstraction and [`store/records.py`](https://github.com/earthtojake/text-to-cad/blob/main/store/records.py) for model metadata management. These modules support the generation pipeline by ensuring consistent artifact storage across different output formats.

## Viewer Architecture

The repository includes a full-stack CAD viewer that enables interactive inspection of generated models. The viewer consists of a Python Flask backend and a React frontend.

### Flask Backend Server

The viewer's server-side logic is implemented in [`packages/cadgen/src/cadgen/viewer/main.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/viewer/main.py). This Flask application serves generated CAD artifacts to the client and provides API endpoints for model retrieval. According to the Text-to-CAD source code, you can launch the development server using the CLI:

```python
import subprocess

# Start the local development server

subprocess.run(["cadgen", "viewer", "--dev"])

```

This command initializes the Flask backend and serves the React UI from the `apps/viewer/` directory.

### React Frontend Application

The user interface code lives in [`apps/viewer/src/App.jsx`](https://github.com/earthtojake/text-to-cad/blob/main/apps/viewer/src/App.jsx) (with the entry point often referenced as [`index.jsx`](https://github.com/earthtojake/text-to-cad/blob/main/index.jsx)). This React application displays STEP and GLB models, provides UI controls for camera manipulation, and communicates with the backend via the `cadgen.viewer` API.

## JavaScript Runtime Utilities

For consumers needing CAD rendering capabilities outside the main viewer, the `packages/cadgen-js/` directory contains framework-agnostic utilities. The primary entry point is [`packages/cadgen-js/src/index.js`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen-js/src/index.js), which exports functions like `loadGLB()` for loading models in browser environments:

```javascript
import { loadGLB } from "cadgen-js";

loadGLB("/api/artifacts/hinge.glb").then(scene => {
  // Render the scene in your application
});

```

## Sample Models and Development Tools

The `models/examples/src/` directory contains executable Python scripts that demonstrate proper usage of the generation API. For instance, [`models/examples/src/print_in_place_hinge.py`](https://github.com/earthtojake/text-to-cad/blob/main/models/examples/src/print_in_place_hinge.py) provides a working example of a parametric hinge model that can be passed directly to the generation functions.

Supporting infrastructure includes:

- **[`scripts/test/test.sh`](https://github.com/earthtojake/text-to-cad/blob/main/scripts/test/test.sh)** – Automated testing scripts for CI pipelines.
- **[`scripts/release/check-version.sh`](https://github.com/earthtojake/text-to-cad/blob/main/scripts/release/check-version.sh)** – Version validation before releases.
- **[`scripts/bundle/bundle.sh`](https://github.com/earthtojake/text-to-cad/blob/main/scripts/bundle/bundle.sh)** – Packaging scripts for distribution.

## Working with the Source Code

To explore the Text-to-CAD source code locally, clone the repository and navigate to the component you need to modify. The [`README.md`](https://github.com/earthtojake/text-to-cad/blob/main/README.md) file in the repository root provides high-level architecture documentation and installation instructions.

When contributing to or extending the library, focus your changes on the appropriate package:

- Modify generation algorithms in [`packages/cadgen/src/cadgen/generation.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/generation.py).
- Update viewer backend routes in [`packages/cadgen/src/cadgen/viewer/main.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/viewer/main.py).
- Extend frontend rendering logic in [`apps/viewer/src/App.jsx`](https://github.com/earthtojake/text-to-cad/blob/main/apps/viewer/src/App.jsx).

## Summary

- The earthtojake/text-to-cad repository is a monorepo containing the complete Text-to-CAD source code.
- Core generation logic resides in [`packages/cadgen/src/cadgen/generation.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/generation.py), exposing the `cadgen` Python API.
- The viewer stack uses Flask ([`packages/cadgen/src/cadgen/viewer/main.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/viewer/main.py)) for the backend and React ([`apps/viewer/src/App.jsx`](https://github.com/earthtojake/text-to-cad/blob/main/apps/viewer/src/App.jsx)) for the frontend.
- Shared JavaScript utilities are available in [`packages/cadgen-js/src/index.js`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen-js/src/index.js).
- Example models in `models/examples/src/` demonstrate practical usage of the generation pipeline.

## Frequently Asked Questions

### Where is the main Python API defined in the Text-to-CAD source code?

The main Python API is defined in [`packages/cadgen/src/cadgen/generation.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/generation.py), which exports functions like `generate_step()`, `generate_glb()`, and `generate_urdf()`. This module serves as the primary entry point for programmatic CAD generation according to the earthtojake/text-to-cad source code.

### How do I run the CAD viewer locally from the source code?

You can launch the development viewer by running the Flask backend located at [`packages/cadgen/src/cadgen/viewer/main.py`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen/src/cadgen/viewer/main.py) using the command `cadgen viewer --dev`. This starts the backend server and serves the React frontend from `apps/viewer/`, enabling local inspection of generated models.

### What JavaScript utilities are available for CAD rendering?

The repository provides framework-agnostic utilities in [`packages/cadgen-js/src/index.js`](https://github.com/earthtojake/text-to-cad/blob/main/packages/cadgen-js/src/index.js), including the `loadGLB()` function for loading and rendering GLB models in browser environments. These utilities are consumed by the React viewer and can be imported into custom JavaScript applications.

### Where can I find example models to test the generator?

Sample CAD models are located in `models/examples/src/`, including files like [`print_in_place_hinge.py`](https://github.com/earthtojake/text-to-cad/blob/main/print_in_place_hinge.py). These scripts demonstrate the expected input format for the generation pipeline and can be passed directly to the `generate_step()` or `generate_glb()` functions to produce output files.