Skip to content

rachit23tech/VoteQuest

Repository files navigation

VoteQuest โ€” Gamified Election Assistant

An interactive, gamified platform to teach election processes, timelines, and civic engagement through gameplay. Transform voters into election strategists.

Live Demo API Status License: MIT

Tech Stack: Next.js 15+ | FastAPI | PostgreSQL | Google Cloud Run


๐ŸŽฎ Project Vision

Most election resources are dry, static, and forgettable. VoteQuest gamifies the learning experience โ€” users progress through levels as virtual campaign managers, earning points and badges while mastering real election processes.

What Makes It Stand Out

  • Interactive โ€” Drag-and-drop, puzzle-based learning
  • Personalized โ€” State-specific rules embedded in gameplay
  • Engaging โ€” Points, badges, leaderboards, time pressure
  • Educational โ€” Master real deadlines, requirements, logistics
  • Shareable โ€” Compete with friends, viral potential
  • Mobile-First โ€” Works on any device

๐Ÿ”— Live Deployments


๐Ÿ“‹ Feature Overview

Core Gameplay (MVP)

Level 1: Voter Registration Challenge

  • Mechanics: Drag voter profiles to correct registration centers
  • Duration: 3-minute timer
  • Challenge: 8/10 voters must be registered correctly
  • State Rules: ID requirements, eligibility checks vary by state
  • Scoring: Base 100 + time bonus + accuracy multiplier
  • Learning Outcome: Understand registration deadlines and requirements

Level 2: Campaign Trail (Post-MVP)

  • Resource management (budget, volunteers, time)
  • Navigate state-specific voting rules
  • Boss battle: Debate opponent with election trivia

Level 3: Get Out The Vote (GOTV) (Post-MVP)

  • Early voting mechanics puzzle
  • Polling place logistics challenges
  • Day-of problem-solving scenarios

Level 4: Election Night (Post-MVP)

  • Results calculation mechanics
  • Vote counting process simulation
  • Final scoring and achievements

๐Ÿ† Gamification Elements

Feature Implementation
Points System +100 base per level, +time bonus, +accuracy multiplier
Achievements 6 badges: "First Vote", "Early Bird", "Accessibility Champion", "On Fire", "All States Master", "Speed Racer"
Leaderboard Global top 10, weekly rankings, state-by-state competition
Progression 4 levels, unlock new content, save game state
Streaks Consecutive level completions = bonus multiplier
Narrative Unique storyline for each state (political lore)
Time Pressure Countdown timers simulate real deadline urgency
Consequences Wrong choices = time/point penalties (teaches real impact)

Achievement Badges

  • ๐Ÿ† "First Vote" โ€” Complete Level 1
  • โฐ "Early Bird" โ€” Register 30+ days early
  • ๐Ÿ‘ฅ "Accessibility Champion" โ€” Help all voters with accessibility needs
  • ๐Ÿ”ฅ "On Fire" โ€” 5-level streak without mistakes
  • ๐ŸŒ "All States Master" โ€” Complete levels in all 50 states
  • โšก "Speed Racer" โ€” Complete level in under 2 minutes

๐Ÿ“ฆ Tech Stack

Frontend

Framework:        Next.js 15+ (React 18+)
Language:         TypeScript
Styling:          Tailwind CSS + Framer Motion
State Management: Zustand (game state) + React Query (server state)
Game Mechanics:   Konva.js (drag-and-drop), react-beautiful-dnd
Testing:          Vitest + React Testing Library
Deployment:       Netlify

Backend

Framework:        FastAPI (Python 3.10+)
Database:         PostgreSQL + SQLAlchemy ORM
Authentication:   JWT (stateless) with OAuth2PasswordRequestForm
Validation:       Pydantic
Testing:          pytest
Deployment:       Google Cloud Run

Database

Primary:          PostgreSQL
ORM:              SQLAlchemy
Migrations:       Alembic

๐Ÿ—‚๏ธ Project Structure

