# runicgateway/website architecture

> Architecture diagram of the GitHub repository runicgateway/website, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/runicgateway/website
- Repository: https://github.com/runicgateway/website

## Overview

#### 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: [`server/src/router/v1/v1.router.js`](https://github.com/runicgateway/website/blob/main/server/src/router/v1/v1.router.js) (Versioned API routers), [`server/src/model/users/users.model.js`](https://github.com/runicgateway/website/blob/main/server/src/model/users/users.model.js) (Controllers & domain models), [`client/src/App.jsx`](https://github.com/runicgateway/website/blob/main/client/src/App.jsx) (React/Vite SPA), [`server/src/app.js`](https://github.com/runicgateway/website/blob/main/server/src/app.js) (Express application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Edge &amp; Deployment"]
  node_proxy{{"TLS reverse proxy<br/>edge proxy"}}
end

subgraph group_web["Website Backend"]
  node_express["Express application<br/>Node.js runtime<br/>[app.js]"]
  node_api["Versioned API routers<br/>HTTP boundary<br/>[v1.router.js]"]
  node_security["Session &amp; security middleware<br/>auth middleware"]
  node_domain["Controllers &amp; domain models<br/>application layer<br/>[users.model.js]"]
  node_blocks["Server block registry<br/>content validation<br/>[registry.js]"]
  node_database[("MariaDB<br/>relational database<br/>[schema.sql]")]
  node_shardclient["uo-link client &amp; ingest<br/>integration gateway<br/>[shardIngest.js]"]
  node_shardstate["Shard state &amp; account links<br/>domain models"]
  node_announcements["Announcement dispatch<br/>job logic"]
end

subgraph group_client["React SPA"]
  node_spa["React/Vite SPA<br/>browser application<br/>[App.jsx]"]
  node_authcontext["Session context &amp; route guards<br/>client access layer<br/>[AuthContext.jsx]"]
  node_blockrenderer["Block renderer<br/>CMS renderer<br/>[BlockRenderer.jsx]"]
end

subgraph group_bot["Discord Bot"]
  node_discordbot["Discord bot runtime<br/>Node.js service<br/>[app.js]"]
  node_botinternal["Bot internal API<br/>authenticated service boundary<br/>[internal.routes.js]"]
end

subgraph group_external["External Services"]
  node_uolink{{"uo-link sidecar<br/>shard integration"}}
  node_discord{{"Discord platform<br/>external API"}}
  node_identity{{"OAuth/OIDC providers<br/>external identity"}}
  node_notifications{{"Mail, push &amp; ntfy<br/>notification services<br/>[pushDispatch.js]"}}
end

node_proxy -->|"HTTPS"| node_express
node_express -->|"serves production build"| node_spa
node_spa -->|"session and route state"| node_authcontext
node_spa -->|"renders CMS pages"| node_blockrenderer
node_spa -->|"same-origin API calls"| node_api
node_express -->|"applies"| node_security
node_security -->|"authorizes requests"| node_api
node_security -->|"OAuth/OIDC"| node_identity
node_api -->|"controllers"| node_domain
node_domain -->|"validates authored blocks"| node_blocks
node_domain -->|"parameterized queries"| node_database
node_api -->|"public/admin SSE and data"| node_shardstate
node_shardclient -->|"authenticated REST and WebSocket"| node_uolink
node_shardclient -->|"dispatches ingest"| node_shardstate
node_shardstate -->|"state and event logs"| node_database
node_announcements -->|"news announcements"| node_discord
node_announcements -->|"town criers"| node_uolink
node_discordbot -->|"internal operations"| node_botinternal
node_botinternal -->|"authenticated internal endpoints"| node_api
node_discordbot -->|"bot API"| node_discord
node_domain -->|"email and push dispatch"| node_notifications

