A modern, full-stack platform for creating, managing, and publishing Language Model (LLM) routers on SyftBox. Built with a Python backend (FastAPI, SyftBox) and a sleek Preact/TypeScript frontend.
- Provider Mode: Create, manage, and publish routers with monetization
- Client Mode: Discover and use published routers
- Web-Based Creation: Intuitive UI for creating routers through the dashboard
- Two-Path Generation: Choose between "batteries included" (default) or "build from scratch" (custom)
- Service Configuration: Enable/disable chat and search services
- Pricing Control: Set per-service pricing with flexible charge types
- Real-time Status: Monitor router health and service status
- Responsive Design: Works seamlessly on desktop and mobile
- Type Safety: Full TypeScript support with strict typing
- Real-time Feedback: Loading states, error handling, and success animations
- Accessible: Built with accessibility best practices
- Database Integration: SQLite with SQLModel for data persistence
- Static Asset Serving: Optimized frontend build with Vite
- API Documentation: Auto-generated OpenAPI/Swagger docs
- Easy Deployment: Simple setup scripts and configuration
syft-llm-router/
βββ backend/ # FastAPI + SyftBox backend
β βββ main.py # Main application entry point
β βββ router/ # Router management module
β β βββ api.py # FastAPI routes and endpoints
β β βββ manager.py # Business logic and orchestration
β β βββ repository.py # Data access layer (Repository pattern)
β β βββ models.py # SQLAlchemy ORM models
β β βββ schemas.py # Pydantic DTOs and validation
β β βββ constants.py # Application constants
β β βββ exceptions.py # Custom exception classes
β β βββ publish.py # Publishing logic and metadata
β βββ generator/ # Router template generation
β β βββ service.py # Router generation service
β β βββ common/ # Shared generation utilities
β β βββ templates/ # Router templates (default/custom)
β βββ shared/ # Shared utilities and configuration
β β βββ database.py # Database configuration and session management
β βββ static/ # Served frontend assets (generated)
β βββ build_frontend.sh # Frontend build script
βββ frontend/ # Preact + TypeScript frontend
β βββ src/ # Source code
β βββ public/ # Static assets
β βββ package.json # Frontend dependencies
βββ data/ # SQLite database
βββ run.sh # Full-stack startup script
βββ README.md # This file
backend/router/
: Core router management with Repository pattern and DTOsbackend/generator/
: Router template generation and customizationbackend/shared/
: Shared utilities and database configurationfrontend/
: Preact application with TypeScript and TailwindCSSdata/
: SQLite database storagerun.sh
: One-command startup script
The backend follows modern architectural patterns:
- Repository Pattern: Data access layer in
router/repository.py
with proper separation of concerns - DTO Pattern: Pydantic models in
router/schemas.py
for API contracts and validation - Manager Layer: Business logic orchestration in
router/manager.py
- API Layer: FastAPI routes in
router/api.py
with RESTful design - Shared Database: Centralized database configuration in
shared/database.py
- Eager Loading: Optimized database queries with
selectinload
to prevent N+1 problems
- Python 3.12+
- uv (Python package manager)
- Bun (JavaScript runtime)
# Clone the repository
git clone <repository-url>
cd syft-llm-router
# One command to start everything
./run.sh
That's it! π The run.sh
script handles everything:
- β Environment Setup: Creates Python virtual environment
- β Dependencies: Installs all Python and JavaScript packages
- β Frontend Build: Compiles the React application
- β Database: Initializes SQLite database with tables
- β
Server Start: Launches the backend on
http://localhost:8080
Once the script completes, open your browser and navigate to:
You'll see the Syft LLM Router dashboard where you can:
- Choose your profile (Provider/Client)
- Create and manage routers
- Publish and monetize your services
If you need to use a different port:
export SYFTBOX_ASSIGNED_PORT=9000
./run.sh
- Onboarding: Choose "Provider" profile during first visit
- Create Router:
- Click "Create Router" button in the dashboard
- Enter router name and select type (Default/Custom)
- Choose services (Chat/Search)
- Router is generated and saved to database
- Manage Router:
- View router in dashboard
- Check status and health
- Edit configuration
- Publish Router:
- Click "Publish" button
- Add metadata (summary, description, tags)
- Configure pricing for each service
- Set charge type (per request, per token, etc.)
- Router becomes publicly available
- Monitor & Monetize:
- Track usage and revenue
- Update pricing as needed
- Unpublish if necessary
- Onboarding: Choose "Client" profile during first visit
- Discover Routers:
- Browse published routers in dashboard
- View summaries, pricing, and service details
- Filter by tags or services
- Use Router:
- Click "View Details" to see full documentation
- Access API endpoints
- Integrate into your applications
- Chat Interface (if available):
- Use built-in chat interface
- Test router capabilities
- View conversation history
- Chat Service: Pre-configured Ollama integration
- Search Service: Local RAG with ChromaDB
- Auto-setup: Dependencies installed automatically
- Production Ready: Includes validation and monitoring
- Template Structure: Clear TODO comments and examples
- Flexible Configuration: Add your own config options
- Service Placeholders: Implement your own logic
- Easy Extension: Simple to add new service types
GET /router/list
- List all routers (filtered by user profile)POST /router/create
- Create a new router via web UIGET /router/exists
- Check if router name is availableGET /router/details
- Get detailed router informationDELETE /router/delete
- Delete a router (RESTful DELETE method)
POST /router/publish
- Publish router with metadata and pricingPUT /router/unpublish
- Unpublish a router (RESTful PUT method)
GET /username
- Get current user informationGET /sburl
- Get SyftBox server URLGET /router/status
- Get router runtime status
- Clean, responsive interface with TailwindCSS
- Real-time data updates
- Loading states and error handling
- Accessible design patterns
- List View: See all routers with status indicators
- Detail View: Comprehensive router information
- Create Modal: Step-by-step router creation via web UI
- Publish Modal: Multi-step publishing with pricing
- Toggle switches for enabling/disabling services
- Price input with validation
- Charge type selection (per request, per token, etc.)
- Real-time pricing preview
cd backend
uv venv -p 3.12 .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -r requirements.txt
uvicorn main:app --reload --port 8080
cd frontend
bun install
bun run dev
The application uses SQLite with automatic table creation:
# Database is automatically created at data/routers.db
# Tables are created on first startup
# Build frontend for production
cd frontend
bun run build
# Start backend with production settings
cd backend
uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4
# Optional: Set custom port
export SYFTBOX_ASSIGNED_PORT=8080
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Use TypeScript for all frontend code
- Follow Preact best practices
- Write reusable, accessible components
- Add proper error handling and loading states
- Keep backend and frontend types in sync
- Test on different screen sizes
- Follow Repository pattern for data access
- Use Pydantic DTOs for API contracts
- Implement proper separation of concerns
- Use eager loading for database queries to avoid N+1 problems
This project is part of the Syft LLM Router ecosystem and is licensed under the same terms as the parent project.
- Documentation: Check the
backend/router_generator/README.md
for detailed router generation docs - Issues: Report bugs and feature requests via GitHub Issues
- Discussions: Join community discussions for questions and ideas