votequest/
โ”‚
โ”œโ”€โ”€ frontend/                          # Next.js App
โ”‚   โ”œโ”€โ”€ next.config.js
โ”‚   โ”œโ”€โ”€ tsconfig.json
โ”‚   โ”œโ”€โ”€ tailwind.config.js
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”‚   โ””โ”€โ”€ assets/
โ”‚   โ”‚       โ”œโ”€โ”€ flags/                # State flags
โ”‚   โ”‚       โ”œโ”€โ”€ avatars/              # Voter avatars
โ”‚   โ”‚       โ””โ”€โ”€ icons/                # UI icons
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ app/
โ”‚       โ”‚   โ”œโ”€โ”€ layout.tsx            # Root layout
โ”‚       โ”‚   โ”œโ”€โ”€ page.tsx              # Homepage
โ”‚       โ”‚   โ”œโ”€โ”€ auth/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ login/page.tsx
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ signup/page.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ game/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx          # Game hub
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ level/[id]/page.tsx
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ results/page.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ leaderboard/page.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ profile/page.tsx
โ”‚       โ”‚   โ””โ”€โ”€ about/page.tsx
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ components/
โ”‚       โ”‚   โ”œโ”€โ”€ Game/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ GameContainer.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ LevelSelector.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ Level1_Registration.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ Level2_Campaign.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ Level3_GOTV.tsx
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ Level4_Results.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ UI/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ PointsDisplay.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ ProgressBar.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ TimerWidget.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ AchievementPopup.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ Button.tsx
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ Card.tsx
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ Modal.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ Leaderboard/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ LeaderboardTable.tsx
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ StateRanking.tsx
โ”‚       โ”‚   โ””โ”€โ”€ Layout/
โ”‚       โ”‚       โ”œโ”€โ”€ Header.tsx
โ”‚       โ”‚       โ””โ”€โ”€ Sidebar.tsx
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ hooks/
โ”‚       โ”‚   โ”œโ”€โ”€ useGameState.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useTimer.ts
โ”‚       โ”‚   โ”œโ”€โ”€ usePoints.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useLeaderboard.ts
โ”‚       โ”‚   โ””โ”€โ”€ useAchievements.ts
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ store/
โ”‚       โ”‚   โ””โ”€โ”€ gameStore.ts          # Zustand store
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ lib/
โ”‚       โ”‚   โ”œโ”€โ”€ api.ts                # API client
โ”‚       โ”‚   โ””โ”€โ”€ utils.ts              # Helper functions
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ types/
โ”‚       โ”‚   โ””โ”€โ”€ index.ts              # TypeScript interfaces
โ”‚       โ”‚
โ”‚       โ””โ”€โ”€ styles/
โ”‚           โ””โ”€โ”€ globals.css
โ”‚
โ”œโ”€โ”€ backend/                           # FastAPI App
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ”œโ”€โ”€ .env.example
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”‚   โ”œโ”€โ”€ database.py
โ”‚   โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ game.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ leaderboard.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ states.py
โ”‚   โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ user.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ game.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ score.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ achievement.py
โ”‚   โ”‚   โ”œโ”€โ”€ schemas/
โ”‚   โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ scoring.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ validation.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ auth.py
โ”‚   โ”‚   โ””โ”€โ”€ crud/
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ migrations/
โ”‚   โ”œโ”€โ”€ tests/
โ”‚   โ”‚   โ”œโ”€โ”€ test_auth.py
โ”‚   โ”‚   โ”œโ”€โ”€ test_game.py
โ”‚   โ”‚   โ”œโ”€โ”€ test_scoring.py
โ”‚   โ”‚   โ””โ”€โ”€ conftest.py
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ data/
โ”‚       โ””โ”€โ”€ election_data.json        # Seed data for all 50 states
โ”‚
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

๐Ÿ—„๏ธ Database Schema

users

- id (PK)
- username (UNIQUE, VARCHAR)
- email_hash (VARCHAR)
- password_hash (VARCHAR)
- state (CHAR(2), Foreign Key)
- total_score (INT, default 0)
- created_at (TIMESTAMP)
- updated_at (TIMESTAMP)

game_sessions

- id (PK)
- user_id (FK -> users)
- state (CHAR(2))
- current_level (INT)
- progress_json (JSONB)
- started_at (TIMESTAMP)
- completed_at (TIMESTAMP, nullable)

scores

- id (PK)
- user_id (FK -> users)
- level (INT)
- points (INT)
- accuracy (FLOAT)
- time_taken (INT, seconds)
- timestamp (TIMESTAMP)

achievements

- id (PK)
- user_id (FK -> users)
- badge_name (VARCHAR)
- unlocked_at (TIMESTAMP)

election_data

