# notforgetwyn/codex-openfoam architecture

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

- Interactive diagram: https://gitdiagram.com/notforgetwyn/codex-openfoam
- Repository: https://github.com/notforgetwyn/codex-openfoam

## Overview

1. **What this repository is**
   - FoamDesk is a **desktop CFD client** for **OpenFOAM**, not a web app.
   - The hard boundary is between the **PySide6/Qt GUI** and the **local OpenFOAM runtime** in the same WSL/Linux environment.
   - The app’s job is to wrap the OpenFOAM workflow: geometry, mesh, solver setup, execution, diagnostics, results, and reporting.

2. **Top-level architecture**
   - The code is organized into four main layers under `src/foamdesk`:
     - `app/`: startup and dependency wiring
     - `ui/`: Qt windows, tabs, and visualization widgets
     - `services/`: application use-cases and file/process orchestration
     - `integrations/`: external-system integration, mainly OpenFOAM
     - `domain/`: shared data models
   - This is a classic **UI → service → integration → filesystem/process** flow.

3. **Application bootstrap and lifecycle**
   - `src/foamdesk/app/main.py` and `bootstrap.py` are the entrypoint and composition root.
   - `StartupWindow` and `MainWindow` define the user flow: project selection first, then the main case workspace.
   - The startup layer appears to assemble services and hand them into the UI rather than letting UI code instantiate OpenFOAM logic directly.

4. **UI subsystem**
   - `src/foamdesk/ui/` is split by responsibility:
     - `main_window.py` is the central shell
     - `main_window_*_logic.py` files separate feature behavior for project, geometry, parameters, results, and settings
     - `draw_geometry_tab.py` handles geometry authoring
     - `visualization_widgets.py` contains the 3D/plot display widgets
     - `theme.py` centralizes styling
   - This suggests the UI is a **feature-based Qt shell** with isolated logic modules instead of one monolithic window class.

5. **Service layer as the main orchestration boundary**
   - `services/` contains the real application workflows:
     - `project_service.py` for project/case management
     - `geometry_import_service.py` for STL/geometry ingestion
     - `case_parameter_service.py` and `settings_service.py` for case dictionary/config state
     - `result_index_service.py` for discovering OpenFOAM result folders and time steps
     - `residual_plot_service.py` and `log_metric_service.py` for solver-quality signals
     - `log_diagnostic_service.py` for translating raw OpenFOAM logs into user-facing diagnoses
     - `metric_export_service.py` and `report_export_service.py` for exports
     - `openfoam_vtk_service.py` for loading simulation outputs into visualization-ready data
   - These services are the key architectural boundary between UI actions and filesystem/OpenFOAM side effects.

6. **OpenFOAM integration**
   - `src/foamdesk/integrations/openfoam/environment.py` is the main integration point for the external runtime.
   - The README indicates commands are run locally via **`bash -lc` / OpenFOAM bashrc sourcing**, inside the same WSL/Linux environment.
   - This is important architecturally: FoamDesk does not call a remote API; it shells out to the installed OpenFOAM toolchain and works against generated case directories.

7. **Domain and case data**
   - `domain/models.py` holds the core data structures shared across UI and services.
   - The application is case-centric: each project contains one or more **OpenFOAM cases**, and each case owns its geometry, dictionaries, logs, and results.
   - The data model likely captures project metadata, case parameters, geometry placement, solver selection, and result indexing.

8. **Filesystem as the primary persistence layer**
   - The app is built around a local workspace model, not a database.
   - Runtime state lives in project/case directories: generated dictionaries, solver inputs, logs, result folders, and exported artifacts.
   - The checked-in `assets/test_geometries/` folder provides sample STL/CSV geometry inputs for development and testing.
   - Files like `foamdesk_run.log`, `foamdesk_debug.log`, and `report.md` show the repo also produces operational artifacts and exportable reports.

9. **Geometry and preprocessing flow**
   - Geometry can come from **CSV-based primitives** or **imported STL meshes**.
   - The preprocessing path centers on generating OpenFOAM-ready geometry and mesh setup, including `snappyHexMeshDict`, then running `blockMesh`, `snappyHexMesh`, and `checkMesh`.
   - The design implies a clear split between **geometry authoring/import** and **mesh-generation orchestration**.

10. **Results and visualization flow**
   - Result handling is split into:
     - indexing available OpenFOAM output
     - loading field data
     - rendering in embedded 3D widgets
     - plotting residuals and metrics
   - The README and services suggest the visualization stack uses **VTK** for 3D field data and **Matplotlib** for residual/metric plots.
   - This is an internal post-processing boundary: the app does not rely on ParaView as its primary UI.

