Site Service
The Site service is the primary web application that users interact with. Itβs built with SvelteKit and TypeScript.Technology Stack
- Framework: SvelteKit (full-stack meta-framework)
- UI Library: Svelte 5 (compiled reactive components)
- Language: TypeScript (strict type checking enabled)
- Runtime: Bun (fast JavaScript runtime)
- Build Tool: Vite (dev server and bundler)
Responsibilities
User Management
- Registration with invite keys
- Authentication and session management
- Profile customization (description, avatar, body colors)
- Friend requests and relationships
- User moderation and bans
Content Management
- Asset catalog and inventory
- Game/place creation and hosting
- Forum posts and comments
- Groups and group membership
- Asset thumbnails and renders
Administrative Functions
- User moderation tools
- Registration key management
- Asset approval queue
- Transaction monitoring
- Audit logging
- Banner management
Route Structure
SvelteKit uses file-based routing inSite/src/routes/:
(plain), (main), and (legal) share common layouts without affecting URLs.
Server-Side Code
Server utilities are inSite/src/lib/server/:
- surreal.ts: Database connection and helpers
- economy.ts: Economy service client
- auth.ts: Authentication utilities
- validate.ts: Input validation
- sign.ts: Asset signing for corescripts
- email.ts: Email sending
- *.surql: SurrealQL query files
API Routes
SvelteKit provides automatic API routes through+server.ts files:
Environment Variables
Configured inSite/.env:
Development
Start the dev server:- Hot module replacement (instant updates)
- Fast refresh for Svelte components
- On-demand compilation
- Built-in inspector (Ctrl+I to select elements)
Production Build
- Pre-renders static pages
- Optimizes and minifies code
- Generates service worker
- Outputs to
Site/build/
Database Service
SurrealDB serves as the primary database, running on port 8000.Starting the Database
Development (auto-started by Site service):Connection
The Site service connects via WebSocket (Site/src/lib/server/surreal.ts:36-93):Schema Initialization
On startup, the Site service runsinit.surql to define the complete database schema. This includes:
- Table definitions (user, asset, place, comment, etc.)
- Field types and validation
- Graph relationships (friends, follows, likes, etc.)
- Computed fields (user status, comment scores)
- Indexes (username uniqueness)
- Database functions
- Event triggers for audit logging
Query Retry Logic
SurrealDB supports optimistic concurrency. The Site service automatically retries failed transactions:Type Safety
The Site service defines TypeScript types for all database tables (Site/src/lib/server/surreal.ts:101-186):Economy Service
A standalone Go service that manages the virtual economy, running on port 2009.Architecture
The Economy service is intentionally simple and focused:- Written in Go for performance and reliability
- Append-only transaction ledger (JSONL format)
- In-memory balance calculation
- REST API for Site service
- No database dependencies
Starting the Service
Development (auto-started by Site service):API Endpoints
GET /currentStipend
Returns the current daily stipend amount. Response:10000000 (10.000000 units)
GET /balance/:id
Get a userβs currency balance. Response:50000000 (50.000000 units)
GET /transactions/:id
Get last 100 transactions for a user. Response:GET /transactions
Get last 100 transactions across entire economy (admin only).POST /transact
Execute a transaction between two users. Request Body:POST /mint
Create new currency (admin only). Request Body:POST /burn
Destroy currency (e.g., creation fees). Request Body:POST /stipend/:id
Grant daily stipend to a user (12-hour cooldown). Response: 200 OK or 400 βNext stipend not available yetβClient Integration
The Site service includes a typed client (Site/src/lib/server/economy.ts):Pricing Functions
The Site service defines standard pricing (Site/src/lib/server/economy.ts:126-132):Startup Logs
Service Dependencies
Health Monitoring
All services include process monitoring:- Database: Site service monitors process and auto-restarts
- Economy: Site service monitors process and auto-restarts
- Site: Systemd, PM2, or container orchestrator handles restarts
- Error logging with last 10 lines of output
- Process exit with error code
- Orchestrator restart (in production)
Inter-Service Communication
Services communicate over localhost using HTTP/WebSocket:- Site β Database: WebSocket (port 8000) for real-time queries
- Site β Economy: HTTP REST API (port 2009) for transactions
- External β Site: HTTPS via Caddy (ports 80/443)