click node_express "https://github.com/runicgateway/website/blob/main/server/src/app.js"
click node_api "https://github.com/runicgateway/website/blob/main/server/src/router/v1/v1.router.js"
click node_security "https://github.com/runicgateway/website/blob/main/server/src/auth/session.middleware.js"
click node_domain "https://github.com/runicgateway/website/blob/main/server/src/model/users/users.model.js"
click node_blocks "https://github.com/runicgateway/website/blob/main/server/src/blocks/registry.js"
click node_database "https://github.com/runicgateway/website/blob/main/server/db/schema.sql"
click node_shardclient "https://github.com/runicgateway/website/blob/main/server/src/utils/shardIngest.js"
click node_shardstate "https://github.com/runicgateway/website/blob/main/server/src/model/shardState/shardState.model.js"
click node_announcements "https://github.com/runicgateway/website/blob/main/server/src/model/announceJobs/announceJobs.logic.js"
click node_spa "https://github.com/runicgateway/website/blob/main/client/src/App.jsx"
click node_authcontext "https://github.com/runicgateway/website/blob/main/client/src/contexts/AuthContext.jsx"
click node_blockrenderer "https://github.com/runicgateway/website/blob/main/client/src/blocks/BlockRenderer.jsx"
click node_discordbot "https://github.com/runicgateway/website/blob/main/bot/src/app.js"
click node_botinternal "https://github.com/runicgateway/website/blob/main/bot/src/internal/internal.routes.js"
click node_notifications "https://github.com/runicgateway/website/blob/main/server/src/utils/pushDispatch.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_proxy toneBlue
class node_express,node_api,node_security,node_domain,node_blocks,node_database,node_shardclient,node_shardstate,node_announcements toneAmber
class node_spa,node_authcontext,node_blockrenderer toneMint
class node_discordbot,node_botinternal toneRose
class node_uolink,node_discord,node_identity,node_notifications toneIndigo
```

## Components

### Edge & Deployment

- **TLS reverse proxy**: edge proxy

### Website Backend

- [Express application](https://github.com/runicgateway/website/blob/main/server/src/app.js): Node.js runtime · Serves the production SPA and REST/SSE API. · `server/src/app.js`
- [Versioned API routers](https://github.com/runicgateway/website/blob/main/server/src/router/v1/v1.router.js): HTTP boundary · Public, auth, player, admin, and internal routes. · `server/src/router/v1/v1.router.js`
- [Session & security middleware](https://github.com/runicgateway/website/blob/main/server/src/auth/session.middleware.js): auth middleware · Sessions, OAuth identities, TOTP, token flows, and request protections. · `server/src/auth/session.middleware.js`
- [Controllers & domain models](https://github.com/runicgateway/website/blob/main/server/src/model/users/users.model.js): application layer · CMS, accounts, moderation, links, and parameterized persistence logic. · `server/src/model/users/users.model.js`
- [Server block registry](https://github.com/runicgateway/website/blob/main/server/src/blocks/registry.js): content validation · Constrains authored block content before storage. · `server/src/blocks/registry.js`
- [MariaDB](https://github.com/runicgateway/website/blob/main/server/db/schema.sql): relational database · Schema, CMS data, users, shard state, and bot data. · `server/db/schema.sql`
- [uo-link client & ingest](https://github.com/runicgateway/website/blob/main/server/src/utils/shardIngest.js): integration gateway · Holds the sidecar token and ingests outbound shard events. · `server/src/utils/shardIngest.js`
- [Shard state & account links](https://github.com/runicgateway/website/blob/main/server/src/model/shardState/shardState.model.js): domain models · Materialized shard state, event logs, and player access links. · `server/src/model/shardState/shardState.model.js`
- [Announcement dispatch](https://github.com/runicgateway/website/blob/main/server/src/model/announceJobs/announceJobs.logic.js): job logic · Sends news announcements to Discord and in-game criers. · `server/src/model/announceJobs/announceJobs.logic.js`

### React SPA

- [React/Vite SPA](https://github.com/runicgateway/website/blob/main/client/src/App.jsx): browser application · Public site/wiki, player portal, and staff console. · `client/src/App.jsx`
- [Session context & route guards](https://github.com/runicgateway/website/blob/main/client/src/contexts/AuthContext.jsx): client access layer · Loads session state and gates player/admin routes. · `client/src/contexts/AuthContext.jsx`
- [Block renderer](https://github.com/runicgateway/website/blob/main/client/src/blocks/BlockRenderer.jsx): CMS renderer · Renders validated authored page blocks. · `client/src/blocks/BlockRenderer.jsx`

### Discord Bot

- [Discord bot runtime](https://github.com/runicgateway/website/blob/main/bot/src/app.js): Node.js service · Commands, moderation, roles, invites, scheduling, and announcements. · `bot/src/app.js`
- [Bot internal API](https://github.com/runicgateway/website/blob/main/bot/src/internal/internal.routes.js): authenticated service boundary · Communicates with the website through internal endpoints. · `bot/src/internal/internal.routes.js`

### External Services

- **uo-link sidecar**: shard integration · External REST and WebSocket bridge to the game shard.
- **Discord platform**: external API
- **OAuth/OIDC providers**: external identity · Google and Discord identity providers.
- [Mail, push & ntfy](https://github.com/runicgateway/website/blob/main/server/src/utils/pushDispatch.js): notification services · `server/src/utils/pushDispatch.js`

## Connections

- 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
