# younghyopark/mjfit architecture

> Architecture diagram of the GitHub repository younghyopark/mjfit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/younghyopark/mjfit
- Repository: https://github.com/younghyopark/mjfit

## Overview

mjfit generates exact convex collision geometry as MJCF for MuJoCo, covering peg-and-hole assemblies, threaded parts, and gears. Users can start through the CLI or Python API, supply configs or parameters, and receive MJCF; sampling and scene composition support batches of assemblies. The graph also shows the shared polygon kernel and MJCF writer. Several source modules are represented from the SOURCE INDEX and README rather than inspected excerpts, so their internal calls are omitted where evidence is limited.

Main entry points: [`src/mjfit/__init__.py`](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/__init__.py) (Python API), [`src/mjfit/_peg.py`](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_peg.py) (Peg generator), [`src/mjfit/_polygon.py`](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_polygon.py) (Polygon kernel), [`src/mjfit/_thread.py`](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_thread.py) (Thread generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI<br/>[cli.py]"]
  node_api["Python API<br/>[__init__.py]"]
end

subgraph group_configuration["Configuration and sampling"]
  node_configs["Config loader<br/>[_config.py]"]
  node_sampler["Peg sampler<br/>[_sample.py]"]
end

subgraph group_geometry["Geometry kernel"]
  node_shapes["Shape outlines<br/>[shapes.py]"]
  node_polygon["Polygon kernel<br/>[_polygon.py]"]
end

subgraph group_generators["Assembly generators"]
  node_peg["Peg generator<br/>[_peg.py]"]
  node_thread["Thread generator<br/>[_thread.py]"]
  node_gear["Gear generator<br/>[_gear.py]"]
end

subgraph group_output["Model output"]
  node_mjcf["MJCF writer<br/>[_mjcf.py]"]
  node_scene["Scene grid<br/>[_scene.py]"]
  node_xml["MJCF model"]
end

node_user(("User"))
node_mujoco["MuJoCo"]

node_user -->|"runs command"| node_cli
node_user -->|"calls generator"| node_api
node_cli -->|"loads config"| node_configs
node_cli -->|"builds model"| node_api
node_api -->|"loads config"| node_configs
node_api -->|"dispatches"| node_peg
node_api -->|"dispatches"| node_thread
node_api -->|"dispatches"| node_gear
node_api -->|"exposes sampling"| node_sampler
node_sampler -->|"creates outlines"| node_shapes
node_sampler -->|"checks offsets"| node_polygon
node_shapes -->|"uses geometry"| node_polygon
node_peg -->|"parses outlines"| node_shapes
node_peg -->|"decomposes geometry"| node_polygon
node_peg -->|"builds model"| node_mjcf
node_thread -->|"uses geometry"| node_polygon
node_thread -->|"builds model"| node_mjcf
node_gear -->|"uses geometry"| node_polygon
node_gear -->|"builds model"| node_mjcf
node_scene -->|"uses constants"| node_mjcf
node_peg -->|"emits MJCF"| node_xml
node_thread -->|"emits MJCF"| node_xml
node_gear -->|"emits MJCF"| node_xml
node_scene -->|"combines models"| node_xml
node_xml -->|"loads model"| node_mujoco

click node_cli "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/cli.py"
click node_api "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/__init__.py"
click node_configs "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_config.py"
click node_sampler "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_sample.py"
click node_shapes "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/shapes.py"
click node_polygon "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_polygon.py"
click node_peg "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_peg.py"
click node_thread "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_thread.py"
click node_gear "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_gear.py"
click node_mjcf "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_mjcf.py"
click node_scene "https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_scene.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_api,node_user toneBlue
class node_configs,node_sampler toneAmber
class node_shapes,node_polygon toneMint
class node_peg,node_thread,node_gear toneRose
class node_mjcf,node_scene,node_xml,node_mujoco toneIndigo
```

## Components

### User interfaces

- [CLI](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/cli.py): `src/mjfit/cli.py`
- [Python API](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/__init__.py): `src/mjfit/__init__.py`

### Configuration and sampling

- [Config loader](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_config.py): `src/mjfit/_config.py`
- [Peg sampler](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_sample.py): `src/mjfit/_sample.py`

### Geometry kernel

- [Shape outlines](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/shapes.py): `src/mjfit/shapes.py`
- [Polygon kernel](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_polygon.py): `src/mjfit/_polygon.py`

### Assembly generators

- [Peg generator](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_peg.py): `src/mjfit/_peg.py`
- [Thread generator](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_thread.py): `src/mjfit/_thread.py`
- [Gear generator](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_gear.py): `src/mjfit/_gear.py`

### Model output

- [MJCF writer](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_mjcf.py): `src/mjfit/_mjcf.py`
- [Scene grid](https://github.com/younghyopark/mjfit/blob/main/src/mjfit/_scene.py): `src/mjfit/_scene.py`
- **MJCF model**

### Other components

- **User**
- **MuJoCo**

## Connections

- User → CLI: runs command (evidence: `README.md`)
- User → Python API: calls generator (evidence: `README.md`)
- CLI → Config loader: loads config (evidence: `src/mjfit/cli.py`)
- CLI → Python API: builds model (evidence: `src/mjfit/cli.py`)
- Python API → Config loader: loads config (evidence: `src/mjfit/__init__.py`)
- Python API → Peg generator: dispatches (evidence: `src/mjfit/__init__.py`)
- Python API → Thread generator: dispatches (evidence: `src/mjfit/__init__.py`)
- Python API → Gear generator: dispatches (evidence: `src/mjfit/__init__.py`)
- Python API → Peg sampler: exposes sampling (evidence: `src/mjfit/__init__.py`)
- Peg sampler → Shape outlines: creates outlines (evidence: `src/mjfit/_sample.py`)
- Peg sampler → Polygon kernel: checks offsets (evidence: `src/mjfit/_sample.py`)
- Shape outlines → Polygon kernel: uses geometry (evidence: `src/mjfit/shapes.py`)
- Peg generator → Shape outlines: parses outlines (evidence: `src/mjfit/_peg.py`)
- Peg generator → Polygon kernel: decomposes geometry (evidence: `src/mjfit/_peg.py`)
- Peg generator → MJCF writer: builds model (evidence: `src/mjfit/_peg.py`)
- Thread generator → Polygon kernel: uses geometry (evidence: `src/mjfit/_thread.py`)
- Thread generator → MJCF writer: builds model (evidence: `src/mjfit/_thread.py`)
- Gear generator → Polygon kernel: uses geometry (evidence: `src/mjfit/_gear.py`)
- Gear generator → MJCF writer: builds model (evidence: `src/mjfit/_gear.py`)
- Scene grid → MJCF writer: uses constants (evidence: `src/mjfit/_scene.py`)
- Peg generator → MJCF model: emits MJCF (evidence: `README.md`)
- Thread generator → MJCF model: emits MJCF (evidence: `README.md`)
- Gear generator → MJCF model: emits MJCF (evidence: `README.md`)
- Scene grid → MJCF model: combines models (evidence: `src/mjfit/_scene.py`)
- MJCF model → MuJoCo: loads model (evidence: `README.md`)
