Shallabuf follows a modular, service-oriented architecture where independent services communicate through a combination of PostgreSQL events and NATS messaging. The system is designed for scalability, leveraging WebAssembly (WASM) for secure and efficient execution of tasks.
The backend is built in Rust and consists of several key services:
- API Service (
api/): Handles client requests and exposes RESTful endpoints. - Worker Service (
worker/):- Accepts messages from the scheduler.
- Executes tasks inside WebAssembly (WASM) modules using the Wasmtime runtime.
- Uses WASI (WebAssembly System Interface) for secure interaction with the host environment.
- Provides a lightweight, sandboxed execution environment for isolated tasks.
- Scheduler Service (
scheduler/):- Manages scheduled jobs and dispatches tasks to worker services.
- Ensures efficient task distribution based on workload.
- Event Bridge (
event-bridge/):- Listens to PostgreSQL events (e.g., inserts, updates, deletes).
- Dispatches these events to other services using NATS, a high-performance messaging system.
- Enables real-time event-driven communication between system components.
- PostgreSQL (
db/): The primary relational database for structured application data. - MinIO: Provides object storage for large files and unstructured data. (S3 compatible)
- Docker & Docker Compose: Used for containerization and service orchestration.
- SQLx (
.sqlx/): A Rust-based database toolkit for schema management and queries. - NATS: A lightweight, high-performance messaging system for service communication.
- Loki (
loki-config.yaml) & Prometheus (prometheus.yaml): Used for logging, monitoring, and observability.
- Next.js (
frontend/): A React-based frontend framework for the user interface. - Bun: A fast JavaScript runtime used for dependency management and development tooling.
By utilizing PostgreSQL events and NATS, Shallabuf achieves a highly efficient event-driven architecture, ensuring real-time updates, decoupled communication, and scalable task execution.
graph TD;
subgraph Frontend
NextJS["Next.js (web)"]
end
subgraph Backend
API["API Service"]
Worker["Worker Service (WASM)"]
Scheduler["Scheduler Service"]
EventBridge["Event Bridge"]
end
subgraph Infrastructure
DB["PostgreSQL"]
MinIO["MinIO (Object Storage)"]
NATS["NATS (Message Broker)"]
Loki["Loki (Logging)"]
Prometheus["Prometheus (Monitoring)"]
end
NextJS -->|HTTP Requests| API
API -->|Reads/Writes| DB
DB -->|Triggers Events| EventBridge
EventBridge -->|Dispatches Events| NATS
NATS -->|Publishes Events| API
NATS -->|Publishes Events| Scheduler
Scheduler -->|Dispatch Jobs| Worker
Worker -->|Executes WASM Tasks| NATS
Worker -->|Stores Processed Data| MinIO
Worker -->|Stores Metadata| DB
NATS -->|Message Queue| Worker
Prometheus -->|Monitors| Backend
Loki -->|Logs| Backend
- Frontend: The Next.js app interacts with the backend via API calls.
- API Service: Communicates with the database and publishes events when changes occur.
- Event Bridge: Listens for PostgreSQL events and publishes them via NATS.
- Scheduler: Dispatches jobs to worker services via NATS.
- Worker Service: Executes WebAssembly (WASM) modules securely using Wasmtime.
- Infrastructure: Includes PostgreSQL (for data), MinIO (for object storage), NATS (for messaging), and monitoring/logging tools like Loki and Prometheus.
This provides a clear, structured view of your architecture in Mermaid format. Let me know if you want any modifications! π
Required tools:
- Rust ^1.84
- Bun ^1.1
- Docker ^27.4
- just (command runner)
- MinIO Client (mc)
- PostgreSQL Client (psql)
Optional but recommended:
- asdf (for managing Bun version)
- cargo-make (for running Rust services)
- cargo-watch (for development)
- cargo-sqlx (for database migrations)
-
Install Just
Follow the official Just installation guide
-
Install Required Tools
# Install all required tools (includes cargo-make and MinIO Client) just install-tools # Install Bun using asdf (optional) just install-bun
just install-tools # Install all required tools
just create-env # Create backend/.env from template
just dev # Start all servicesFor detailed setup, follow these steps:
-
Environment Setup
# Create backend/.env file from example just create-env -
Start Infrastructure
# Start all Docker containers (PostgreSQL, MinIO, NATS, etc.) just docker-up -
Database and MinIO Setup
# Sets up MinIO credentials, creates database, runs migrations and seeds just setup-db -
Frontend Setup
# Install frontend dependencies just setup-frontend
-
Start All Services
# Starts both frontend and backend services just devOr start them separately:
# Start frontend only just dev-frontend # Start backend services only just dev-backend
-
Backend Services Order Services start in the following order:
- Event Bridge
- Worker
- Scheduler
- API
-
Access Services
- Frontend: http://localhost:3000
- MinIO Console: http://localhost:30901 (default credentials: minio/minioadmin)
- API: http://localhost:8000
- Grafana: http://localhost:30001 (default credentials: admin/admin)
- Prometheus: http://localhost:30090
Pre-configured test users:
- Email: alex@mail.com, Password: alexpass
- Email: bob@mail.com, Password: bobpass
# Clean up everything (stop docker, clean database, etc.)
just clean
# Reset database (drops, recreates, migrates, and seeds)
just reset-db
# Run all tests
just test
# Format code
just fmt
# Lint code
just lint-
MinIO Access Issues
- Ensure MinIO is running:
docker ps | grep minio - Check credentials in backend/.env file
- Try rerunning setup:
just setup-minio
- Ensure MinIO is running:
-
Database Connection Issues
- Ensure PostgreSQL is running:
docker ps | grep postgres - Check DATABASE_URL in backend/.env file
- Try waiting for database:
just wait-for-db
- Ensure PostgreSQL is running:
-
Service Start Issues
- Ensure all containers are running:
docker ps - Check logs:
docker compose logs - Try restarting services:
just docker-down && just docker-up
- Ensure all containers are running:
.
βββ backend/ # All Rust backend services
β βββ api/ # API service
β βββ builtins/ # WASM modules
β βββ db/ # Database migrations and seed data
β βββ event-bridge/ # Event bridge service
β βββ scheduler/ # Scheduler service
β βββ worker/ # Worker service
β βββ .env # Environment variables
β βββ .env.example # Environment template
βββ frontend/ # Frontend (Next.js)
βββ docker-compose.yaml
βββ justfile # Command runner recipes
βββ Makefile.toml # Cargo make tasks