- id (PK)
- state_code (CHAR(2), UNIQUE)
- state_name (VARCHAR)
- registration_deadline (DATE)
- early_voting_start (DATE)
- early_voting_end (DATE)
- election_day (DATE)
- polling_info (JSONB)
- id_requirements (JSONB)
- accessibility_rules (JSONB)

๐ŸŽฏ Scoring Algorithm

def calculate_score(
    base_points: int = 100,
    time_taken: int,  # seconds
    correct_answers: int,
    total_answers: int,
    accessibility_bonus: bool = False
) -> int:

    # Time bonus: Up to +100 points for finishing under 3 minutes
    time_bonus = max(0, (300 - time_taken) / 3)

    # Accuracy multiplier (0 to 1)
    accuracy_multiplier = correct_answers / total_answers

    # Base calculation
    score = (base_points * accuracy_multiplier) + time_bonus

    # Accessibility bonus: +50 points for inclusive gameplay
    if accessibility_bonus:
        score += 50

    return int(score)

Example Scoring Scenarios

Scenario Base Time Bonus Accuracy Accessibility Total
Perfect run (2:30) 100 +23.3 ร—1.0 +50 173
Good run (3:00) 100 +0 ร—0.9 - 90
Moderate run (3:30) 100 -10 ร—0.8 - 70

๐Ÿš€ Development Phases

Phase 1: Project Setup & Infrastructure โœ… COMPLETED

  • Initialize Next.js with TypeScript
  • Configure Tailwind CSS + Prettier + ESLint
  • Setup Zustand store structure
  • Initialize FastAPI project with SQLAlchemy + PostgreSQL
  • Configure JWT authentication with automatic table creation
  • Seed election data (50 states)

Phase 2: Core Game Engine โœ… COMPLETED

  • Implement /api/game/start endpoint
  • Build scoring calculation engine
  • Implement achievement checking and leaderboard queries
  • Build GameContainer and all four Level components
  • Implement drag-and-drop mechanics, timer, and results screen
  • Full TypeScript type coverage across all React components

Phase 3: Gamification Features ๐Ÿ”„ IN PROGRESS

  • Points calculation and achievement unlock logic
  • Global and state-by-state leaderboard API
  • Leaderboard UI components
  • Badge display system
  • Game state save/load to database

Phase 4: Frontend UI & Polish ๐Ÿ”„ IN PROGRESS

  • Home/splash page, auth pages, level gameplay pages, results screen
  • Reusable component library
  • Game hub page, leaderboard page, profile/stats page
  • Dark mode, level transition animations, toast notifications

Phase 5: State Data & Integration

  • All 50 states populated with real election data
  • State-specific rule engine
  • Voter profile generator, election trivia database

Phase 6: Testing & Deployment

  • Unit + integration tests (backend: pytest, frontend: Vitest)
  • E2E tests with Playwright
  • CI/CD pipeline

๐Ÿ“Š MVP Status

Milestone Status
Level 1 fully playable โœ… Done
Level 2โ€“4 component structure โœ… Done
User authentication โœ… Done
Scoring system โœ… Done
Full TypeScript coverage โœ… Done
All 50 states with election data โœ… Done
Frontend deployed โœ… Live
Backend deployed โœ… Live
Leaderboard UI โณ Pending
Achievement badge display โณ Pending
Mobile responsiveness testing โณ Pending
Test suite (>80% coverage) โณ Pending

๐Ÿ“ˆ API Endpoints

Authentication

POST   /api/auth/register
POST   /api/auth/login
POST   /api/auth/logout
GET    /api/auth/me

Game Management

POST   /api/game/start
GET    /api/game/session/{id}
POST   /api/game/level/{level}/submit
POST   /api/game/level/{level}/action
GET    /api/game/history

Scoring & Achievements

GET    /api/leaderboard
GET    /api/leaderboard/weekly
GET    /api/leaderboard/state/{state}
GET    /api/achievements
GET    /api/stats

Election Data

GET    /api/states
GET    /api/states/{state}
GET    /api/voters/generate
GET    /api/election-facts

๐Ÿ” Environment Variables

Frontend (frontend/.env.local)

NEXT_PUBLIC_API_URL=http://localhost:8000

Backend (backend/.env)

