# Bonsai Web A simple web interface for the Bonsai. ## Local Development ### Prerequisites - Python 3.9+ - Flask ### Installation 1. Clone this repository 2. Install dependencies: ```bash pip install -r requirements.txt ``` ### Running Locally ```bash 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 ```bash # 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 ```bash just build # or `just --set image build` ``` #### Pushing the container ```bash just push # or `just --set image push` ``` ### Running the Container ```bash podman run -p 5000:5000 git.d464.sh/diogo464/bonsai-web:latest ``` ## Usage 1. Open the web application in your browser 2. Enter your network configuration in YAML format in the text area 3. Click "Generate Network Files" 4. View or download the generated `edges.csv` and `nodes.csv` files ### Example Configuration ```yaml network: nodes: 10 density: 0.3 latency_range: [1, 100] ``` ## API ### POST / Generates network files from a YAML configuration. **Request Body:** ```json { "config": "network:\n nodes: 10\n density: 0.3" } ``` **Response:** ```json { "edges.csv": "source,target,weight\nnode1,node2,0.5\n...", "nodes.csv": "id,label,x,y\nnode1,Node 1,0,0\n..." } ```