Bonsai Web
A simple web interface for the Bonsai.
Local Development
Prerequisites
- Python 3.9+
- Flask
Installation
- Clone this repository
- Install dependencies:
bash pip install -r requirements.txt
Running Locally
python app.py
The application will be available at http://localhost:5000
Environment Configuration
The application behavior can be controlled using the BONSAI_TEST_MODE environment variable:
- Test Mode (default for local development):
BONSAI_TEST_MODE=true - If Bonsai fails or is not available, dummy files are generated for testing
-
Useful for development and testing the web interface
-
Production Mode:
BONSAI_TEST_MODE=false - If Bonsai fails, proper error messages are returned to the user
- No dummy files are generated
# Run in production mode
BONSAI_TEST_MODE=false python app.py
# Run in test mode (default)
BONSAI_TEST_MODE=true python app.py
# or simply
python app.py
Development Mode
For development, the application includes fallback dummy data generation when BONSAI_TEST_MODE=true and the actual Bonsai tool is not available. This allows you to test the web interface without having the full Bonsai installation.
Error Handling: When Bonsai fails in production mode, detailed error messages are displayed to the user in red text, including: - Execution failures with return codes and stderr output - Timeout errors (30-second limit) - Missing Bonsai installation errors
Container Deployment
Building the Container
just build
# or `just --set image <custom image> build`
Pushing the container
just push
# or `just --set image <custom image> push`
Running the Container
podman run -p 5000:5000 git.d464.sh/diogo464/bonsai-web:latest
Usage
- Open the web application in your browser
- Enter your network configuration in YAML format in the text area
- Click "Generate Network Files"
- View or download the generated
edges.csvandnodes.csvfiles
Example Configuration
network:
nodes: 10
density: 0.3
latency_range: [1, 100]
API
POST /
Generates network files from a YAML configuration.
Request Body:
{
"config": "network:\n nodes: 10\n density: 0.3"
}
Response:
{
"edges.csv": "source,target,weight\nnode1,node2,0.5\n...",
"nodes.csv": "id,label,x,y\nnode1,Node 1,0,0\n..."
}
