Backend Documentatie
Technische documentatie voor de backend van Milena's Cozy Treehouse Club.
Architectuur Overzicht
┌─────────────────────────────────────────────────────────┐
│ Clients │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Godot Game │ │ Admin Panel │ │ Designer │ │
│ │ (GDScript) │ │ (Next.js) │ │ Portal │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
└─────────┼────────────────┼────────────────┼─────────────┘
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────────┐
│ WebSocket Connection │
└──────────────────────┬───────────────────────┘
│
┌──────────────────────▼───────────────────────┐
│ SpacetimeDB │
│ ┌─────────────────────────────────────────┐ │
│ │ WASM Module (Rust) │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ Tables │ │Reducers │ │Scheduled│ │ │
│ │ │ (Data) │ │ (Logic) │ │ Tasks │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ └─────────────────────────────────────────┘ │
└──────────────────────────────────────────────┘
│
┌──────────────────────▼───────────────────────┐
│ Cloudflare R2 │
│ (Asset Storage - optioneel) │
└──────────────────────────────────────────────┘
Tech Stack
| Component | Technologie | Versie |
|---|---|---|
| Database | SpacetimeDB | 1.0+ |
| Backend Logic | Rust (WASM) | 1.75+ |
| Admin Panel | Next.js | 15 |
| Game Client | Godot | 4.5 |
| Storage | Cloudflare R2 | - |
Waarom SpacetimeDB?
SpacetimeDB is ideaal voor dit project vanwege:
-
Real-time Synchronisatie
- Automatische sync tussen alle clients
- Geen polling nodig
- Lage latency
-
Rust WASM Modules
- Type-safe backend logic
- Snelle uitvoering
- Makkelijk te testen
-
Geïntegreerde Database
- Geen aparte database setup
- SQL-achtige queries
- Automatische indexering
-
Schaalbaarheid
- Horizontale schaling
- Edge deployment mogelijk
- Bewezen (BitCraft gebruikt het)
Quick Start
Vereisten
# Rust installeren
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
# SpacetimeDB CLI installeren
curl -fsSL https://install.spacetimedb.com | bash
Lokaal Draaien
# Start lokale SpacetimeDB server
spacetime start
# Build en publish module
cd server
spacetime build
spacetime publish milenas-treehouse --clear-database
Verbinden met Godot
De Godot SDK genereert automatisch bindings bij verbinding.
In Deze Sectie
- SpacetimeDB - Database en module architectuur
- Schema - Database tabellen en structuur
- Reducers - API endpoints en logica
- Admin Panel - Web interface voor beheer
- Deployment - Lokaal en productie deployment
Belangrijke Bestanden
| Bestand | Beschrijving |
|---|---|
server/src/lib.rs | Hoofd SpacetimeDB module |
server/Cargo.toml | Rust dependencies |
admin/ | Next.js admin panel |
deployment/ | Deployment scripts |