mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2025-12-16 22:05:12 +00:00
4.1 KiB
4.1 KiB
FastAPI Backend for ArisuAutoSweeper
This is the new FastAPI-based backend for the ArisuAutoSweeper WebUI, providing a modern REST API architecture while maintaining the same visual style as the original PyWebIO interface.
Architecture
Backend (FastAPI)
- main.py: Main FastAPI application with route registration and lifecycle management
- routes/: API endpoint modules
config.py: Configuration management endpointsprocess.py: Process control endpoints (start/stop/restart)system.py: System settings and update management
- websocket_handler.py: WebSocket endpoints for real-time log streaming
- templates/: Jinja2 HTML templates
- static/: Static assets (CSS, JS)
Frontend
- Simple HTML/CSS/JS frontend that reuses existing CSS from
assets/gui/css/ - Bootstrap 5 for base styling
- Native JavaScript for API interactions
- WebSocket for real-time updates
Usage
Starting the FastAPI Backend
# Use the new FastAPI backend
python gui_fastapi.py
# Or with custom host/port
python gui_fastapi.py --host 0.0.0.0 --port 23467
API Endpoints
Configuration Management
GET /api/config/instances- Get list of all instancesGET /api/config/{instance_name}- Get configuration for an instancePOST /api/config/{instance_name}- Update configurationPOST /api/config/create- Create new instanceDELETE /api/config/{instance_name}- Delete instance
Process Management
GET /api/process/- Get all processes statusGET /api/process/{instance_name}/status- Get process statusPOST /api/process/{instance_name}/start- Start processPOST /api/process/{instance_name}/stop- Stop processPOST /api/process/{instance_name}/restart- Restart process
System Management
GET /api/system/info- Get system informationPOST /api/system/language- Set languagePOST /api/system/theme- Set themeGET /api/system/update/status- Get update statusPOST /api/system/update/check- Check for updatesPOST /api/system/update/run- Run updatePOST /api/system/restart- Restart system
WebSocket
WS /ws/logs/{instance_name}- Real-time log streaming for an instanceWS /ws/system- System-wide real-time updates
Comparison with PyWebIO Backend
PyWebIO Backend (Original)
- Location:
module/webui/app.py - Entry Point:
gui.py - Architecture: Monolithic, UI generated from Python code
- Advantages: Simpler development, no frontend/backend separation
- Disadvantages: Tightly coupled, harder to extend, limited API access
FastAPI Backend (New)
- Location:
module/webui/fastapi_backend/ - Entry Point:
gui_fastapi.py - Architecture: Separated backend (REST API) and frontend
- Advantages:
- Modern REST API
- Can be used by multiple clients (web, mobile, CLI)
- Better separation of concerns
- Easier to test and extend
- Real-time updates via WebSocket
- Disadvantages: More code to maintain, requires frontend development
Migration Path
Both backends can coexist:
- Use
python gui.pyfor the original PyWebIO interface - Use
python gui_fastapi.pyfor the new FastAPI interface
Users can gradually migrate from PyWebIO to FastAPI as features are completed.
Development
Adding New Endpoints
- Create or modify files in
routes/ - Add Pydantic models for request/response validation
- Register the router in
main.py - Update the frontend to use the new endpoints
Reusing Existing CSS
The frontend reuses CSS from assets/gui/css/:
alas.css- Base stylesalas-pc.css- Desktop styleslight-alas.css/dark-alas.css- Theme styles
Testing
# Test that the app loads
python -c "from module.webui.fastapi_backend.main import app; print('OK')"
# Start the server
python gui_fastapi.py
# Access the interface
# Open browser to http://localhost:23467
Future Enhancements
- Complete configuration editor UI
- Enhanced log viewer with filtering
- Scheduler visualization
- Task queue management
- Mobile-responsive design improvements
- Authentication/authorization
- API documentation (Swagger UI at /docs)