Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ VITE_FIREBASE_APP_ID=""

# Google Analytics measurement ID for Firebase Analytics (optional)
VITE_FIREBASE_MEASUREMENT_ID=""

# VPS deployment profile path, relative to the checkout (optional).
# e.g. instances/dev.json; blank defaults to instances/oscana.json.
# scripts/vps.sh reads the file before building and seeding. Public data only.
VITE_INSTANCE_CONFIG="instances/oscana.json"
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ARG BUILD_NODE_HEAP_MB=4096
# Build arguments for client-side environment variables (VITE_* prefix)
ARG VITE_APP_TITLE
ARG VITE_COMMIT_SHA
ARG VITE_INSTANCE_CONFIG
ARG VITE_FIREBASE_API_KEY
ARG VITE_FIREBASE_AUTH_DOMAIN
ARG VITE_FIREBASE_PROJECT_ID
Expand All @@ -39,6 +40,7 @@ ARG VITE_FIREBASE_MEASUREMENT_ID
# Set build-time environment variables
ENV VITE_APP_TITLE=${VITE_APP_TITLE}
ENV VITE_COMMIT_SHA=${VITE_COMMIT_SHA}
ENV VITE_INSTANCE_CONFIG=${VITE_INSTANCE_CONFIG}
ENV VITE_FIREBASE_API_KEY=${VITE_FIREBASE_API_KEY}
ENV VITE_FIREBASE_AUTH_DOMAIN=${VITE_FIREBASE_AUTH_DOMAIN}
ENV VITE_FIREBASE_PROJECT_ID=${VITE_FIREBASE_PROJECT_ID}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Oscana

For other Polsimmer deployments, see [instance configuration](docs/INSTANCE_CONFIGURATION.md). Oscana remains the default profile.

Oscana is a TanStack Start game application with PostgreSQL and Firebase Authentication. This branch (`revival`) is an unfinished rewrite of the `develop` version. See [the rewrite notes](docs/REVIVAL_OVERVIEW.md) for the main product changes and known gaps.

## Local development
Expand Down
2 changes: 2 additions & 0 deletions deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ chmod 600 /srv/democracyonline-dev/.env /srv/democracyonline-prod/.env

Replace every `CHANGE_ME` value. Keep each generated `DB_PASSWORD`, `DATABASE_URL`, `CRON_INTERNAL_TOKEN`, project name, port, and `SITE_URL` tied to its environment. A PostgreSQL password change requires changing both `DB_PASSWORD` and the password embedded in `DATABASE_URL`; after a database volume exists, rotate the database role password inside PostgreSQL too. Never copy one `.env` over the other.

To use a different profile, set `VITE_INSTANCE_CONFIG=instances/dev.json` in that checkout's `.env` (and commit the public JSON file for Actions deployments). `scripts/vps.sh` reads the path relative to the checkout and supplies its JSON to the app build and seeds. Leave the value blank or unset to use `instances/oscana.json`. Do not use `$(cat ...)` in `.env`. Rebuild to apply profile changes; seeds reset game data.

Firebase values come from the Firebase console as described in [Firebase Authentication](docs/FIREBASE_AUTH.md). For the current shared project, authorize both `oscana.nya.je` and `dev.oscana.nya.je`. When splitting the projects, authorize only the matching hostname in each. Use the service account JSON `project_id`, `client_email`, and JSON-escaped `private_key` in the corresponding `.env`. Put the key on one line, in double quotes, with literal `\n` sequences. `VITE_*` values are browser configuration; the service account private key must stay server-side. Set `ADMIN_EMAILS` to real admin addresses.

Check each configuration:
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
args:
BUILD_NODE_HEAP_MB: ${BUILD_NODE_HEAP_MB:-4096}
VITE_COMMIT_SHA: ${DEPLOY_COMMIT_SHA:-}
VITE_INSTANCE_CONFIG: ${VITE_INSTANCE_CONFIG:-}
VITE_FIREBASE_API_KEY: ${VITE_FIREBASE_API_KEY}
VITE_FIREBASE_AUTH_DOMAIN: ${VITE_FIREBASE_AUTH_DOMAIN}
VITE_FIREBASE_PROJECT_ID: ${VITE_FIREBASE_PROJECT_ID}
Expand All @@ -35,6 +36,7 @@ services:
NODE_ENV: production
HOST: 0.0.0.0
PORT: 3000
VITE_INSTANCE_CONFIG: ${VITE_INSTANCE_CONFIG:-}
ports:
- "127.0.0.1:${APP_PORT:?Set APP_PORT in .env}:3000"
depends_on:
Expand Down Expand Up @@ -70,6 +72,8 @@ services:
context: .
target: tooling
env_file: .env
environment:
VITE_INSTANCE_CONFIG: ${VITE_INSTANCE_CONFIG:-}
command: ["bun", "run", "db:migrate"]
depends_on:
db:
Expand Down
74 changes: 74 additions & 0 deletions docs/INSTANCE_CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Instance configuration

Polsimmer ships with the Oscana profile at [`instances/oscana.json`](../instances/oscana.json). Without an override, development, builds and fresh seeds use this profile. Start from the fully populated, copy-ready [`instances/example.json`](../instances/example.json), or copy Oscana's profile and edit it. For standalone seed commands, set `VITE_INSTANCE_CONFIG` to the profile's **JSON contents**; for example:

```sh
export VITE_INSTANCE_CONFIG="$(cat instances/my-nation.json)"
bun run build
```

JSON does not support comments, so `instances/example.json` is valid, uncommented JSON. To leave optional settings disabled in your own profile, delete those fields; the defaults below will apply. For a commented reference while editing, optional examples are shown in JSONC (JSON with comments):

```jsonc
{
"id": "my-nation", // Unique lowercase slug; also used to namespace browser drafts/events.
"name": "My Nation", // Instance/community name shown in the app.
"nationName": "The Republic of Example", // Used when creating the nation in a fresh seed.
"description": "A player-led political world.",
"domain": "https://example.org", // Public canonical URL; use your real domain.
"locale": "en-US", // BCP 47 locale.
"timeZone": "UTC", // IANA time zone.
"branding": {
"logo": "/logo.png", // Root-relative file in public/.
"icon": "/favicon.ico",
"socialName": "Public Square" // Optional; defaults to "Social".
},
// Optional. Omit community if you don't have an instance Discord/community.
"social": { "community": "https://discord.gg/your-invite-code" },
"terminology": { // Optional; omitted labels use these defaults.
"president": "President",
"senate": "Senate",
"house": "House",
"party": "Party"
},
"features": { // Optional; both default to true. These hide UI, not access-control gates.
"social": true,
"browserNotifications": true
},
"theme": { // Optional; defaults to dark. Use a built-in ID or display label.
"default": "Default (Dark)",
// Optional custom default palette; use accessible six-digit hex colors.
"colors": {
"mode": "dark",
"background": "#111827",
"foreground": "#f9fafb",
"primary": "#60a5fa",
"accent": "#34d399"
}
},
"game": { // Optional UTC cron schedules.
"billAdvanceScheduleUtc": "0 4,12,20 * * *",
"gameAdvanceScheduleUtc": "0 20 * * *"
}
}
```

Remove comment markers and comments before saving: application config must be strict JSON. If you provide `theme.colors`, its `mode` controls the shared **Default** palette, replacing the built-in light/dark defaults. Players can still choose alternate themes or return to **Default** from the theme picker.

Set `VITE_INSTANCE_CONFIG=instances/dev.json` in the checkout's `.env` for local Vite development/builds or VPS deployments via `scripts/vps.sh`. Both resolve the path relative to the checkout and load its JSON; the VPS script also passes it to the seed container. An empty or absent value keeps the Oscana default. Direct Compose builds and standalone seed commands still require JSON contents, not a path. The profile contains **public data only** and is embedded into browser assets. Do not include secrets. Restart Vite or rebuild after edits; runtime changes do not change already-built browser assets. Use the same profile for application and seed commands. Supply the usual independent Firebase, database, `SITE_URL`, domain/DNS and deployment credentials for each installation.