DATABASE_URL=postgresql://votequest_user:password123@localhost:5432/votequest_db
SECRET_KEY=your-secret-key-min-32-chars-change-in-production
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=1440
CORS_ORIGINS=["http://localhost:3000"]
ENVIRONMENT=development
DEBUG=true

๐ŸŽฎ Game State Flow

User lands on /           โ†’ Splash page
  โ†“ clicks "Start Playing"
/auth/signup              โ†’ Creates account (username, email, password, state)
  โ†“ auto-login
/game                     โ†’ Game Hub
  โ†“ selects state + clicks "Play Level"
/game/level/1             โ†’ Level 1: Voter Registration Challenge
  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  โ”‚ PLAYING: drag voter cards โ†’ registration zones        โ”‚
  โ”‚  โ”‚ Timer counts down from 3:00                          โ”‚
  โ”‚  โ”‚ Feedback: โœ“ green / โœ— red per placement              โ”‚
  โ”‚  โ”‚ Submit early after 8+ placements OR wait for timer   โ”‚
  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  โ†“ level complete
/game/results             โ†’ Score tier (S/A/B/C/D/F), accuracy, time, achievements
  โ†“
/leaderboard              โ†’ Global / weekly rankings
/profile                  โ†’ Stats, achievement badges

๐Ÿ“ฆ Voter Profile Data Structure (Level 1)

interface VoterProfile {
  id: string;
  name: string;
  age: number;
  emoji: string;
  situation: string;
  detail: string;
  answer: 'online' | 'mail' | 'in-person';
  hint: string;
}
Situation Correct Zone Reason
Has internet + valid ID Online Fast, standard path
Homebound / rural no internet Mail-In No alternative access
First-time voter (some states) In-Person State law requirement
Expired / lost ID In-Person Staff assistance needed
Language assistance needed In-Person Bilingual staff available
Overseas military (UOCAVA) Mail-In Federal provision

๐Ÿ› ๏ธ Installation & Setup

Prerequisites

  • Node.js 18+
  • Python 3.10+
  • PostgreSQL 13+
  • Git

Frontend Setup

cd frontend
npm install
cp .env.example .env.local
npm run dev
# http://localhost:3000

Backend Setup

cd backend
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
python -m app.seed
uvicorn app.main:app --reload
# http://localhost:8000/docs

Docker Setup (Recommended)

docker-compose up -d
# Frontend: http://localhost:3000
# Backend:  http://localhost:8000/docs
# PostgreSQL: localhost:5432
docker-compose exec backend python -m app.seed

๐Ÿ“ฑ Frontend Routes

Route Purpose
/ Homepage / Splash screen
/auth/login Login page
/auth/signup User registration
/game Game hub
/game/level/1 Level 1 (Voter Registration)
/game/results Post-level results screen
/leaderboard Global + state rankings
/profile User stats & achievements
/about How elections work

๐Ÿ”’ Security Notes

  • JWT tokens: 24-hour expiry. Currently stored in localStorage (acceptable for MVP; switch to httpOnly cookies for production).
  • Passwords: bcrypt-hashed via passlib.
  • CORS: Restricted to CORS_ORIGINS list โ€” never use * in production.
  • Rate limiting: Not implemented in MVP. Add slowapi before production.
  • SQL injection: SQLAlchemy ORM parameterizes all queries.

๐Ÿ“š Learning Outcomes

By playing VoteQuest, users will understand:

  1. Registration Process โ€” Deadlines, requirements, where to register
  2. Eligibility โ€” Age, citizenship, residency requirements
  3. Accessibility โ€” ADA accommodations, language assistance
  4. Voting Methods โ€” Early voting, mail-in, in-person
  5. State Variations โ€” Why each state has different rules
  6. Logistics โ€” Why counting takes time, how audits work
  7. Deadlines โ€” Why they matter and what happens if missed
  8. Civic Responsibility โ€” The work behind fair elections

๐Ÿš€ Future Features

  • Levels 2, 3, 4 fully implemented
  • Multiplayer mode (real-time challenges)
  • Teacher dashboard
  • Mobile app (React Native)
  • AI opponent (trivia battles, strategy)
  • Internationalization (other countries' election processes)
  • Social features (friend challenges, team mode)

๐Ÿ™ Acknowledgments


๐Ÿ“ License

MIT License โ€” see LICENSE for details.


Version: 1.0.0

About

A Website where people who have never taken part in elections can go through the process and importance of elections.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors