Skip to content

About

Where consensus finds its voice

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

dēmos

Where consensus finds its voice

A full-stack consensus and voting platform. Create a session, vote your way, and watch the decision form in real time.

Live demo · System design doc · Contributor guide

Next.js React TypeScript Supabase Tailwind CSS


About

Group decisions get lost in endless threads and buried polls, and nobody remembers who decided what or why. dēmos puts the whole cycle in one place: propose, vote, see results, and keep a record that sticks.

Groups live in workspaces (same many-to-many model as Slack or Discord) and hold voting sessions on anything from a hiring priority to where to eat Friday. Two workspace flavors ship today:

  • Standard: admin controlled, public or private sessions, restrained and information dense.
  • F&F: always public, casual, built for keeping a running record of friend-group votes.

Features

Three voting formats Single choice, multiple choice, and ranked choice with instant-runoff tallying.
Live results Bars update as votes land, powered by Supabase Realtime on Postgres changes.
Guest voting Share a join code and vote with no account, backed by Supabase anonymous sessions so one browser gets one vote.
Session lifecycle Draft, open, closed, and results released, with hidden or live result visibility per session.
Access control in the database Row Level Security policies decide who can see and do what, not just app code.
Ballot secrecy Selections are exposed through an anonymized ballot reference so a vote can never be traced back to a voter.
Departments Workspace sub-groups for targeting sessions at part of a team.
Invites and notifications Workspace and session invite codes, email invites, and in-app notifications with a realtime bell.
Light and dark themes Semantic CSS variable tokens, applied before first paint so there is no flash of the wrong theme.

Tech stack

Layer Choice
Frontend and server logic Next.js 15 (App Router), React 19, Server Actions
Styling Tailwind CSS with semantic color tokens
Database Postgres via Supabase
Auth Supabase Auth (email/password plus anonymous sessions)
Realtime Supabase Realtime (Postgres Changes)
Access control Postgres Row Level Security
Edge functions Supabase Functions (session invites, notification events)
Charts Recharts
Tests Vitest
Hosting Vercel (app) and Supabase (data, auth, realtime)

MERN and plain React were both considered and rejected. The reasoning is written up in section 4 of the system design doc.

Project structure

Code is colocated by feature rather than by file type, so a bug in one feature means opening one folder instead of hunting across the repo. Only page.tsx, layout.tsx, and route.ts are routes, so _lib and _components folders sit safely alongside them.

app/
  (auth)/            login, signup, and their schema/actions
  workspaces/        list, create, [id] detail and overview
  family/            F&F casual mode surfaces
  sessions/
    create/          session creation
    vote/            join and vote entry point
    [id]/            voting client and results display
    _lib/            schema.ts, actions.ts, tally.ts, tally.test.ts
  notifications/     notification bell, actions, schema
  settings/          account settings
components/          shared UI (logo, theme toggle, dashboards, modals)
lib/
  supabase/          server, client, admin, middleware clients
  types/             generated database types (do not hand edit)
supabase/
  migrations/        22 numbered SQL migrations, one per module
  functions/         notify-events, send-session-invite
demos-system-design.md   living design reference
CLAUDE.md                conventions and rules for AI-assisted changes

Data model

Twelve tables cover the whole product: profiles, workspaces, workspace_memberships, workspace_groups, workspace_group_members, invites, voting_sessions, session_options, votes, vote_selections, session_access_grants, and notifications.

Two design choices worth calling out:

  • votes and vote_selections are split. The votes row is the envelope that proves one ballot was cast; the selections are the choices inside it. Single, multiple, and ranked choice all use the same two tables, with only rank varying, and weighted voting later becomes a column addition rather than a redesign.
  • Integrity is enforced by constraints, not by trust. Unique keys on (session_id, user_id), (vote_id, option_id), and (vote_id, rank) make double voting, duplicate selections, and duplicate ranks structurally impossible.

Instant-runoff tallying

Ranked choice is tallied by real IRV in app/sessions/_lib/tally.ts: count first choices, eliminate the lowest, redistribute those ballots to their next surviving option, and repeat until something clears a majority. Two cases the design doc left open are decided in code and covered by unit tests:

  • Exhausted ballots (no ranked options left) are dropped from both the round count and the majority denominator instead of being counted for nobody.
  • A tie for lowest eliminates every tied option in the same round, with a guard for the case where all remaining options are tied.

The tallying functions are pure and kept out of actions.ts, which is a 'use server' module, so they can be unit tested directly.

npm test

Getting started

Prerequisites: Node 18 or newer, a Supabase project, and the Supabase CLI.

git clone https://github.com/malgmash/Demos.git
cd Demos
npm install

Create .env.local:

NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key   # server side only, never expose to the client

Apply the schema and start the app:

supabase link --project-ref your-project-ref
supabase db push          # applies supabase/migrations in filename order
npm run dev               # http://localhost:3000

Enable anonymous sign-ins in Supabase Auth settings if you want guest voting to work locally.

After any schema change, regenerate types instead of editing them by hand:

supabase gen types typescript --linked > lib/types/database.ts

Scripts

Command What it does
npm run dev Start the dev server
npm run build Production build
npm start Serve the production build
npm run lint ESLint via eslint-config-next
npm test Run the Vitest suite

Security notes

Access control lives in the database. Every table carries RLS policies, and privileged reads go through security-definer functions with search_path pinned so they cannot be hijacked by a shadowed schema. Migration 014_ballot_secrecy.sql closed a real hole where vote_selections could be joined back to votes through vote_id, replacing that link with a dense_rank() derived anonymized ballot reference.

Known gap, deliberately deferred: there is no CAPTCHA or Turnstile on anonymous sign-in. That is fine for a demo, and should be added before any genuinely public deployment.

Roadmap

  • Post-results comments (admin toggled, off by default)
  • Weighted voting
  • Custom result themes
  • CAPTCHA on anonymous sign-in
  • Broader test coverage and CI

Contributors

@malgmash Backend logic, system design, data model, authorization, and tallying
@gbemilekeadesiyan-a11y Frontend

License

Not currently licensed for reuse. Add a LICENSE file if you want to change that.

About

Where consensus finds its voice

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages