FOAMFlask is an attempt to make a yet another lightweight web-based GUI for managing and running OpenFOAM tutorials and simulations. It allows users to easily select a tutorial, set a case directory, and execute OpenFOAM commands directly from a browser. Since this is targeted for beginners, the documentation has been kept as extensive as possible.
Important
- Currently only loading and execution of OpenFOAM tutorials (
$FOAM_TUTORIALS) is supported. Creating custom cases is planned. - Always edit files in
static/ts/directory, never directly instatic/js/. Thestatic/js/files are overwritten during the build process.
- Web interface for OpenFOAM case management.
- Persistently store the CASE_ROOT across sessions.
- Load and copy tutorials from the OpenFOAM tutorials directory.
- Run common OpenFOAM commands (
blockMesh,simpleFoam,pimpleFoam) with live output. - Color-coded console output for stdout, stderr, info, and tutorial messages.
- Fully compatible with OpenFOAM 2506 (adjustable for other versions).
- Security-hardened command execution with input validation and injection protection.
You have two options: Download a pre-built binary (easiest) or build from source using the automated installer.
Clone the repository and run the installer script. This will automatically check for and attempt to install dependencies (Python, Node.js, pnpm), build the frontend, and start the app.
Windows
git clone https://github.com/dhruvhaldar/FOAMFlask
cd FOAMFlask
.\install.ps1Linux / macOS
git clone https://github.com/dhruvhaldar/FOAMFlask
cd FOAMFlask
chmod +x install.sh
./install.shTip
After running the automated installer, if the uv command is not recognized, you may need to restart your terminal or add the local bin directory to your PATH:
- Windows:
$env:USERPROFILE\.local\bin - Linux/macOS:
~/.local/bin
If you prefer to manage the environment yourself:
- Install Prerequisites: Python 3.12+, Node.js 20+, pnpm 8+, and Docker.
- Install Frontend:
pnpm install pnpm run build
- Install Backend:
uv sync
Windows
uv run app.py 2>&1 | Tee-Object -FilePath app.logLinux / macOS
uv run app.py 2>&1 | tee app.logpkill -f "uv run app.py"; sleep 1; uv run app.py > app_output.log 2>&1 &-
Start the Application:
- If using the binary, just double-click it.
- If using source, run
uv run app.py.
-
Access the web interface: Open your browser and navigate to
http://localhost:5000. -
Access the web interface: Open your browser and navigate to
http://localhost:5000. -
Set a case directory: Enter a path for your simulation cases. Click
Set Case Dir. -
Set OpenFOAM root directory: Enter a path for your OpenFOAM root directory. Click
Set OpenFOAM Root. -
Load a tutorial: Select a tutorial from the dropdown. Click
Load Tutorial. The tutorial will be copied to your selected case directory. -
Run OpenFOAM commands: Use the buttons (blockMesh, simpleFoam, pimpleFoam) to execute commands. Live output is shown in the console panel.
-
Realtime Plotting:
- Click "Show Plots" to enable realtime polling of OpenFOAM results.
- Plots update every 2 seconds.
- For aerodynamic cases, click "Show Aero Plots" to see Pressure Coefficient (Cp) and Velocity Profiles.
Note
This section is intended for developers who wish to contribute to or modify FOAMFlask.
FOAMFlask/
├── app.py # Main Flask application
├── case_config.json # Stores the last used CASE_ROOT
├── package.json # Node.js dependencies and build scripts
├── copy-built-js.mjs # Custom build script
├── static/
│ ├── html/
│ │ └── foamflask_frontend.html # HTML template
│ ├── ts/
│ │ └── foamflask_frontend.ts # TypeScript source code
│ ├── js/
│ │ ├── foamflask_frontend.js # Compiled JavaScript (for browser)
│ │ └── frontend/
│ │ └── isosurface.js # PyVista integration
│ ├── js-build/
│ │ └── foamflask_frontend.js # TypeScript compiler output
├── backend/
│ ├── geometry/
│ │ └── manager.py # Geometry management utilities
│ ├── mesh/
│ │ └── mesher.py # Mesh generation utilities
│ ├── plots/
│ │ └── realtime_plots.py # Real-time plotting backend
│ ├── post/
│ │ └── isosurface.py # Post-processing utilities
│ ├── verification/
│ │ └── verify_changes.py # Verification utilities
├── test/
│ ├── check_coverage.py # Code coverage analysis script
│ ├── check_docstrings.py # Docstring coverage checker
│ ├── docker_test.py # Docker functionality tests
│ ├── pyvista_test.py # PyVista integration tests
│ ├── foamlib_test.py # FOAM library tests
│ └── bike.vtp # Test VTK file
├── docs/ # Generated documentation
├── environments/ # Python virtual environments
└── README.md # This file
- Backend Source:
app.py&backend/ - Frontend Source:
static/ts/ - Frontend Template:
static/html/
- Make changes to the TypeScript files in
static/ts/. - Compile to JavaScript:
You must compile the TypeScript to JavaScript for the browser to run it.
pnpm run build # One-time build (uses SWC for speed) pnpm run build:watch # Watch for changes (uses SWC)
- Run the backend (see Usage section) and refresh your browser.
- Add/Modify Logic:
- Create new modules in
backend/for organized logic (e.g., new file parsers, simulation controllers). - Import them in
app.py.
- Create new modules in
- Add Endpoints:
- Define new routes in
app.pyusing@app.route.
- Define new routes in
- Restart the server:
- Flask's debug mode (default) usually auto-reloads on python file changes.
This project is built with robustness and simplicity in mind, avoiding heavy frontend frameworks in favor of a clean, performant architecture.
-
Backend:
- Python 3.13+: Core logic managed by uv.
- Flask: Lightweight WSGI web application framework.
- Docker SDK (
docker-py): For programmatic control of Docker containers. - PyVista / VTK: For mesh processing and isosurface generation.
- Custom Parsers: Dedicated Python parsers (
realtime_plots.py) for reading both uniform and nonuniform OpenFOAM fields.
-
Frontend:
- TypeScript / SWC: For type-safe code and ultra-fast compilation (using SWC).
- Vanilla DOM API: No React/Vue/Angular. Direct DOM manipulation for maximum performance.
- TailwindCSS: Utility-first CSS framework for styling.
- Plotly.js: For responsive, interactive charts (using data served by Flask endpoints).
-
Architecture:
- RESTful API for client-server communication.
- Stateless Backend: The server does not maintain session state; state is managed by the client or persisted to disk.
Issue Description: Warning on the backend console:WARNING:FOAMFlask:[FOAMFlask] get_tutorials called but Docker Desktop is not running. Frontend shows empty drop down for Load Tutorial.
Explanation: This means the application is trying to access Docker Desktop but it's either not running or not installed.
Resolution: Here's how to resolve this:
-
Install Docker Desktop (if not already installed):
- Download from Docker's official website
- Follow the installation instructions for your operating system
- This build was tested on 4.45.0 (203075)
-
Start Docker Desktop
- Launch Docker Desktop before running the FOAMFlask application
- Wait for Docker to fully start (you'll see the Docker icon
Docker Desktop runningin your system tray/menu bar)
-
Restart FOAMFlask after Docker is running
-
In Docker Desktop settings, you have the option
Start Docker Desktop when you sign in to your computerto ensure Docker Desktop runs automatically the next time you login.
Issue Description: "Permission denied" error when trying to access the Docker socket (e.g., cannot connect to Docker daemon).
Explanation: The application needs to communicate with the Docker daemon, but your user does not have permission to access the Unix socket /var/run/docker.sock.
Resolution:
-
Add your user to the
dockergroup:sudo usermod -aG docker $USER -
Apply the group changes:
- Method A (Temporary): Run
newgrp dockerin your current terminal. - Method B (Permanent): Log out and log back in (recommended).
- Method C: Restart your computer.
- Method A (Temporary): Run
-
Verify access:
docker run --rm hello-world
Issue Description: Files created by the OpenFOAM container (e.g., tutorial files, logs) are owned by root and cannot be deleted by the user.
Explanation: By default, Docker containers run as root, so any files they write to the host system via bind mounts are owned by root.
Resolution: FOAMFlask includes an automated startup check to handle this:
- On the first run, it performs a "dry run" by launching a container to write a test file.
- It attempts to delete this file.
- If deletion fails (Permission Denied), it detects the issue and automatically configures future containers to run with your current user ID (UID) and group ID (GID).
- This ensures all subsequent files created by OpenFOAM are owned by you.
You will see a "System Check" modal on startup while this verification takes place.
On the first run, FOAMFlask performs several checks to ensure your environment is correctly configured:
- Docker Installation: Checks if the Docker executable is in your system PATH.
- Permissions: Verifies that the current user can run Docker commands (without sudo).
- Image Availability: Checks if the required OpenFOAM Docker image exists.
- If missing, it will automatically pull the image.
- Note: This is a large download (several GBs). A warning will be displayed for metered connections.
- File Permissions: As mentioned above, it ensures container-generated files are owned by you.
The application uses specific bind mount paths to ensure compatibility with different user permissions (especially on Linux).
Caution
Do NOT modify the internal container mount paths in app.py or backend/startup.py.
The application is configured to mount cases to /tmp/FOAM_Run inside the container. This /tmp path is critical because it ensures the directory is writable by ANY user (including your non-root host user).
Changing this back to /home/foam or other strict directories will cause "Permission Denied" errors on Linux systems.
Note
Security Suppression: You may see # nosec B108 comments in the code near these paths. This is required to suppress Bandit security warnings because /tmp is a hardcoded path, which is flagged by default but is safe and intentional in this Docker container context.
By default, the application binds to 0.0.0.0 (all interfaces) to ensure it is accessible when running inside a container.
To change this behavior (e.g., for local development security), you can set the FLASK_HOST environment variable:
- Container/Public Access (Default):
FLASK_HOST=0.0.0.0 - Localhost Only (Secure):
FLASK_HOST=127.0.0.1
On startup, the application logs the listening address: FOAMFlask listening on: {host}:{port}
Note
Security Suppression: You may see # nosec B104 in app.py. This suppresses the Bandit warning for binding to all interfaces, which is intentional for the containerized deployment strategy.
FOAMFlask includes a comprehensive test suite using pytest. The test suite includes unit tests, integration tests, and end-to-end tests for the application's core functionality.
-
Install test dependencies (if not already installed):
uv sync
-
Run all tests with coverage:
# Run all tests with coverage uv run pytest --cov=app --cov=backend --cov-report=term-missing --cov-report=html -
Run specific test files or individual tests:
# Run a specific test file uv run pytest test/test_app.py -v # Run a specific test function uv run pytest test/test_app.py::test_index_route -v
-
Run tests in parallel (faster execution):
uv run pytest -n auto --cov=app --cov=backend
To check test coverage and generate reports:
# Generate HTML coverage report (recommended)
uv run pytest --cov=app --cov=backend --cov-report=html
# View coverage in terminal
uv run pytest --cov=app --cov=backend --cov-report=term-missing
# Generate XML report (for CI/CD integration)
uv run pytest --cov=app --cov=backend --cov-report=xmlCoverage Reports:
- HTML report will be generated in the
htmlcovdirectory - Open
htmlcov/index.htmlin your browser to view the detailed coverage report - The terminal report shows which lines are missing coverage
test/
├── conftest.py # Test fixtures and configuration
├── test_app.py # Main application tests
└── test_security.py # Security-related tests
- Create a new test file following the naming convention
test_*.py - Use pytest fixtures from
conftest.pywhen available - Follow the existing test patterns for consistency
- Include docstrings explaining what each test verifies
# Run all tests with coverage
uv run pytest --cov=app --cov=backend
# Run tests without coverage
uv run pytest
# Run tests with detailed output
uv run pytest -v
# Run tests and stop after first failure
uv run pytest -x
# Run tests and show output from print statements
uv run pytest -s
# Run tests matching a specific pattern
uv run pytest -k "test_name_pattern"FOAMFlask is released under the GPLv3 License.