The contract is the Zod `instanceSchema` in [`src/lib/instance-config.ts`](../src/lib/instance-config.ts). Required: `id` (lowercase slug, also namespaces browser events/drafts), `name`, `nationName` (fresh seed), `description`, `domain` (absolute URL), `locale` (valid BCP 47 tag), `timeZone` (IANA zone), and `branding.logo` / `branding.icon` (root-relative paths under `public/`). Validation rejects missing or invalid values with an `Invalid instance configuration` error. Put new image assets under `public/` and reference them by URL; `public/logo.png` and `public/favicon.ico` preserve Oscana's existing assets. Never put a private URL or key here.

Optional fields and defaults:

| Field | Default / purpose |
| --- | --- |
| `branding.socialName` | `Social`; name of the in-game social feed |
| `social.community` | absent; instance/nation community link shown in game navigation and login help. Polsimmer product footer links are fixed and not configurable per instance. |
| `terminology.president`, `.senate`, `.house`, `.party` | `President`, `Senate`, `House`, `Party`; display terminology (persisted roles, stages, API values and URLs remain unchanged) |
| `features.social`, `.browserNotifications` | `true`; hide the social navigation entry or the browser notification invitation; **not access-control gates** |
| `theme.default` | `dark`; a built-in theme ID (such as `dracula`) or label (such as `Default (Dark)`); used when a player has not chosen a theme |
| `theme.colors` | absent; optional shared default palette with `mode`, `background`, `foreground`, `primary`, and `accent` six-digit hex colors; players can choose alternatives |
| `game.billAdvanceScheduleUtc`, `.gameAdvanceScheduleUtc` | `0 4,12,20 * * *` and `0 20 * * *`; server scheduling defaults, still overridable by `BILL_ADVANCE_SCHEDULE_UTC` and `GAME_ADVANCE_SCHEDULE_UTC` |

The current political simulation uses fixed internal offices, stages and election mechanics. Terminology here is presentation-only; changing government structure or disabling features end-to-end requires additional implementation. Database `game_settings` and existing nation records remain persistent per-instance state, not deployment configuration. Historical migrations and Oscana-specific E2E guards are intentionally not renamed: they are database history and safety mechanisms, not instance branding. Demo election fixtures in `scripts/seed.ts` are not a production initialization path; use `seed:fresh` on a disposable database only.
13 changes: 13 additions & 0 deletions instances/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": "dev",
"name": "Dev",
"nationName": "Oscana (Dev)",
"description": "Dev sandbox.",
"domain": "https://dev.oscana.nya.je",
"locale": "en-US",
"timeZone": "UTC",
"branding": {
"logo": "/logo.png",
"icon": "/favicon.ico"
}
}
41 changes: 41 additions & 0 deletions instances/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"id": "my-nation",
"name": "My Nation",
"nationName": "The Republic of Example",
"description": "A player-led political world where parties compete, laws are debated, and every election can change the nation's direction.",
"domain": "https://example.org",
"locale": "en-US",
"timeZone": "UTC",
"branding": {
"logo": "/logo.png",
"icon": "/favicon.ico",
"socialName": "Public Square"
},
"social": {
"community": "https://discord.gg/your-invite-code"
},
"terminology": {
"president": "President",
"senate": "Senate",
"house": "House",
"party": "Party"
},
"features": {
"social": true,
"browserNotifications": true
},
"theme": {
"default": "Default (Dark)",
"colors": {
"mode": "dark",
"background": "#000000",
"foreground": "#f9fafb",
"primary": "#60a5fa",
"accent": "#34d399"
}
},
"game": {
"billAdvanceScheduleUtc": "0 4,12,20 * * *",
"gameAdvanceScheduleUtc": "0 20 * * *"
}
}
31 changes: 31 additions & 0 deletions instances/oscana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "oscana",
"name": "Oscana",
"nationName": "The Republic of Oscana",
"description": "Oscana is the ultimate political arena. Build parties, win elections, and pass legislation in a living democracy.",
"domain": "https://oscana.nya.je",
"locale": "en-US",
"timeZone": "UTC",
"branding": {
"logo": "/logo.png",
"icon": "/favicon.ico",
"socialName": "Z.com"
},
"social": {
"community": "https://discord.gg/kYdDXfJFdn"
},
"terminology": {
"president": "President",
"senate": "Senate",
"house": "House",
"party": "Party"
},
"features": {
"social": true,
"browserNotifications": true
},
"game": {
"billAdvanceScheduleUtc": "0 4,12,20 * * *",
"gameAdvanceScheduleUtc": "0 20 * * *"
}
}
7 changes: 5 additions & 2 deletions opencode.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"$schema": "https://opencode.ai/config.json",
"permission": "allow"
"$schema": "https://opencode.ai/config.json",
"permission": "allow",
"plugin": [
"@dietrichgebert/ponytail"
]
}
4 changes: 2 additions & 2 deletions public/push-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ self.addEventListener("push", (event) => {
}
}
event.waitUntil(self.registration.showNotification(
typeof message.title === "string" ? message.title.slice(0, 80) : "Oscana",
typeof message.title === "string" ? message.title.slice(0, 80) : "Notification",
{
body: typeof message.body === "string" ? message.body.slice(0, 120) : "You have a new notification.",
tag: typeof message.tag === "string" ? message.tag.slice(0, 100) : "oscana-mention",
tag: typeof message.tag === "string" ? message.tag.slice(0, 100) : "mention",
icon: "/favicon.ico",
data: { target },
},
Expand Down
4 changes: 3 additions & 1 deletion scripts/seed-fresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (!process.env.DATABASE_URL) {
loadEnvFile(process.env.COMPOSE_ENV_FILE ?? ".env");
}

const { instance } = await import("../src/lib/instance-config");

if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is required");
}
Expand Down Expand Up @@ -147,7 +149,7 @@ try {
["name", "civil_rights", "economy", "political_freedoms"],
[
[
"The Republic of Oscana",
instance.nationName,
headlines.civil_rights,
headlines.economy,
headlines.political_freedoms,
Expand Down
4 changes: 3 additions & 1 deletion scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { seedAjAvatar } from "./seed-aj-avatar";

loadEnvFile();

const { instance } = await import("../src/lib/instance-config");

if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is required");
}
Expand Down Expand Up @@ -354,7 +356,7 @@ async function seed() {
["name", "civil_rights", "economy", "political_freedoms"],
[
[
"The Republic of Oscana",
instance.nationName,
initialHeadlines.civil_rights,
initialHeadlines.economy,
initialHeadlines.political_freedoms,
Expand Down
9 changes: 8 additions & 1 deletion scripts/vps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ value() {
}
compose() { docker compose --env-file .env "$@"; }
check() {
local key val
local key val profile
for key in DEPLOYED_ENV COMPOSE_PROJECT_NAME APP_PORT SITE_URL DB_PASSWORD DATABASE_URL CRON_INTERNAL_TOKEN ADMIN_EMAILS FIREBASE_PROJECT_ID FIREBASE_CLIENT_EMAIL FIREBASE_PRIVATE_KEY VITE_FIREBASE_API_KEY VITE_FIREBASE_AUTH_DOMAIN VITE_FIREBASE_PROJECT_ID VITE_FIREBASE_STORAGE_BUCKET VITE_FIREBASE_MESSAGING_SENDER_ID VITE_FIREBASE_APP_ID; do
val="$(value "$key")"
if [[ -z "$val" || "$val" == *CHANGE_ME* || "$val" == *example.com* ]]; then
Expand All @@ -29,6 +29,13 @@ check() {
[[ "$(value DATABASE_URL)" == "postgresql://democracyonline:$(value DB_PASSWORD)@db:5432/democracyonline" ]] || { echo "DATABASE_URL and DB_PASSWORD do not match this project's database" >&2; return 1; }
[[ "$(value FIREBASE_PROJECT_ID)" == "$(value VITE_FIREBASE_PROJECT_ID)" ]] || { echo "Firebase project IDs differ" >&2; return 1; }
[[ "$(value CRON_INTERNAL_TOKEN)" =~ ^[a-f0-9]{64}$ ]] || { echo "CRON_INTERNAL_TOKEN must be 64 hex characters" >&2; return 1; }
profile="$(value VITE_INSTANCE_CONFIG)"
if [[ -n "$profile" ]]; then
[[ -s "$profile" ]] || { echo "Missing instance config file: $profile" >&2; return 1; }
export VITE_INSTANCE_CONFIG="$(cat "$profile")"
else
unset VITE_INSTANCE_CONFIG
fi
compose config --quiet
echo "Configuration OK for $(value DEPLOYED_ENV)"
}
Expand Down
32 changes: 32 additions & 0 deletions src/components/auth/auth-intro.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { instance } from "@/lib/instance-config";
import type { ReactNode } from "react";

export function AuthIntro({ children }: { children: ReactNode }) {
return (
<div className="relative flex flex-1 items-center justify-center overflow-hidden px-4 py-10 sm:py-16">
<div aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-hidden">
<div className="absolute -left-24 top-10 h-80 w-80 rounded-full bg-green-400/15 blur-3xl dark:bg-green-400/10" />
<div className="absolute -right-24 bottom-10 h-96 w-96 rounded-full bg-blue-400/15 blur-3xl dark:bg-blue-400/10" />
<div className="absolute left-1/2 top-1/2 h-96 w-96 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary/10 blur-3xl" />
</div>
<div className="relative grid w-full max-w-5xl items-center gap-10 lg:grid-cols-2 lg:gap-16">
<div className="space-y-6 text-center lg:text-left">
<p className="text-sm font-semibold uppercase tracking-widest text-primary">{instance.nationName}</p>
<h1 className="font-serif text-4xl font-bold tracking-tight sm:text-5xl">Welcome to {instance.name}</h1>
<p className="text-lg leading-relaxed text-muted-foreground">{instance.description}</p>
<div className="space-y-3 border-t pt-5 text-sm leading-relaxed text-muted-foreground">
<p><strong className="text-foreground">{instance.name} is an instance of Polsimmer</strong>, a free, open-source, self-hostable political simulation web game. Form parties, run in elections, debate bills, and shape a shared nation.</p>
<p>Anyone can host their own instance with its own nation, community, and political story.</p>
<div className="flex flex-wrap justify-center gap-x-5 gap-y-2 font-medium text-primary lg:justify-start">
<span>Host your own <a href="https://github.com/ajstrongdev/polsimmer" target="_blank" rel="noopener noreferrer" className="underline underline-offset-4 hover:text-primary/80">now</a>.</span>
{instance.social.community && (
<a href={instance.social.community} target="_blank" rel="noopener noreferrer" className="underline underline-offset-4 hover:text-primary/80">Join the {instance.name} community</a>
)}
</div>
</div>
</div>
<div className="w-full max-w-md justify-self-center space-y-4">{children}</div>
</div>
</div>
);
}
5 changes: 3 additions & 2 deletions src/components/bills/bill-comments.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { instance } from "@/lib/instance-config";
import { useState } from "react";
import { useRouter } from "@tanstack/react-router";
import type { CommentNode } from "@/lib/social-comment-tree";
Expand Down Expand Up @@ -274,7 +275,7 @@ export function BillComments({
</div>
<WikiSection
title="Discussion"
description="Comments are public and also appear on Z.com with a link back to this bill."
description={`Comments are public and also appear on ${instance.branding.socialName} with a link back to this bill.`}
aside={
<span className="text-xs text-muted-foreground">
{comments.length} comments
Expand Down Expand Up @@ -330,7 +331,7 @@ export function BillComments({
{content.trim() && (
<div className="mt-4 rounded-lg border bg-muted/20 p-3">
<p className="mb-2 text-xs font-semibold text-muted-foreground">
Preview on Z.com
Preview on {instance.branding.socialName}
</p>
<MarkdownContent
content={billCommentPostContent(billId, content)}
Expand Down
Loading
Loading