This is the community-built, open-source website for Alveus Sanctuary. You can access the site at alveussanctuary.org (or alveus.gg).
- Data repository: ambassador, enclosure, and other shared data, published as the
@alveusgg/datapackage - Twitch extension
This repository holds more than the public website. It also contains the admin dashboard, the stream overlays, a Twitch chat bot, and the donations service behind features like the pixel mural.
It is a pnpm workspace monorepo, and most work happens in apps/website.
| Path | What it is | Runs on |
|---|---|---|
apps/website |
Next.js app: public pages, admin dashboard, stream overlays, and the API (tRPC and REST) that the other apps talk to | Vercel |
apps/database |
Prisma schema and client (@alveusgg/database), shared by the website and the chat bot |
library |
apps/chatbot |
Twitch chat bot that lets mods send "live now" notifications from chat | Docker |
apps/donations/worker |
Donations manager: takes in donations from Twitch Charity, PayPal, and Neon CRM, saves them via the website, and runs the pixel mural | Cloudflare Workers |
apps/donations/core |
Shared donation types | library |
apps/donations/neon-crm-api |
Neon CRM API client and webhook schemas | library |
docs |
Deep dives into specific features, e.g. file uploads and attachments |
flowchart TB
chat(["Twitch chat"])
people(["Visitors, staff & mods<br/>browser, PWA, stream overlays"])
donations(["Donation sources<br/>Twitch Charity, PayPal, Neon CRM"])
subgraph repo["This repository"]
chatbot["<b>Chat bot</b><br/>apps/chatbot<br/><i>Docker</i>"]
worker["<b>Donations worker</b><br/>apps/donations/worker<br/><i>Cloudflare Workers</i>"]
website["<b>Website & API</b><br/>apps/website<br/><i>Vercel</i>"]
end
data["@alveusgg/data<br/>ambassadors & enclosures"]
subgraph services["Infrastructure & external services"]
db[("MySQL<br/>schema in apps/database")]
storage[("S3 storage<br/>file uploads")]
upstash["Upstash<br/>QStash, Redis"]
push["Web push services"]
apis["External APIs<br/>Twitch, YouTube, Discord,<br/>Weather, Cloudflare Stream"]
end
chat <-- "commands" --> chatbot
people -- "pages, tRPC" --> website
people -- "live pixels" --> worker
donations -- "webhooks, sync" --> worker
chatbot -- "send notification" --> website
worker -- "new donations" --> website
data -. "npm package" .-> website
chatbot --> db
website --> db & storage & upstash & push & apis
- Website (
apps/website) is the hub. It serves the pages and the tRPC API, signs people in with Twitch, keeps data in MySQL and uploads in S3-compatible storage, and sends notifications through web push and Discord. A Vercel cron job calls/api/cronevery 10 minutes to run the scheduled tasks, such as syncing calendar events and retrying notification pushes. - Chat bot (
apps/chatbot) listens to Twitch chat. When a mod sends a notification command, the bot passes it to the website API. It reads its own Twitch token and user roles from the shared database. - Donations worker (
apps/donations/worker) receives donation webhooks (Twitch Charity via EventSub, PayPal IPN, Neon CRM) and syncs with Neon CRM every hour. It queues the donations, saves them via the website's tRPC API, and keeps the pixel mural state that browsers follow live over a WebSocket. - Ambassador and enclosure data comes from
@alveusgg/data, which is installed from the GitHub Package Registry. This is why the setup below needs a GitHub token.
pages/: most site pages (Next.js Pages Router), plus API routes inpages/api/app/: App Router route handlers for newer API endpoints, RSS feeds, and the OAuth endpointscomponents/: React components, grouped by feature (admin/,overlay/,content/, …)server/: server-only code, including tRPC routers (server/trpc/router/), database access (server/db/), and clients for external APIs (server/apis/)data/: static content and configuration, such as navigation, staff, events, and scheduled taskssw/: the service worker that shows push notificationsenv/: the environment variable schema (keep it in sync with.env.example)
For development:
- Node.js (see
enginesinpackage.json) - pnpm with workspaces
- Prettier (code formatting)
- ESLint (code linting)
- Vitest (unit tests)
- Docker Compose (local MySQL, Redis, and S3)
Website stack (based on the T3 Stack):
- TypeScript
- Next.js (framework)
- tRPC (typesafe API)
- Prisma (database ORM)
- Auth.js aka NextAuth.js (auth via OAuth)
- Tailwind CSS (styling)
Other apps:
- Chat bot: Node.js with Twurple
- Donations worker: Cloudflare Workers with Hono, Durable Objects, and Queues
Hosting (production):
- Vercel (website)
- PlanetScale (MySQL database)
- DigitalOcean Spaces (S3-compatible storage)
- Upstash QStash (queue for push notifications) and Upstash Redis (rate limiting, OAuth codes)
- Cloudflare Workers (donations worker) and Cloudflare Stream (low-latency cams)
- A Docker host (chat bot)
- Twitch: OAuth (sign-in), Helix API, chat, and EventSub (charity donations)
- YouTube Data API
- Discord (calendar events and webhooks)
- Weather.com / Wunderground (on-site weather station)
- Neon CRM and PayPal (donations)
Hey there! Welcome to Alveus.gg! There's a few ways that you can help contribute.
- If you find a bug - you can fill out a bug report
- If you have an idea that would make Alveus better - please fill out an idea issue
- If you have development experience, take a look at our issues labeled good first issue, read our contributing guide and agree to our code of conduct before you get started.
Note
If you only want to work on the front end, you may skip the prerequisite and skip setting up a database or file storage (step 5). But you may encounter some errors when running the website without a database or file storage.
If you aren't working on features related to Twitch authentication, you can set the DISABLE_ADMIN_AUTH to true in your apps/website/.env file (see step 6 and 6.i) in order to use the admin dashboard immediately. Otherwise, create a Twitch application, setting the OAuth callback to be http://localhost:3000/api/auth/callback/twitch. Note down your client ID and client secret.
- Install Node.js using a version manager like
nvmorfnm. Runnvm install/fnm installin the project directory to install andnvm use/fnm useto use the correct Node.js version. Alternatively see nodejs.org for other options to download and install Node.js. You can see what version we need inpackage.jsonunderengines. - Use
corepack enableto use pnpm as the package manager. Corepack is a tool provided with Node.js that makes it easy for you to use the specific package manager we expect. - Authenticate with the GitHub Package Registry:
npm login --auth-type=legacy --registry=https://npm.pkg.github.com- Use your GitHub username (lowercase) as the username when prompted
- Create a GitHub personal access token (classic) with the
read:packagesscope and use it as the password when prompted
- Install dependencies:
pnpm install --frozen-lockfile - Run
docker compose up -dfrom withinapps/websiteto start a local MySQL database, Redis, and an S3 bucket. - Copy
apps/website/.env.exampletoapps/website/.envand open your copy in a text editor and fill it:- If your feature is not related to Twitch authentication, you can set
DISABLE_ADMIN_AUTHtotruein order to use the admin dashboard without authentication. Otherwise, fill inTWITCH_CLIENT_IDandTWITCH_CLIENT_SECRETas mentioned above. - The vapid keys for web notifications have to be generated using
pnpx web-push generate-vapid-keys - The Next Auth secret (
NEXTAUTH_SECRET), Action API secret (ACTION_API_SECRET), TRPC API secret (TRPC_API_SHARED_KEY) and Vercel Cron Secret (CRON_SECRET) have to be filled with 32-byte Base64-encoded secrets. See Generate secrets below. - The data encryption passphrase (
DATA_ENCRYPTION_PASSPHRASE) has to be filled with a 24-byte Base64-encoded secret. See Generate secrets below. - You may define a Weather API key (
WEATHER_API_KEY) to use the weather API and stream overlay. See Weather API below. - If you are using Twitch authentication, you may define privileged users once they have signed in in the
SUPER_USER_IDSvariable with their CUID (using comma separated values)
- If your feature is not related to Twitch authentication, you can set
- Copy
apps/database/.env.exampletoapps/database/.env - Copy
apps/donations/worker/.env.exampletoapps/donations/worker/.env- Copy your
TRPC_API_SHARED_KEYfromapps/website/.envas the value forSHARED_KEY - Set a secret for Twitch EventSub as the value for
TWITCH_SUBSCRIPTION_SECRET. See Twitch EventSub secrets for more info. This is used to verify that incoming EventSub webhooks are actually from Twitch.
- Copy your
- Push the database schema to the new database using
pnpm prisma db pushfrom withinapps/database. - Start the dev server using
pnpm devfrom withinapps/website - The website should be running at
http://localhost:3000/(open in browser)
- Learn more about the stack at Create T3 App - Introduction
- You can use the Prisma Studio to view your database. Launch it with
pnpm prisma studiofrom withinapps/database - To change the database schema, see
apps/database/README.md - You can access a direct MySQL CLI to the database with
docker compose exec db sh -c 'MYSQL_PWD=$MYSQL_ROOT_PASSWORD mysql alveusgg' - If you're using VSCode, add
"typescript.tsdk": "node_modules/typescript/lib"+"eslint.workingDirectories": [{ "pattern": "apps/*" }]to.vscode/s 8000 ettings.jsonto ensure you're using the correct TypeScript version + ESLint working directories
We use Base64-encoded random strings for various secrets. To generate these secrets you can use OpenSSL or Python. OpenSSL should be preinstalled on most Unix-like systems (Linux, macOS, WSL). If neither is installed on your system, you may need to install it yourself.
- Using OpenSSL:
- Generate a 32-byte secret:
openssl rand -base64 32 - Generate a 24-byte secret:
openssl rand -base64 24
- Generate a 32-byte secret:
- Using Python:
You may need to call
python3instead depending on your installation.- Generate a 32-byte secret:
python -c "import os, base64; print(base64.b64encode(os.urandom(32)).decode('utf-8'))" - Generate a 24-byte secret:
python -c "import os, base64; print(base64.b64encode(os.urandom(24)).decode('utf-8'))"
- Generate a 32-byte secret:
Alveus operates a weather station on-site that uploads data to wunderground.com. Wunderground provide an API via api.weather.com that we use to display the weather for the stream overlay (and in the API for the Twitch chat bot). Accessing the API required an API key, which is only granted to users that have a weather station on wunderground.com.
It seems that anyone can sign up for a Wunderground account and register a weather station on the site, at which point you'll be granted access to the API, without ever needing to actually connect a weather station and upload data. It seems you can use this to get an API key to develop with the weather API locally.
In production, we use the actual API key for the account that is associated with the Alveus weather station, which does upload data to the site.
We use Cloudflare Stream to host a low-latency variation of the live cams specifically for camera operators. To do that, we need to do some setup with Cloudflare.
-
Login to the Cloudflare dashboard and navigate to Stream -> Live Inputs and click "Create Live Input"
-
Tick the "Require Signed URLs" box and leave the rest of the defaults
-
Click "Create Live Input" button
-
Make a note of the "Live Input ID", this will be used to configure the
CF_STREAM_LOLA_VIDEO_IDenvironment variable. -
Make a note of the host, this will be used to configure the
CF_STREAM_HOSTenvironment variable. It will look likecustomer-<unique-customer-id>.cloudflarestream.comand can be found under Connection Info -> WebRTC (WHIP) -> WebRTC (WHIP) URL. -
Create an API token with the
Stream:Editpermission. This is sometimes referred to as "Stream" under the "Account" dropdown. -
Use that token to make a request to create a set of signing keys for Cloudflare Stream. This is global to the account, not just this specific stream.
-
Make a note of the
idandjwkvalues, these will be used to configure theCF_STREAM_KEY_IDandCF_STREAM_KEY_JWKenvironment variables. -
Ensure that the following environment variables are set in
apps/website/.env:CF_STREAM_KEY_IDCF_STREAM_KEY_JWKCF_STREAM_LOLA_VIDEO_IDCF_STREAM_HOST
For the Neon CRM donation embed to load successfully, the site needs to be running with SSL on a domain that is trusted by Neon CRM. To aid local development with this, we've configured local.alveussanctuary.org to be trusted by Neon CRM and set it to resolve to 127.0.0.1 (localhost). Next.js can be started with HTTPS support bound to that hostname via pnpm dev:next --experimental-https --hostname local.alveussanctuary.org --port 443 in apps/website, allowing https://local.alveussanctuary.org to be accessed to test the Neon CRM donation embed locally.
You only need these when working on the chat bot or on donations and the pixel mural.
- Chat bot: Copy
apps/chatbot/.env.exampletoapps/chatbot/.env. SetAPI_SECRETto the website'sACTION_API_SECRET, and fill in the same Twitch client ID and secret as the website. The bot reads its Twitch token from the database, but a normal sign-in only grants basic scopes. So first sign in to your local website as the bot account (BOT_USER_ID) using the Log in button under Provide auth on the admin Twitch API page (/admin/twitch), which also grants the chat scopes (chat:readandchat:edit). That page is admin-only, so setDISABLE_ADMIN_AUTHtotrue(see step 6.i) or add your user toSUPER_USER_IDSbefore opening it. Then start it usingpnpm startfrom withinapps/chatbot. - Donations worker: After step 8 above, start it using
pnpm devfrom withinapps/donations/worker. It runs athttp://localhost:8787. To have the worker save donations to your local website, setSITE_URLtohttp://localhost:3000inapps/donations/worker/.env. To connect the website to the worker for the pixel mural, setNEXT_PUBLIC_DONATIONS_MANAGER_URLtohttp://localhost:8787inapps/website/.env.
The stack should work on any Node.js server or Next.js capable hosting provider and any MySQL server, but has only been tested on Vercel (and PlanetScale) for now.
- Create a twitch application (see Development setup above)
- Create a PlanetScale account or provide your own MySQL server, that should give you two DSN for the main and shadow database (something like
mysql://user:pass@us-east.connect.psdb.cloud/alveusgg?sslaccept=strictandmysql://user:pass@us-east.connect.psdb.cloud/alveusgg/shadow?sslaccept=strict) - Set up some S3-compatible storage for file uploads (e.g. DigitalOcean Spaces, Backblaze R2 or AWS S3)
- Go through the
apps/website/.env.exampleand create your ownapps/website/.env.production(see Development setup above) and also:- Fill the Prisma section with the database info (DSN)
- Fill in the S3 section with your S3-compatible storage info
- Push the database schema to the new database using
pnpm prisma db pushfrom withinapps/database. - Get your own domain (optional)
- Create a Vercel account
- Create a new Vercel project with these settings:
- General:
- Framework Preset:
Next.js, leave the other build/dev settings on the default option - Root directory:
apps/website - Node.js Version: See
enginesinpackage.jsonfor the required version
- Framework Preset:
- Domains: add your domains
- Git: connect your Git repo
- Environment Variables: Copy your
apps/website/.env.productionhere, and addGH_PKG_REGISTRY_TOKEN: a GitHub personal access token with theread:packagesscope. The install command inapps/website/vercel.jsonuses it to install@alveusgg/data.
- General:
Both deploy automatically through GitHub Actions when a push to main (production) or preview changes their files (each workflow has a paths filter). They can also be started manually from the Actions tab.
- The chat bot is rebuilt and restarted with Docker Compose over SSH, see
update-chatbot.yml. - The donations worker is deployed to Cloudflare with Wrangler, see
update-donations-worker.yml.