11. **Diagnostics and reporting**
   - Raw solver output is not just displayed; it is parsed for **common OpenFOAM failure modes** and converted into Chinese-language guidance.
   - Reporting is a separate export path, likely turning selected plots/images and run metadata into Markdown or image assets.
   - This makes logs, metrics, and report generation a distinct subsystem rather than a UI-only feature.

12. **Testing and quality boundaries**
   - `tests/unit/` focuses on service and integration behavior, especially:
     - environment setup
     - project/case management
     - log diagnostics
     - metric extraction/export
     - result indexing
     - residual plotting
     - VTK loading
   - That test shape reinforces the architecture: most logic is expected to be in services and integration adapters, not in the UI.

13. **Relevant technology footprint**
   - Core runtime: **Python 3**
   - Desktop UI: **PySide6 / Qt**
   - Numerical/data handling: **NumPy**, **SciPy**
   - 2D plotting: **Matplotlib**
   - 3D field/result handling: **VTK**
   - Execution environment: **WSL/Linux with local OpenFOAM installation**
   - Persistence: **filesystem + local JSON/config-like artifacts**, not a server or database

14. **How to draw the system**
   - Draw the UI as the entry point on top.
   - Put a central service layer beneath it with project, geometry, case-parameter, result, diagnostic, and export services.
   - Draw OpenFOAM integration as a separate boundary below services, reached via local process execution.
   - Show the filesystem/workspace as the main storage backend for cases, generated dictionaries, logs, and results.
   - Add a side path from result services into VTK/Matplotlib-based visualization and report export.

Main entry points: [`src/foamdesk/ui/main_window_results_logic.py`](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_results_logic.py) (Results Logic), [`src/foamdesk/domain/models.py`](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/domain/models.py) (Models), [`src/foamdesk/ui/main_window.py`](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window.py) (Main Window), [`src/foamdesk/integrations/openfoam/environment.py`](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/integrations/openfoam/environment.py) (OpenFOAM Env)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App"]
  node_app_main["Main<br/>entrypoint<br/>[main.py]"]
  node_app_bootstrap["Bootstrap<br/>composition root<br/>[bootstrap.py]"]
end

subgraph group_ui["UI"]
  node_startup_window["Startup<br/>qt window<br/>[startup_window.py]"]
  node_main_window["Main Window<br/>qt shell<br/>[main_window.py]"]
  node_geometry_tab["Geometry Tab<br/>ui feature"]
  node_viz_widgets["Viz Widgets<br/>view widgets"]
  node_project_logic["Project Logic<br/>ui controller"]
  node_geometry_logic["Geometry Logic<br/>ui controller"]
  node_parameters_logic["Parameters Logic<br/>ui controller"]
  node_results_logic["Results Logic<br/>ui controller"]
  node_physics_logic["Physics Logic<br/>ui controller"]
end

subgraph group_services["Services"]
  node_project_service["Project Service<br/>workflow service<br/>[project_service.py]"]
  node_geometry_service["Geometry Import<br/>workflow service"]
  node_case_params_service["Case Params<br/>workflow service"]
  node_result_index_service["Result Index<br/>workflow service"]
  node_log_diag_service["Diagnostics<br/>workflow service"]
  node_metric_export_service["Metric Export<br/>export service"]
  node_report_export_service["Report Export<br/>export service"]
  node_vtk_service["VTK Loader<br/>data service"]
end

subgraph group_integrations["Integrations"]
  node_openfoam_env["OpenFOAM Env<br/>runtime adapter<br/>[environment.py]"]
end

subgraph group_domain["Domain"]
  node_models["Models<br/>[models.py]"]
end

subgraph group_workspace["Workspace"]
  node_workspace_fs[("Workspace Files<br/>filesystem")]
end

