ConstructCraft

API reference: overview

Português · Full reference by crate

This page explains how ConstructCraft’s code is organized and where its main types live. The full reference lists, crate by crate and module by module, every item that is not private: functions, structs, enums, traits, type aliases, constants and re-exports, with their signatures and documentation, the fields of structs, the variants of enums, the methods of each type and the traits each type implements. It is generated from the source code by cargo run -p api_doc (tools/api_doc), so it always says what the doc comments say; to change it, edit the comments and run the generator again.

If you want to use ConstructCraft from outside (scripts, the command line, AI agents), the command reference and the automation guide are what you need: commands are the stable interface. This reference is for people working on the code itself.

Classes and inheritance in Rust

ConstructCraft is written in Rust, which has no classes and no inheritance. The same ideas are expressed with other building blocks, and the reference is organized around them:

Object-oriented idea In Rust In this reference
Class with fields struct struct, with its Fields
Class hierarchy with a closed set of subclasses enum whose variants carry data enum, with its Variants
Methods functions in impl Type { … } blocks, which may live in any module of the crate Methods of the type; (in module) says where a method is defined when it is not the type’s own module
Interface / abstract base class trait trait, with its Required and provided items and Implemented by
Inheriting an interface a supertrait: trait Command: DeserializeOwned + JsonSchema the trait’s signature
Implementing an interface impl Trait for Type Traits of the type
Generated standard behaviour #[derive(Clone, Debug, Serialize, …)] also listed under Traits
Static members associated functions (no self) and associated constants under Methods

Two patterns stand in for inheritance throughout the code:

Crates

The code is a Cargo workspace of crates, each a library (or a program) with a single responsibility. Each crate uses only those listed before it in this order, so cc_core depends on no other crate and nothing depends on cc_app:

Crate Uses (workspace crates)
cc_core —
cc_skp —
cc_script cc_core
cc_cad cc_core
cc_geom cc_core, cc_script
cc_views, cc_ifc, cc_render cc_core, cc_geom
cc_raytracing cc_core, cc_geom, cc_views
cc_engine cc_core, cc_cad, cc_geom, cc_ifc, cc_raytracing, cc_script, cc_skp, cc_views
cc_plugins cc_engine, cc_script, cc_skp
cc_cli cc_core, cc_engine, cc_plugins
cc_app cc_core, cc_engine, cc_geom, cc_ifc, cc_plugins, cc_raytracing, cc_render, cc_script, cc_views

What each crate holds:

Crate What it holds Main types
cc_core The BIM model, the single source of truth: project, levels, materials, types, elements, views, undo/redo, files. Knows nothing of geometry or UI. Project, Element, ElementKind, ElementType, TypeData, View, ViewKind, Document, EditCtx, Transaction, ComponentDef, Sketch, ScheduleDef
cc_geom Geometry derived from the model, rebuilt when it changes: wall joins, solids, roofs, rooms, structure, reinforcement, MEP networks, terrain. ModelGeometry, WallGeom, Solid
cc_views Views as queries over the model: plans, elevations, sections, schedules, sheets, annotations; export to SVG, PDF, PNG and DXF. generate, Drawing2D, Resolver
cc_render The 3D view’s GPU renderer (wgpu). Renderer3D
cc_raytracing Photorealistic rendering on the CPU (path tracing). RenderScene
cc_ifc IFC export and import, with its own STEP reader and writer.  
cc_cad Reading DXF, DWG and SVG drawings into the model’s neutral drawing. CadDrawing (in cc_core)
cc_skp Reading and writing SketchUp files, with no external dependencies. SkpFile
cc_script The sandboxed Lua 5.4 used by scripted components and plugins.  
cc_engine The engine: a session and the catalog of commands every client calls; visual programming graphs; localization. Session, Command, EngineError, Graph, Evaluator
cc_plugins Lua scripts and plugins over the engine. PluginHost
cc_cli The ccad program: commands, scripts and the MCP server, without a GUI.  
cc_app The desktop application (egui). AppState, UiCommand, Tool

How an edit flows through the code

  1. A client (the app, ccad, the MCP server, a Lua script or a graph) asks the Session to run a command by name with JSON parameters, or a typed command struct.
  2. The command’s run (the Command trait) resolves its references (levels, types and views by id or name) and edits the model through commands::edit, which calls Document::try_edit.
  3. Inside the edit, an EditCtx changes the Project; when it finishes, EditCtx::finish keeps derived data in step (dimensions, attachments, piles, shafts, member hosts, phases, design options, view templates…) and the result passes the repair check. A command that would leave the model invalid is refused without an undo step; otherwise the change is recorded as one reversible Transaction.
  4. The document’s revision changes, so ModelGeometry::build (cc_geom) rebuilds the geometry and cc_views::generate redraws the views that are shown, each as a Drawing2D; the 3D view goes to Renderer3D.

Conventions you will meet in the reference