Skip to content

Latest commit

 

History

History
370 lines (288 loc) · 8.91 KB

File metadata and controls

370 lines (288 loc) · 8.91 KB

VoteQuest - Phase 1 Setup Complete ✅

Project Initialization Summary

Status: Phase 1 Complete - Project Structure & Core Setup Done
Date: April 25, 2026
What's Ready: Full backend and frontend scaffolding with database models, API endpoints, and UI components


📁 Project Structure Created

election-game/
├── backend/
│   ├── app/
│   │   ├── __init__.py
│   │   ├── main.py              # FastAPI app entry point
│   │   ├── config.py            # Settings management
│   │   ├── database.py          # Database setup
│   │   ├── models.py            # SQLAlchemy models
│   │   ├── schemas.py           # Pydantic schemas
│   │   ├── scoring.py           # Scoring algorithm
│   │   ├── auth.py              # JWT authentication
│   │   ├── api_auth.py          # Auth endpoints
│   │   ├── api_game.py          # Game endpoints
│   │   ├── api_leaderboard.py   # Leaderboard endpoints
│   │   └── api_election_data.py # Election data endpoints
│   ├── requirements.txt         # Python dependencies
│   ├── .env.example             # Environment template
│   └── Dockerfile               # Container setup
│
├── frontend/
│   ├── src/
│   │   ├── app/                 # Next.js app router
│   │   ├── components/
│   │   │   └── UI/
│   │   │       ├── Button.tsx
│   │   │       └── Card.tsx
│   │   ├── hooks/
│   │   │   ├── useTimer.ts
│   │   │   ├── usePoints.ts
│   │   │   ├── useApi.ts
│   │   │   └── index.ts
│   │   └── store/
│   │       └── gameStore.ts     # Zustand state management
│   ├── package.json             # Node dependencies
│   └── Dockerfile               # Container setup
│
├── docker-compose.yml           # Multi-container setup
├── .gitignore                   # Git ignore rules
└── README.md                    # Project documentation

✨ What's Been Built

Backend (FastAPI)

Database Models

  • User (username, email, state, score)
  • GameSession (user_id, state, level, progress)
  • Score (user_id, level, points, accuracy, time_taken)
  • Achievement (user_id, badge_name, unlocked_at)
  • ElectionData (state election information)

API Endpoints (20+ endpoints)

  • Authentication: /api/auth/register, /api/auth/login, /api/auth/me
  • Game: /api/game/start, /api/game/level/{id}/submit, /api/game/history
  • Leaderboard: /api/leaderboard, /api/leaderboard/weekly, /api/leaderboard/state/{state}
  • Election Data: /api/states, /api/states/{code}, /api/voters/generate, /api/election-facts

Core Services

  • JWT authentication with token management
  • Password hashing with bcrypt
  • Scoring algorithm (base + time bonus + accuracy multiplier)
  • Achievement unlock checking
  • Leaderboard calculations

Frontend (Next.js + React)

State Management

  • Zustand store for global game state
  • Real-time score tracking
  • Achievement management
  • User authentication state

Custom Hooks

  • useTimer() - Countdown timer with pause/resume
  • usePoints() - Score calculation and tier system
  • useApi() - Centralized API client with interceptors

UI Components

  • Button (multiple variants: primary, secondary, danger, success)
  • Card (elevated & outlined variants)
  • Tailwind CSS styling system

🚀 How to Run the Project

Option 1: Docker Compose (Recommended - Easiest)

# From project root
docker-compose up -d

# Access:
# Frontend: http://localhost:3000
# Backend API: http://localhost:8000
# API Docs: http://localhost:8000/docs
# Database: localhost:5432

Option 2: Local Development (Manual)

Backend Setup

# Navigate to backend
cd backend

# Create virtual environment
python -m venv venv

# Activate venv
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
cp .env.example .env

# Setup database (when PostgreSQL is running)
# (Migrations coming in Phase 2)

# Run FastAPI server
uvicorn app.main:app --reload --port 8000

Frontend Setup

# Navigate to frontend
cd frontend

# Install dependencies
npm install

# Create .env.local
echo "NEXT_PUBLIC_API_URL=http://localhost:8000" > .env.local

