Ga naar hoofdinhoud

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

ComponentTechnologieVersie
DatabaseSpacetimeDB1.0+
Backend LogicRust (WASM)1.75+
Admin PanelNext.js15
Game ClientGodot4.5
StorageCloudflare R2-

Waarom SpacetimeDB?

SpacetimeDB is ideaal voor dit project vanwege:

  1. Real-time Synchronisatie

    • Automatische sync tussen alle clients
    • Geen polling nodig
    • Lage latency
  2. Rust WASM Modules

    • Type-safe backend logic
    • Snelle uitvoering
    • Makkelijk te testen
  3. Geïntegreerde Database

    • Geen aparte database setup
    • SQL-achtige queries
    • Automatische indexering
  4. 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

Belangrijke Bestanden

BestandBeschrijving
server/src/lib.rsHoofd SpacetimeDB module
server/Cargo.tomlRust dependencies
admin/Next.js admin panel
deployment/Deployment scripts