|
| 1 | +# FUSION API Module |
| 2 | + |
| 3 | +FastAPI backend for the FUSION GUI web interface. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This module provides a REST API for managing simulation runs, streaming logs, and accessing artifacts. It serves as the backend for the FUSION GUI. |
| 8 | + |
| 9 | +## Quick Start |
| 10 | + |
| 11 | +```bash |
| 12 | +# Install GUI dependencies |
| 13 | +pip install -r requirements-gui.txt |
| 14 | + |
| 15 | +# Start the server |
| 16 | +python -m fusion.cli.run_gui |
| 17 | + |
| 18 | +# Or with reload for development |
| 19 | +python -m fusion.cli.run_gui --reload |
| 20 | +``` |
| 21 | + |
| 22 | +The API will be available at `http://127.0.0.1:8765`. |
| 23 | + |
| 24 | +## API Documentation |
| 25 | + |
| 26 | +Once the server is running, visit: |
| 27 | +- Swagger UI: `http://127.0.0.1:8765/docs` |
| 28 | +- ReDoc: `http://127.0.0.1:8765/redoc` |
| 29 | + |
| 30 | +## Module Structure |
| 31 | + |
| 32 | +``` |
| 33 | +fusion/api/ |
| 34 | +├── __init__.py # Package exports |
| 35 | +├── main.py # FastAPI app, lifespan, middleware |
| 36 | +├── config.py # Settings (pydantic-settings) |
| 37 | +├── dependencies.py # Dependency injection |
| 38 | +├── routes/ # API endpoints |
| 39 | +│ ├── runs.py # /api/runs - Run management |
| 40 | +│ ├── configs.py # /api/configs - Templates |
| 41 | +│ ├── artifacts.py # /api/runs/{id}/artifacts |
| 42 | +│ └── system.py # /api/health, /api/version |
| 43 | +├── schemas/ # Pydantic models |
| 44 | +│ ├── run.py # Run request/response models |
| 45 | +│ ├── config.py # Config models |
| 46 | +│ └── common.py # Shared models |
| 47 | +├── services/ # Business logic |
| 48 | +│ ├── run_manager.py # Simulation lifecycle |
| 49 | +│ └── artifact_service.py # Secure file access |
| 50 | +├── db/ # Database layer |
| 51 | +│ ├── database.py # SQLite + SQLAlchemy |
| 52 | +│ └── models.py # ORM models |
| 53 | +├── static/ # Built React frontend |
| 54 | +└── tests/ # Unit tests |
| 55 | +``` |
| 56 | + |
| 57 | +## Key Endpoints |
| 58 | + |
| 59 | +| Method | Endpoint | Description | |
| 60 | +|--------|----------|-------------| |
| 61 | +| POST | /api/runs | Create and start a run | |
| 62 | +| GET | /api/runs | List all runs | |
| 63 | +| GET | /api/runs/{id} | Get run details | |
| 64 | +| DELETE | /api/runs/{id} | Cancel/delete run | |
| 65 | +| GET | /api/runs/{id}/logs | Stream logs (SSE) | |
| 66 | +| GET | /api/runs/{id}/artifacts | List artifacts | |
| 67 | +| GET | /api/configs/templates | List config templates | |
| 68 | +| GET | /api/health | Health check | |
| 69 | + |
| 70 | +## Configuration |
| 71 | + |
| 72 | +Environment variables (prefix: `FUSION_GUI_`): |
| 73 | + |
| 74 | +| Variable | Default | Description | |
| 75 | +|----------|---------|-------------| |
| 76 | +| HOST | 127.0.0.1 | Server bind address | |
| 77 | +| PORT | 8765 | Server port | |
| 78 | +| DATABASE_URL | sqlite:///data/gui_runs/runs.db | SQLite database path | |
| 79 | +| MAX_CONCURRENT_RUNS | 1 | Maximum simultaneous runs | |
| 80 | + |
| 81 | +## Development |
| 82 | + |
| 83 | +```bash |
| 84 | +# Run with auto-reload |
| 85 | +python -m fusion.cli.run_gui --reload --log-level debug |
| 86 | + |
| 87 | +# Run tests |
| 88 | +pytest fusion/api/tests/ |
| 89 | +``` |
| 90 | + |
| 91 | +## See Also |
| 92 | + |
| 93 | +- [GUI Documentation](../../docs/gui/) - Full GUI design documentation |
| 94 | +- [Backend Standards](../../docs/gui/06-backend-standards.md) - Coding conventions |
0 commit comments