# Run development server
npm run dev

# Open http://localhost:3000

🗄️ Database Setup

The database models are ready but need migration scripts to be created. For development:

Using Docker Postgres

# Start PostgreSQL container (via docker-compose)
docker-compose up db

# Connection string:
# postgresql://votequest_user:password123@localhost:5432/votequest_db

Manual PostgreSQL Setup

# Create database
createdb votequest_db

# Set environment variable
export DATABASE_URL="postgresql://user:password@localhost:5432/votequest_db"

🔑 Environment Variables

Backend (.env)

DATABASE_URL=postgresql://votequest_user:password123@localhost:5432/votequest_db
SECRET_KEY=your-super-secret-key-change-in-production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
CORS_ORIGINS=["http://localhost:3000", "http://localhost:8000"]
ENVIRONMENT=development
DEBUG=true

Frontend (.env.local)

NEXT_PUBLIC_API_URL=http://localhost:8000

📊 API Documentation

Once backend is running, visit: http://localhost:8000/docs

This provides interactive Swagger UI with all endpoints:

  • Try out requests
  • See request/response schemas
  • Test authentication

📦 Installed Dependencies

Backend

  • fastapi - Web framework
  • uvicorn - ASGI server
  • sqlalchemy - ORM
  • psycopg2 - PostgreSQL driver
  • pydantic - Data validation
  • python-jose - JWT tokens
  • passlib - Password hashing
  • alembic - Database migrations
  • pytest - Testing

Frontend

  • next - React framework
  • zustand - State management
  • @tanstack/react-query - Server state
  • axios - HTTP client
  • framer-motion - Animations
  • react-beautiful-dnd - Drag and drop
  • react-toastify - Notifications
  • konva - Canvas drawing
  • tailwindcss - CSS framework

🎮 Next Steps (Phases 2-3)

Phase 2: Core Game Engine

  • Build Level 1 (Voter Registration) game component
  • Implement drag-and-drop mechanics with Konva.js
  • Create game timer and UI components
  • Build results screen
  • Test scoring algorithm

Phase 3: Gamification

  • Implement points calculation on backend
  • Build achievement unlock system
  • Create leaderboard UI
  • Add animations with Framer Motion
  • Setup notification system

Phase 4: UI & Polish

  • Design system tokens
  • Build all navigation pages
  • Mobile responsiveness
  • Dark mode support
  • Accessibility (WCAG)

Phase 5: State Data

  • Populate database with 50 states
  • Create election facts database
  • Setup voter profile generation
  • Test state-specific rules

🧪 Testing Commands

Test Backend

cd backend
pytest tests/
# or specific file
pytest tests/test_scoring.py

Test Frontend

cd frontend
npm run test

📝 Key Files to Know

File Purpose
backend/app/main.py FastAPI application entry point
backend/app/models.py Database schema definitions
backend/app/schemas.py Request/response models
backend/app/scoring.py Scoring algorithm logic
frontend/src/store/gameStore.ts Global game state
frontend/src/hooks/useApi.ts Backend communication
docker-compose.yml Local development orchestration

🐛 Troubleshooting

Port 3000 already in use

# Find process on port 3000
lsof -i :3000
# Kill it
kill -9 <PID>

Port 8000 already in use

# Find process on port 8000
lsof -i :8000
# Kill it
kill -9 <PID>

PostgreSQL connection error

  • Ensure PostgreSQL is running
  • Check DATABASE_URL is correct
  • Verify credentials in .env

npm install fails

# Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install

📞 Support

For issues or questions:

  1. Check API docs: http://localhost:8000/docs
  2. Review error logs in terminal
  3. Check environment variables are set
  4. Ensure all dependencies are installed

✅ Phase 1 Checklist

  • Project structure created
  • Next.js initialized with TypeScript
  • FastAPI backend scaffolded
  • PostgreSQL models defined
  • 20+ API endpoints created
  • Zustand store setup
  • Custom hooks created
  • UI component library started
  • Docker setup
  • Documentation complete

Status: Ready for Phase 2 - Game Engine Development


Project Version: 1.0.0-setup
Last Updated: April 25, 2026