- Website: https://furnovskyland.vercel.app/
- Discord Server: https://discord.gg/UjcUnNhNfk
Furnovskyland is an online community and constitutional monarchy founded in 2018. Over time, its governance evolved to include a written constitution, a Senate, a federal government, a Supreme Court, and regular elections and legislative votes.
Running elections and law votes inside Discord channels through message reactions or generic poll bots created recurring problems:
- No secret ballot: Public reaction polls expose how each member voted, creating social pressure and tactical voting as people watch live tallies.
- Rigid voting systems: Standard Discord polls cannot run instant-runoff (ranked-choice) elections, multi-seat plurality elections, or legislative votes that require specific quorum thresholds, two-thirds supermajorities, and constitutional veto windows.
- Weak eligibility and anti-abuse controls: Restricting specific votes to particular server roles (such as Senators, Ministers, or verified citizens) while detecting duplicate or newly created alternate accounts is difficult without a dedicated backend.
The goal of this project is to solve those problems in a single, self-contained web application. It serves both as the multilingual public portal for Furnovskyland (in English, Hungarian, German, and Slovak) and as a verifiable, role-gated voting system that any Discord-based community, organization, or online state can self-host and adapt for its own governance.
- Citizens sign in with Discord OAuth2 (
identifyscope). - Session state is stored in an HTTP-only, HMAC-SHA256 signed cookie (
lib/session.ts). - A lightweight Discord bot reads the voter's current membership and roles directly from the Discord guild API (
lib/discord.ts). The bot does not need administrative permissions on the server; it only reads member and role lists. - Each vote can be opened to every server member or restricted to a specific set of Discord roles. An optional server-wide login whitelist (
LOGIN_ROLE_IDS) can also restrict platform access during testing or closed sessions.
- Law Vote (
law): Yes / No / Abstain ballots. Supports simple majority (> 50%of Yes + No) or two-thirds majority (>= 2/3of Yes + No), optional minimum ballot quorum (counting abstentions toward turnout), and an configurable post-passage veto window for the head of state (EMPEROR_ROLE_IDS). - Single-Choice Election (
single): Standard first-past-the-post election where each voter selects one candidate. - Multi-Choice Election (
multi): Voters select up toNcandidates; the topNcandidates win, with automatic tie detection at the cutoff. - Ranked-Choice Election (
ranked): Instant-runoff voting where voters number candidates in order of preference. If no candidate reaches a majority in round one, the lowest-polling candidates are eliminated round by round and their ballots transfer to the next ranked preference until a winner is decided or a tie is reached.
- Public pages never reveal individual ballots, and results remain hidden until the vote closes.
- Administrators can view the voter roll (who voted and when) without ever seeing what a voter chose.
- To guard against duplicate voting with alternate accounts, each ballot records a device token and an HMAC-SHA256 hash of the client IP address (raw IP addresses are never stored). The admin panel automatically flags ballots that:
- Share a device cookie with another voter in the same election
- Share a hashed IP connection with another voter in the same election
- Come from a Discord account created less than 30 days before the vote
- Come from a member who joined the Discord server less than 7 days before the vote
- Administrators can void (or restore) flagged ballots at any point before the election closes.
- Each published vote transitions automatically through
scheduled -> open -> veto_window (if applicable) -> final(orvetoed/cancelled). - State transitions use atomic conditional SQL updates so concurrent background jobs and page requests never double-count or double-post announcements.
- When a vote opens, closes with results, is vetoed, or becomes final, the server posts an embed via Discord webhook to the configured channel(s).
- Bun (v1.3 or newer)
- A Discord account and server where you can create an application, invite a bot, and create channel webhooks
- For production: any PostgreSQL database (self-hosted Postgres, Docker Postgres, Neon, Supabase, Railway, etc.). For local development, no external database is needed.
Clone the repository and install dependencies:
git clone https://github.com/CsPS0/WebSite-Furnovskyland.git
cd WebSite-Furnovskyland
bun install
cp .env.example .env.localGenerate two random 32+ character secrets for AUTH_SECRET and IP_HASH_SECRET in .env.local:
openssl rand -base64 32When DATABASE_URL is left empty in .env.local, the application automatically uses an embedded PostgreSQL instance stored in .pglite/ and applies all database migrations on startup.
If you want to test the voting system locally before creating a Discord application, add the following to .env.local:
DEV_FAKE_LOGIN=1
DEV_FAKE_ROLES={"1001":["admin","emperor"],"1002":["senator"],"1003":[]}
ADMIN_ROLE_IDS=admin
EMPEROR_ROLE_IDS=emperorStart the development server:
bun run devThen visit http://localhost:3000/api/auth/login/?dev_user=1001&dev_name=Admin to sign in as an admin and open http://localhost:3000/en/admin/. (DEV_FAKE_LOGIN is disabled automatically when NODE_ENV=production.)
- Create a Discord Application:
- Open the Discord Developer Portal and create a new application.
- Configure OAuth2:
- Open the OAuth2 tab, copy the Client ID (
AUTH_DISCORD_ID) and Client Secret (AUTH_DISCORD_SECRET). - Under Redirects, add your callback URL with the trailing slash:
- Local:
http://localhost:3000/api/auth/callback/ - Production:
https://your-domain.example/api/auth/callback/
- Local:
- Open the OAuth2 tab, copy the Client ID (
- Configure and Invite the Bot:
- Open the Bot tab, reset and copy the bot token (
DISCORD_BOT_TOKEN). - Enable Server Members Intent under Privileged Gateway Intents and save.
- Invite the bot to your Discord server using:
https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot&permissions=0&guild_id=YOUR_GUILD_ID
- Open the Bot tab, reset and copy the bot token (
- Configure Webhooks and Role IDs:
- Set
DISCORD_GUILD_IDto your Discord server ID. - In your Discord server, create a webhook in your elections channel (Edit Channel -> Integrations -> Webhooks -> New Webhook) and set
DISCORD_WEBHOOK_URL. Optionally setDISCORD_LAW_WEBHOOK_URLif law votes should be announced in a separate gazette channel. - Copy the role IDs for your election administrators into
ADMIN_ROLE_IDSand the head-of-state role ID intoEMPEROR_ROLE_IDS.
- Set
This application is a standard Next.js 16 server application using PostgreSQL via Drizzle ORM (db/schema.ts, migrations in drizzle/). You can host it on any platform that supports Node.js/Bun and PostgreSQL:
- Provision a PostgreSQL Database:
- Create a PostgreSQL database on your preferred provider (a self-hosted VPS, Docker container, Railway, Fly.io, Render, Supabase, or Neon) and set
DATABASE_URLto its connection string.
- Create a PostgreSQL database on your preferred provider (a self-hosted VPS, Docker container, Railway, Fly.io, Render, Supabase, or Neon) and set
- Set Environment Variables:
- Configure all variables listed in
.env.example(SITE_URL,AUTH_SECRET,AUTH_DISCORD_ID,AUTH_DISCORD_SECRET,DISCORD_BOT_TOKEN,DISCORD_GUILD_ID,DISCORD_WEBHOOK_URL,ADMIN_ROLE_IDS,EMPEROR_ROLE_IDS,IP_HASH_SECRET,DATABASE_URL).
- Configure all variables listed in
- Build and Start:
- The build script automatically runs pending SQL migrations against
DATABASE_URLbefore compiling the application:bun run build bun run start
- On container or VPS hosts (Docker, systemd, Coolify, Dokploy, Railway, Fly.io, Render), run
bun run buildduring the image/build step andbun run start(port3000by default) as the runtime command. - On serverless Next.js platforms, point the project at the repository root with
bun run buildas the build command.
- The build script automatically runs pending SQL migrations against
bun test # Run unit tests (vote tallying, alt-account flags, session signing)
bun run lint # Run ESLint
bun run build # Run database migrations and production builddev: Default development branch for ongoing work and testing. All day-to-day commits and pushes go todev.main: Production branch. Changes are merged fromdevintomainonly when ready for a production release.
Released under the MIT License.