Directory Structure
The project follows a modular architecture with clear separation of concerns:Core Directories
/store
Contains the application’s global state management using Zustand:
useStore.ts: Central store managing bins, grid configuration, undo/redo history, and all application state
/components
React components for the user interface:
Toolbar.tsx: Top navigation bar with view mode controls (Solid/X-Ray/Blueprint), export buttons, and camera presetsSidebar.tsx: Left panel containing printer presets, bin list, Bill of Materials, and layout optimization toolsGridCanvas2D.tsx: Interactive SVG-based 2D grid with drag-and-drop, resize handles, collision detection, and visual feedbackBinConfigurator.tsx: Parameter editor for individual bins (dimensions, walls, dividers, features)Viewport3D.tsx: Three.js-powered 3D preview with multiple render modes and camera controls
/gridfinity
Core Gridfinity geometry generation and export logic:
constants.ts: Official Gridfinity specification values (cell size, height units, tolerances) and printer/bin presetsbinGeometry.ts: Manifold CSG operations for generating bin meshes with all features (base profile, dividers, magnet holes)baseplateGeometry.ts: Baseplate generation with socket profiles for bin interlockingprofiles.ts: 2D cross-section profiles for the Z-axis base geometryexport3mf.ts: 3MF file format packaging using JSZip and XML serialization
/hooks
React hooks for managing asynchronous operations:
useManifold.ts: Initializes and manages the Manifold WASM module lifecycleuseManifoldWorker.ts: Web Worker interface for offloading heavy CSG operations to a background thread
/workers
Background thread workers:
manifoldWorker.ts: Handles geometry generation in a separate thread to keep the UI responsive during heavy CSG operations
/utils
Utility functions and helper modules:
collision.ts: AABB (Axis-Aligned Bounding Box) collision detection for bin placement validationgridMath.ts: Coordinate system transformations between screen space and grid spacemeshToThree.ts: Converts Manifold mesh data structures to Three.js BufferGeometry
Component Hierarchy
The application follows a clear component hierarchy:Data Flow
The application uses a unidirectional data flow:- User interaction → Component event handler
- Component → Updates Zustand store
- Store → Notifies all subscribers
- Components → Re-render with new state
- For geometry changes:
- Store → Web Worker (via
useManifoldWorker) - Worker → Manifold WASM CSG generation
- Worker → Returns mesh to main thread
- Main thread → Converts to Three.js geometry
- Viewport3D → Renders updated 3D preview
- Store → Web Worker (via
Key Design Patterns
- State Management: Centralized Zustand store with undo/redo support
- Web Workers: Heavy CSG operations run off the main thread
- CSG Pipeline: Boolean operations build complex geometry from primitives
- Component Composition: Small, focused components with clear responsibilities
- Hooks Pattern: Custom hooks encapsulate complex logic (WASM, workers)
