How runicgateway/website works
Purpose and Runtime Topology
Runic Gateway is a multi-instance website and operations gateway for a private Ultima Online shard: public CMS/wiki and shard status, authenticated player portal, protected staff administration, and Discord automation. It runs Node.js/Express, a React/Vite SPA, MariaDB, and a separate Discord bot; production Express serves the built SPA.
• server/src/server.js
• server/src/app.js
• client/src/main.jsx
• bot/src/bootstrap.js
HTTP API and Persistence Core
The backend follows router → controller → model → db, with versioned public, auth, player, admin, and internal boundaries. Models separate domain logic from parameterized MariaDB access; startup ensures schema and seeds initial state/admin. The REST API is the sole browser-facing data boundary and also exposes generated OpenAPI documentation.
• server/src/router/api.router.js
• server/src/router/v1/v1.router.js
• server/src/model/users/users.model.js
• server/db/schema.sql
SPA Surfaces and Access Boundaries
The React SPA is organized by audience: public site/wiki, player account portal, and admin console. Shared contexts fetch session/site state; route guards enforce authentication, player status, and roles client-side, while the API remains authoritative. The client uses same-origin API calls; Vite proxies API/uploads only in development.
• client/src/App.jsx
• client/src/api/client.js
• client/src/contexts/AuthContext.jsx
• client/src/routes/admin/AdminLayout.jsx
• client/src/routes/player/PlayerPortalLayout.jsx
Identity, Sessions, and Platform Security
A common session service supports local credentials, optional TOTP, linked OAuth2/OIDC identities, web JWT cookies, and mobile bearer/rotating refresh tokens. Middleware applies site-mode gating, validation, rate controls, login protection, bot scoring, and internal-key checks. Admin authorization is revalidated against database roles.
• server/src/auth/session.service.js
• server/src/auth/session.middleware.js
• server/src/auth/providers/registry.js
• server/src/middleware/siteMode.js
• server/src/middleware/loginProtection.js
CMS, Moderation, and Notifications
Admin-managed posts, pages, block content, wiki, settings, users, moderation/appeals, invitations, and activity are persisted server-side and rendered through corresponding public/admin views. Server and client maintain parallel block registries/validation so authored page content is constrained before storage and rendering. News announcement jobs dispatch to in-game town criers and Discord.
• server/src/blocks/registry.js
• server/src/blocks/sanitizeBlocks.js
• server/src/model/posts/posts.model.js
• server/src/model/announceJobs/announceJobs.logic.js
• client/src/blocks/BlockRenderer.jsx
Shard Integration and Live Data
The backend is the security boundary for the external uo-link sidecar: it holds its encrypted bearer token, performs authenticated REST calls, and maintains an outbound WebSocket ingest stream. The dispatcher updates materialized shard state and event logs, then exposes curated public and privileged admin SSE streams. Account-link records authorize players’ roster, character, vendor, and sales access.
• server/src/utils/uoLinkClient.js
• server/src/utils/uoLinkSocket.js
• server/src/utils/shardIngest.js
• server/src/model/shardState/shardState.model.js
• server/src/model/shardLinks/shardLinks.model.js
Discord Bot and Internal Service Boundary
A separately deployed Node bot manages Discord commands, moderation/filtering, roles, invites, scheduling, and announcements. It has its own database models and scheduler, and communicates with the website through authenticated internal endpoints rather than exposing bot operations publicly.
• bot/src/app.js
• bot/src/discord/discordManager.js
• bot/src/internal/internal.routes.js
• server/src/router/v1/internal/internal.routes.js
Deployment and External Dependencies
Docker Compose deploys prebuilt app and bot images with MariaDB; uploads, logs, branding assets, and database data persist via mounts/volumes. A TLS-terminating reverse proxy fronts Express. External integrations include Google/Discord OAuth, Gmail OAuth2 via Nodemailer, Discord, ntfy configuration, the uo-link sidecar, and browser push notifications.
• docker-compose.yml
• Dockerfile
• bot/Dockerfile
• server/src/utils/mailer.js
• server/src/utils/pushDispatch.js
Main entry points: v1.router.js Versioned API routers · users.model.js Controllers & domain models · App.jsx React/Vite SPA · app.js Express application
Components 19
Edge & Deployment
- TLS reverse proxy
Website Backend
- Express application · Serves the production SPA and REST/SSE API.
server/src/app.js - Versioned API routers · Public, auth, player, admin, and internal routes.
server/src/router/v1/v1.router.js - Session & security middleware · Sessions, OAuth identities, TOTP, token flows, and request protections.
server/src/auth/session.middleware.js - Controllers & domain models · CMS, accounts, moderation, links, and parameterized persistence logic.
server/src/model/users/users.model.js - Server block registry · Constrains authored block content before storage.
server/src/blocks/registry.js - MariaDB · Schema, CMS data, users, shard state, and bot data.
server/db/schema.sql - uo-link client & ingest · Holds the sidecar token and ingests outbound shard events.
server/src/utils/shardIngest.js - Shard state & account links · Materialized shard state, event logs, and player access links.
server/src/model/shardState/shardState.model.js - Announcement dispatch · Sends news announcements to Discord and in-game criers.
server/src/model/announceJobs/announceJobs.logic.js
React SPA
- React/Vite SPA · Public site/wiki, player portal, and staff console.
client/src/App.jsx - Session context & route guards · Loads session state and gates player/admin routes.
client/src/contexts/AuthContext.jsx - Block renderer · Renders validated authored page blocks.
client/src/blocks/BlockRenderer.jsx
Discord Bot
- Discord bot runtime · Commands, moderation, roles, invites, scheduling, and announcements.
bot/src/app.js - Bot internal API · Communicates with the website through internal endpoints.
bot/src/internal/internal.routes.js
External Services
- uo-link sidecar · External REST and WebSocket bridge to the game shard.
- Discord platform
- OAuth/OIDC providers · Google and Discord identity providers.
- Mail, push & ntfy
server/src/utils/pushDispatch.js
Connections 21
- TLS reverse proxy → Express application: HTTPS
- Express application → React/Vite SPA: serves production build
- React/Vite SPA → Session context & route guards: session and route state
- React/Vite SPA → Block renderer: renders CMS pages
- React/Vite SPA → Versioned API routers: same-origin API calls
- Express application → Session & security middleware: applies
- Session & security middleware → Versioned API routers: authorizes requests
- Session & security middleware → OAuth/OIDC providers: OAuth/OIDC
- Versioned API routers → Controllers & domain models: controllers
- Controllers & domain models → Server block registry: validates authored blocks
- Controllers & domain models → MariaDB: parameterized queries
- Versioned API routers → Shard state & account links: public/admin SSE and data
- uo-link client & ingest → uo-link sidecar: authenticated REST and WebSocket
- uo-link client & ingest → Shard state & account links: dispatches ingest
- Shard state & account links → MariaDB: state and event logs
- Announcement dispatch → Discord platform: news announcements
- Announcement dispatch → uo-link sidecar: town criers
- Discord bot runtime → Bot internal API: internal operations
- Bot internal API → Versioned API routers: authenticated internal endpoints
- Discord bot runtime → Discord platform: bot API
- Controllers & domain models → Mail, push & ntfy: email and push dispatch