# chriswu1997/deepcad architecture

> Architecture diagram of the GitHub repository chriswu1997/deepcad, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chriswu1997/deepcad
- Repository: https://github.com/chriswu1997/deepcad

## Overview

##### Project type and purpose
- DeepCAD is a research‐oriented deep learning toolbox for generative modeling of CAD construction sequences.

##### File structure
- Top‐level scripts:
- train.py (AE training)
- lgan.py (LGAN training & testing)
- test.py (AE encode/decode/inference)
- pc2cad.py / pc2cad_train.py (point cloud to CAD sequence translation)
- evaluation/run_eval_gen.sh and evaluation/*.py (evaluation pipeline)
- utils/ (visualization & export helpers)
- Core library modules:
- cadlib/ – CAD geometry utilities (curves, extrusions, visualization via pythonocc)
- dataset/ – data ingestion & preprocessing (json→vector, json→point cloud, custom PyTorch Dataset classes)
- model/ – network architectures (autoencoder, latentGAN, transformer‐style layers, attention)
- trainer/ – training loop abstractions (base trainer, AE trainer, LGAN trainer, schedulers, loss functions)
- config/ – experiment hyperparameters and model settings (configAE.py, configLGAN.py)
- Dependencies and environment files: requirements.txt, pythonocc via conda.

##### README for insights
- Uses PyTorch 1.5+, CUDA/CuDNN, pythonocc‐core.

##### Detailed capture of architectural elements
- Break out submodules within model (transformer layers, attention).
- Trainer as a wrapper that calls model + loss + scheduler + optimizer.
- Config manager feeding hyperparameters into both train.py and lgan.py.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer" 
        direction TB
        RawCADJSON(("Raw CAD JSON")):::data
        VecFile(("Vectorized CAD (.vec)")):::data
        PCFile(("Point Clouds (H5)")):::data
        RawCADJSON -->|json2vec| JSON2VEC["json2vec"]:::processing
        RawCADJSON -->|json2pc| JSON2PC["json2pc"]:::processing
        JSON2VEC --> CADDATA["CADDataset"]:::data
        JSON2PC --> LGANDATA["LGANDataset"]:::data
    end

    %% CAD Utility Library
    subgraph "CAD Utility Library" 
        direction TB
        CADLIB["cadlib"]:::lib
        Curves["curves.py"]:::lib
        Extrude["extrude.py"]:::lib
        Macro["macro.py"]:::lib
        MathUtils["math_utils.py"]:::lib
        Sketch["sketch.py"]:::lib
        VisualizeLib["visualize.py"]:::lib
        CADLIB --> Curves
        CADLIB --> Extrude
        CADLIB --> Macro
        CADLIB --> MathUtils
        CADLIB --> Sketch
        CADLIB --> VisualizeLib
    end

    %% Configuration Manager
    subgraph "Configuration Manager"
        direction TB
        ConfigAE["configAE.py"]:::config
        ConfigLGAN["configLGAN.py"]:::config
    end

    %% Model Components
    subgraph "Model Components"
        direction TB
        Autoencoder["autoencoder.py"]:::model
        LatentGAN["latentGAN.py"]:::model
        ModelUtils["model_utils.py"]:::model
        Attention["attention.py"]:::model
        Functional["functional.py"]:::model
        ImpTransformer["improved_transformer.py"]:::model
        PosEnc["positional_encoding.py"]:::model
        Transformer["transformer.py"]:::model
        LayersUtils["utils.py"]:::model
    end

    %% Trainer Framework
    subgraph "Trainer Framework"
        direction TB
        BaseTrainer["base.py"]:::trainer
        Losses["loss.py"]:::trainer
        Schedulers["scheduler.py"]:::trainer
        TrainerAE["trainerAE.py"]:::trainer
        TrainerLGAN["trainerLGAN.py"]:::trainer
    end

    %% Orchestration Scripts
    subgraph "Orchestration Scripts"
        direction TB
        TrainAE[/train.py/]:::script
        LGANScript[/lgan.py/]:::script
        TestScript[/test.py/]:::script
        PC2CAD[/pc2cad.py/]:::script
        PC2CADTrain[/pc2cad_train.py/]:::script
    end

    %% Evaluation Suite
    subgraph "Evaluation Suite"
        direction TB
        EvalCollect[/collect_gen_pc.py/]:::eval
        EvalAEAcc[/evaluate_ae_acc.py/]:::eval
        EvalAECD[/evaluate_ae_cd.py/]:::eval
        EvalGenTorch[/evaluate_gen_torch.py/]:::eval
        RunEval[/run_eval_gen.sh/]:::eval
    end

    %% Visualization & Export
    subgraph "Visualization & Export"
        direction TB
        Show[/show.py/]:::viz
        Export2STEP[/export2step.py/]:::viz
        FileUtils["file_utils.py"]:::viz
        PCUtils["pc_utils.py"]:::viz
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        Req["requirements.txt"]:::external
        Readme["README.md"]:::external
        License["LICENSE"]:::external
        PythonOcc(["pythonocc-core"]):::external
        Req --> PythonOcc
    end

    %% Data Flow Pipelines
    CADDATA -->|to TrainerAE| TrainerAE
    LGANDATA -->|to TrainerLGAN| TrainerLGAN
    ConfigAE -->|params| TrainerAE
    ConfigLGAN -->|params| TrainerLGAN
    TrainerAE -->|latent codes| VecFile
    VecFile --> TrainerLGAN
    TrainerLGAN -->|fake codes| Autoencoder
    Autoencoder -->|reconstruct| RawCADJSON

    %% Evaluation Flow
    VecFile -->|input| EvalAEAcc
    VecFile -->|input| EvalAECD
    TrainerLGAN -->|generated data| EvalCollect
    EvalCollect --> EvalGenTorch
    RunEval --> EvalGenTorch

    %% Visualization Flow
    RawCADJSON --> Show
    RawCADJSON --> Export2STEP

    %% Dependencies
    CADLIB -->|uses| PythonOcc
    Show -->|uses| PythonOcc

    %% Click Events
    click JSON2VEC "https://github.com/chriswu1997/deepcad/blob/master/dataset/json2vec.py"
    click JSON2PC "https://github.com/chriswu1997/deepcad/blob/master/dataset/json2pc.py"
    click CADDATA "https://github.com/chriswu1997/deepcad/blob/master/dataset/cad_dataset.py"
    click LGANDATA "https://github.com/chriswu1997/deepcad/blob/master/dataset/lgan_dataset.py"
    click CADLIB "https://github.com/chriswu1997/deepcad/tree/master/cadlib/"
    click Curves "https://github.com/chriswu1997/deepcad/blob/master/cadlib/curves.py"
    click Extrude "https://github.com/chriswu1997/deepcad/blob/master/cadlib/extrude.py"
    click Macro "https://github.com/chriswu1997/deepcad/blob/master/cadlib/macro.py"
    click MathUtils "https://github.com/chriswu1997/deepcad/blob/master/cadlib/math_utils.py"
    click Sketch "https://github.com/chriswu1997/deepcad/blob/master/cadlib/sketch.py"
    click VisualizeLib "https://github.com/chriswu1997/deepcad/blob/master/cadlib/visualize.py"
    click ConfigAE "https://github.com/chriswu1997/deepcad/blob/master/config/configAE.py"
    click ConfigLGAN "https://github.com/chriswu1997/deepcad/blob/master/config/configLGAN.py"
    click Autoencoder "https://github.com/chriswu1997/deepcad/blob/master/model/autoencoder.py"
    click LatentGAN "https://github.com/chriswu1997/deepcad/blob/master/model/latentGAN.py"
    click ModelUtils "https://github.com/chriswu1997/deepcad/blob/master/model/model_utils.py"
    click Attention "https://github.com/chriswu1997/deepcad/blob/master/model/layers/attention.py"
    click Functional "https://github.com/chriswu1997/deepcad/blob/master/model/layers/functional.py"
    click ImpTransformer "https://github.com/chriswu1997/deepcad/blob/master/model/layers/improved_transformer.py"
    click PosEnc "https://github.com/chriswu1997/deepcad/blob/master/model/layers/positional_encoding.py"
    click Transformer "https://github.com/chriswu1997/deepcad/blob/master/model/layers/transformer.py"
    click LayersUtils "https://github.com/chriswu1997/deepcad/blob/master/model/layers/utils.py"
    click BaseTrainer "https://github.com/chriswu1997/deepcad/blob/master/trainer/base.py"
    click Losses "https://github.com/chriswu1997/deepcad/blob/master/trainer/loss.py"
    click Schedulers "https://github.com/chriswu1997/deepcad/blob/master/trainer/scheduler.py"
    click TrainerAE "https://github.com/chriswu1997/deepcad/blob/master/trainer/trainerAE.py"
    click TrainerLGAN "https://github.com/chriswu1997/deepcad/blob/master/trainer/trainerLGAN.py"
    click TrainAE "https://github.com/chriswu1997/deepcad/blob/master/train.py"
    click LGANScript "https://github.com/chriswu1997/deepcad/blob/master/lgan.py"
    click TestScript "https://github.com/chriswu1997/deepcad/blob/master/test.py"
    click PC2CAD "https://github.com/chriswu1997/deepcad/blob/master/pc2cad.py"
    click PC2CADTrain "https://github.com/chriswu1997/deepcad/blob/master/pc2cad_train.py"
    click EvalCollect "https://github.com/chriswu1997/deepcad/blob/master/evaluation/collect_gen_pc.py"
    click EvalAEAcc "https://github.com/chriswu1997/deepcad/blob/master/evaluation/evaluate_ae_acc.py"
    click EvalAECD "https://github.com/chriswu1997/deepcad/blob/master/evaluation/evaluate_ae_cd.py"
    click EvalGenTorch "https://github.com/chriswu1997/deepcad/blob/master/evaluation/evaluate_gen_torch.py"
    click RunEval "https://github.com/chriswu1997/deepcad/blob/master/evaluation/run_eval_gen.sh"
    click Show "https://github.com/chriswu1997/deepcad/blob/master/utils/show.py"
    click Export2STEP "https://github.com/chriswu1997/deepcad/blob/master/utils/export2step.py"
    click FileUtils "https://github.com/chriswu1997/deepcad/blob/master/utils/file_utils.py"
    click PCUtils "https://github.com/chriswu1997/deepcad/blob/master/utils/pc_utils.py"

    %% Styles
    classDef data fill:#D0E4F5,stroke:#3178C6,color:#000
    classDef processing fill:#DFF2E1,stroke:#3B8F3B,color:#000
    classDef lib fill:#E8F0FE,stroke:#2A56C6,color:#000
    classDef config fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef model fill:#FFEFD5,stroke:#FFA500,color:#000
    classDef trainer fill:#FFDADA,stroke:#D9534F,color:#000
    classDef script fill:#FFF5BA,stroke:#F0AD4E,color:#000
    classDef eval fill:#E6E0F8,stroke:#6A0DAD,color:#000
    classDef viz fill:#F3E5F5,stroke:#9C27B0,color:#000
    classDef external fill:#F0F0F0,stroke:#A0A0A0,color:#000
```