node_app_main -->|"starts"| node_app_bootstrap
node_app_bootstrap -->|"creates"| node_startup_window
node_app_bootstrap -->|"injects"| node_main_window
node_startup_window -->|"selects project"| node_project_logic
node_main_window -->|"hosts"| node_project_logic
node_main_window -->|"hosts"| node_geometry_logic
node_main_window -->|"hosts"| node_parameters_logic
node_main_window -->|"hosts"| node_results_logic
node_main_window -->|"hosts"| node_physics_logic
node_geometry_logic -->|"drives"| node_geometry_tab
node_results_logic -->|"renders"| node_viz_widgets
node_project_logic -->|"uses"| node_project_service
node_geometry_logic -->|"uses"| node_geometry_service
node_parameters_logic -->|"uses"| node_case_params_service
node_results_logic -->|"uses"| node_result_index_service
node_results_logic -->|"uses"| node_log_diag_service
node_results_logic -->|"uses"| node_metric_export_service
node_results_logic -->|"uses"| node_report_export_service
node_results_logic -->|"uses"| node_vtk_service
node_project_service -->|"reads/writes"| node_models
node_geometry_service -->|"reads/writes"| node_models
node_case_params_service -->|"reads/writes"| node_models
node_result_index_service -->|"reads/writes"| node_models
node_log_diag_service -->|"reads"| node_models
node_metric_export_service -->|"reads"| node_models
node_report_export_service -->|"reads"| node_models
node_vtk_service -->|"reads"| node_models
node_project_service -->|"manages"| node_workspace_fs
node_geometry_service -->|"writes"| node_workspace_fs
node_case_params_service -->|"writes"| node_workspace_fs
node_result_index_service -->|"scans"| node_workspace_fs
node_log_diag_service -->|"reads"| node_workspace_fs
node_metric_export_service -->|"writes"| node_workspace_fs
node_report_export_service -->|"writes"| node_workspace_fs
node_vtk_service -->|"reads"| node_workspace_fs
node_geometry_service -->|"executes"| node_openfoam_env
node_case_params_service -->|"executes"| node_openfoam_env
node_result_index_service -->|"queries"| node_openfoam_env
node_log_diag_service -->|"parses"| node_openfoam_env
node_vtk_service -->|"loads via"| node_openfoam_env

click node_app_main "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/app/main.py"
click node_app_bootstrap "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/app/bootstrap.py"
click node_startup_window "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/startup_window.py"
click node_main_window "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window.py"
click node_geometry_tab "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/draw_geometry_tab.py"
click node_viz_widgets "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/visualization_widgets.py"
click node_project_logic "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_project_logic.py"
click node_geometry_logic "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_geometry_logic.py"
click node_parameters_logic "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_parameters_logic.py"
click node_results_logic "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_results_logic.py"
click node_physics_logic "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_settings_physics_logic.py"
click node_project_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/project_service.py"
click node_geometry_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/geometry_import_service.py"
click node_case_params_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/case_parameter_service.py"
click node_result_index_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/result_index_service.py"
click node_log_diag_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/log_diagnostic_service.py"
click node_metric_export_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/metric_export_service.py"
click node_report_export_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/report_export_service.py"
click node_vtk_service "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/openfoam_vtk_service.py"
click node_openfoam_env "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/integrations/openfoam/environment.py"
click node_models "https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/domain/models.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_app_main,node_app_bootstrap toneBlue
class node_startup_window,node_main_window,node_geometry_tab,node_viz_widgets,node_project_logic,node_geometry_logic,node_parameters_logic,node_results_logic,node_physics_logic toneAmber
class node_project_service,node_geometry_service,node_case_params_service,node_result_index_service,node_log_diag_service,node_metric_export_service,node_report_export_service,node_vtk_service toneMint
class node_openfoam_env toneRose
class node_models toneIndigo
class node_workspace_fs toneTeal
```

## Components

### App

Startup and dependency wiring

- [Main](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/app/main.py): entrypoint · Application entrypoint · `src/foamdesk/app/main.py`
- [Bootstrap](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/app/bootstrap.py): composition root · Wires services and UI together · `src/foamdesk/app/bootstrap.py`

### UI

Qt windows, tabs, and visualization

- [Startup](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/startup_window.py): qt window · Project selection and initial flow · `src/foamdesk/ui/startup_window.py`
- [Main Window](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window.py): qt shell · Primary case workspace shell · `src/foamdesk/ui/main_window.py`
- [Geometry Tab](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/draw_geometry_tab.py): ui feature · Geometry authoring and import entry · `src/foamdesk/ui/draw_geometry_tab.py`
- [Viz Widgets](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/visualization_widgets.py): view widgets · 3D and plotting displays · `src/foamdesk/ui/visualization_widgets.py`
- [Project Logic](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_project_logic.py): ui controller · Project and case actions · `src/foamdesk/ui/main_window_project_logic.py`
- [Geometry Logic](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_geometry_logic.py): ui controller · Geometry workflow actions · `src/foamdesk/ui/main_window_geometry_logic.py`
- [Parameters Logic](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_parameters_logic.py): ui controller · Case parameter and settings actions · `src/foamdesk/ui/main_window_parameters_logic.py`
- [Results Logic](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_results_logic.py): ui controller · Results inspection and export actions · `src/foamdesk/ui/main_window_results_logic.py`
- [Physics Logic](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/ui/main_window_settings_physics_logic.py): ui controller · Physics and settings actions · `src/foamdesk/ui/main_window_settings_physics_logic.py`

### Services

Workflow orchestration and file/process use cases

- [Project Service](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/project_service.py): workflow service · Project and case lifecycle · `src/foamdesk/services/project_service.py`
- [Geometry Import](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/geometry_import_service.py): workflow service · STL and primitive geometry ingestion · `src/foamdesk/services/geometry_import_service.py`
- [Case Params](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/case_parameter_service.py): workflow service · Case dictionaries and parameter state · `src/foamdesk/services/case_parameter_service.py`
- [Result Index](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/result_index_service.py): workflow service · Discovers result folders and time steps · `src/foamdesk/services/result_index_service.py`
- [Diagnostics](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/log_diagnostic_service.py): workflow service · Parses solver logs into guidance · `src/foamdesk/services/log_diagnostic_service.py`
- [Metric Export](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/metric_export_service.py): export service · Exports solver metrics · `src/foamdesk/services/metric_export_service.py`
- [Report Export](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/report_export_service.py): export service · Builds report artifacts · `src/foamdesk/services/report_export_service.py`
- [VTK Loader](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/services/openfoam_vtk_service.py): data service · Loads field data for visualization · `src/foamdesk/services/openfoam_vtk_service.py`

### Integrations

External runtime adapters

- [OpenFOAM Env](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/integrations/openfoam/environment.py): runtime adapter · Local bash-sourced OpenFOAM execution · `src/foamdesk/integrations/openfoam/environment.py`

### Domain

Shared data models

- [Models](https://github.com/notforgetwyn/codex-openfoam/blob/main/src/foamdesk/domain/models.py): data models · Shared project and case structures · `src/foamdesk/domain/models.py`

### Workspace

Local case files and generated artifacts

- **Workspace Files**: filesystem · Cases, dictionaries, logs, results, exports

## Connections

- Main → Bootstrap: starts · Launches composition root
- Bootstrap → Startup: creates · Builds initial UI flow
- Bootstrap → Main Window: injects · Provides services to main shell
- Startup → Project Logic: selects project · Project selection and case entry
- Main Window → Project Logic: hosts · Project and case actions
- Main Window → Geometry Logic: hosts · Geometry workflow actions
- Main Window → Parameters Logic: hosts · Parameter and settings actions
- Main Window → Results Logic: hosts · Results and export actions
- Main Window → Physics Logic: hosts · Physics and settings actions
- Geometry Logic → Geometry Tab: drives · Geometry authoring UI
- Results Logic → Viz Widgets: renders · 3D and plot presentation
- Project Logic → Project Service: uses · Project lifecycle orchestration
- Geometry Logic → Geometry Import: uses · Imports and prepares geometry
- Parameters Logic → Case Params: uses · Case parameter editing
- Results Logic → Result Index: uses · Finds available outputs
- Results Logic → Diagnostics: uses · Turns logs into diagnostics
- Results Logic → Metric Export: uses · Exports metric data
- Results Logic → Report Export: uses · Exports report artifacts
- Results Logic → VTK Loader: uses · Loads simulation fields
- Project Service → Models: reads/writes · Shares case and project state
- Geometry Import → Models: reads/writes · Shares geometry state
- Case Params → Models: reads/writes · Shares case parameter state
- Result Index → Models: reads/writes · Uses case metadata for discovery
- Diagnostics → Models: reads · Interprets runs in domain terms
- Metric Export → Models: reads · Exports case metrics
- Report Export → Models: reads · Builds reports from case data
- VTK Loader → Models: reads · Maps case outputs to field data
- Project Service → Workspace Files: manages · Creates and opens project folders
- Geometry Import → Workspace Files: writes · Generates geometry and mesh inputs
- Case Params → Workspace Files: writes · Persists OpenFOAM dictionaries
- Result Index → Workspace Files: scans · Discovers result directories and times
- Diagnostics → Workspace Files: reads · Consumes solver logs
- Metric Export → Workspace Files: writes · Exports metrics files
- Report Export → Workspace Files: writes · Creates report artifacts
- VTK Loader → Workspace Files: reads · Loads result files
- Geometry Import → OpenFOAM Env: executes · Runs OpenFOAM mesh tools locally
- Case Params → OpenFOAM Env: executes · Writes and validates case setup
- Result Index → OpenFOAM Env: queries · Inspects runtime output layout
- Diagnostics → OpenFOAM Env: parses · Reads solver command output
- VTK Loader → OpenFOAM Env: loads via · Uses OpenFOAM result conventions
