What Programming Languages Does Text-to-CAD Use? A Polyglot Codebase Breakdown
Text-to-CAD uses four primary programming languages—Python, JavaScript, TypeScript, and GLSL—to power its complete CAD-to-agent workflow, spanning from backend geometry generation to browser-based implicit modeling.
The earthtojake/text-to-CAD repository is a polyglot system that leverages specific languages for distinct architectural layers. Understanding this language distribution is essential for contributors targeting the core CAD generation logic, the web viewer, or the shader-based rendering pipeline.
Python for Core CAD Generation and Export
Python handles the heavy lifting of CAD artifact creation, geometry export, and robot-description management. The core logic resides in the cadpy package, where the public API exposes methods for generating industry-standard formats.
The primary entry point for Python-based operations is packages/cadpy/src/cadpy/api.py. This module implements the high-level interface for exporting CAD models to formats including STEP, STL, 3MF, GLB, and URDF. The test suite in tests/python/viewer/moveit2_server/test_protocol.py validates the protocol interactions between the CAD generation layer and the robot simulation environment.
# Python: Export a STEP model from a user prompt
from cadpy import export_step
export_step("Create a rectangular block with holes", "output/block.step")
JavaScript and TypeScript for the Browser-Based Viewer
The frontend architecture splits responsibilities between JavaScript for runtime execution and TypeScript for type-safe development and documentation.
JavaScript Runtime and UI Glue
JavaScript powers the browser-based viewer runtime and UI integration scripts. The file packages/implicitjs/src/browser.js serves as the main entry point for launching the CAD viewer, handling the glue code necessary to initialize the rendering context and load local model directories.
// JavaScript: Launch the CAD viewer for a local models directory
import { launchViewer } from "cadjs-viewer";
launchViewer({ dir: "/absolute/path/to/models" });
TypeScript Type Definitions and Next.js Integration
TypeScript provides strong typing for the shared CAD JavaScript library and supports the Next.js documentation site. The type definitions in docs/src/types/cadjs.d.ts specify the interfaces for viewer configuration, ensuring compile-time safety for frontend tooling that interacts with the CAD pipeline.
// TypeScript: Strongly‑typed API for CAD viewer configuration
import type { ViewerOptions } from "cadjs-viewer";
const opts: ViewerOptions = { dir: "/models", port: 4178 };
launchViewer(opts);
GLSL Shaders for Implicit CAD Rendering
GLSL (OpenGL Shading Language) enables real-time implicit CAD rendering through signed-distance-field shaders that execute directly in the browser. These shaders are embedded within the JavaScript sources and compiled at runtime by the WebGL context.
The fragment shader logic resides in packages/implicitjs/src/lib/implicitCad/shader.glsl, containing the distance functions that render 3D geometry without explicit meshes.
// GLSL (embedded in JavaScript): Simple signed distance function for a sphere
float sdSphere(vec3 p, float r) {
return length(p) - r;
}
How the Languages Interact in the CAD Workflow
The text-to-CAD architecture follows a clear separation of concerns across its language boundaries:
- Python executes on the server or local environment to generate and export CAD artifacts from text prompts
- JavaScript handles the browser-side viewer initialization and runtime communication
- TypeScript ensures type safety across the frontend toolchain and documentation
- GLSL performs the final pixel-level rendering of implicit models using GPU acceleration
This polyglot approach allows the repository to combine Python's strength in computational geometry with the web platform's capabilities for interactive visualization.
Summary
- Python (
packages/cadpy/src/cadpy/api.py) manages core CAD generation and export to formats like STEP, STL, and URDF - JavaScript (
packages/implicitjs/src/browser.js) runs the browser-based viewer and UI glue code - TypeScript (
docs/src/types/cadjs.d.ts) provides type-safe interfaces for the CAD library and Next.js site tooling - GLSL (
packages/implicitjs/src/lib/implicitCad/shader.glsl) powers implicit CAD rendering via signed-distance-field shaders in the browser
Frequently Asked Questions
Is text-to-CAD primarily a Python project?
No, text-to-CAD is a polyglot codebase that distributes functionality across Python, JavaScript, TypeScript, and GLSL according to the earthtojake/text-to-CAD source code. While Python handles the backend CAD generation in packages/cadpy/src/cadpy/api.py, the JavaScript/TypeScript frontend and GLSL shaders are essential for the interactive viewer experience.
What is the role of GLSL in a text-to-CAD system?
GLSL implements signed-distance-field shaders that render implicit CAD models directly in the browser without generating intermediate mesh files. The shader code in packages/implicitjs/src/lib/implicitCad/shader.glsl is compiled at runtime to enable real-time preview of generated geometry using GPU acceleration.
Does text-to-CAD use TypeScript for the backend?
No, TypeScript is used exclusively for frontend tooling, type definitions, and the Next.js documentation site. The backend CAD generation and export logic is implemented entirely in Python, as seen in packages/cadpy/src/cadpy/api.py.
Where does the browser-based CAD viewer code live?
The JavaScript runtime for the viewer is located in packages/implicitjs/src/browser.js, while the TypeScript type definitions reside in docs/src/types/cadjs.d.ts. The GLSL shaders used for rendering are stored in packages/implicitjs/src/lib/implicitCad/shader.glsl.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →