Skip to content

zemekeneng/rankchoice

Repository files navigation

RankChoice.app

A modern, secure web application for creating and managing ranked-choice voting polls with real-time results and comprehensive analytics.

RankChoice.app License Backend Frontend Database

πŸ—³οΈ What is Ranked-Choice Voting?

Ranked-choice voting (RCV) is an electoral system where voters rank candidates in order of preference. Winners are determined through instant runoff rounds:

  • Single-winner: Candidate needs >50% of votes to win
  • Multi-winner: Multiple candidates can win based on vote thresholds

✨ Features

Core Functionality

  • πŸ—³οΈ Create RCV Polls - Single-winner and multi-winner elections
  • πŸ‘₯ Candidate Management - Add, edit, reorder candidates with descriptions
  • πŸ”— Secure Voting Links - Unique ballot tokens for each voter
  • πŸ“Š Real-time Results - Live vote tabulation with round-by-round visualization
  • πŸ“± Mobile-Responsive - Optimized for all devices

Authentication & Security

  • πŸ” JWT Authentication - Secure user registration and login
  • πŸ›‘οΈ Route Protection - Authenticated-only access to sensitive areas
  • πŸ”‘ Password Security - Argon2 hashing for maximum security
  • 🚫 Fraud Prevention - Ballot validation and duplicate vote protection

User Experience

  • 🎨 Modern UI - Beautiful Tailwind CSS design with Svelte 5
  • ⚑ Fast Performance - Optimized Rust backend and reactive frontend
  • πŸ“‹ Form Validation - Real-time validation with helpful error messages
  • πŸ”„ Poll Preview - Preview polls before publishing
  • πŸ“ˆ Dashboard - Comprehensive poll management interface

Developer Experience

  • πŸ§ͺ Comprehensive Testing - 59 backend tests + 17 E2E tests
  • πŸ› οΈ Development Tools - Automated Makefile workflows
  • πŸ“š Complete Documentation - API specs, guides, and examples
  • 🐳 Docker Setup - Containerized development environment

πŸ—οΈ Architecture

Tech Stack

  • Backend: Rust with Axum framework
  • Frontend: SvelteKit with Svelte 5 and TypeScript
  • Database: PostgreSQL with SQLx migrations
  • Styling: Tailwind CSS
  • Testing: Rust tests + Vitest + Playwright E2E
  • Development: Docker Compose for local services

Project Structure

rankchoice/
β”œβ”€β”€ backend/           # Rust API server (Axum)
β”‚   β”œβ”€β”€ src/          # Source code
β”‚   β”œβ”€β”€ migrations/   # Database migrations
β”‚   └── tests/        # Backend tests
β”œβ”€β”€ frontend/         # SvelteKit app (Svelte 5 + TypeScript)
β”‚   β”œβ”€β”€ src/          # Source code
β”‚   └── e2e/          # E2E tests
β”œβ”€β”€ docs/             # Documentation
β”œβ”€β”€ infrastructure/   # Terraform for AWS deployment
└── Makefile         # Development automation

πŸš€ Quick Start

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/your-org/rankchoice.git
    cd rankchoice
  2. Start the development environment

    make dev-bg

    For first-time setup with dependency installation:

    make quick-start
  3. Verify everything is running

    make status
    make health
  4. Access the application

πŸ“– Important: Follow the Development Process for the complete standard workflow. This prevents common issues like 404 errors and service conflicts.

Development Commands

# Start development environment (background)
make dev-bg

# Check service status
make status

# View logs
make logs

# Run all tests
make test

# Run E2E tests
make test-e2e

# Stop all services
make stop

For detailed commands, see docs/MAKEFILE_COMMANDS.md.

πŸ“– Documentation

This project maintains comprehensive documentation organized by purpose and audience:

πŸš€ Getting Started (Developers)

Document Purpose Audience
Quick Start Essential setup and development commands All developers (START HERE)
Development Process Complete standard workflow All developers
Makefile Commands Full command reference All developers

πŸ“‹ Project Information (Product & Planning)

Document Purpose Audience
Development Status Current implementation status and next steps Product managers, developers
Project Planning Complete project specification and architecture Product managers, architects

πŸ”§ Technical Documentation (Implementation)

Document Purpose Audience
API Specification Complete REST API documentation Backend developers, frontend developers
RCV Algorithm Ranked-choice voting implementation details Algorithm developers
Svelte 5 Guide Frontend development patterns and syntax Frontend developers

πŸ§ͺ Testing Documentation (Quality Assurance)

Document Purpose Audience
Backend Testing Guide Backend testing strategy and implementation Backend developers, QA
E2E Testing Guide End-to-end testing comprehensive guide All developers, QA

πŸ”Œ Service Documentation (Microservices)

Document Purpose Audience
Email Service Email microservice setup and API DevOps, backend developers

πŸ§ͺ Testing

Backend Tests (59 tests)

  • Authentication: Registration, login, JWT validation (18 tests)
  • Polls API: CRUD operations, validation (14 tests)
  • Candidates API: Management and ordering (11 tests)
  • RCV Algorithm: Vote tabulation and tie-breaking (5 tests)
  • Voting System: Ballot submission and validation (4 tests)
  • Results API: Real-time results and rounds (5 tests)
  • Integration: End-to-end workflows (2 tests)

Frontend Tests

  • Unit Tests: Component and utility testing with Vitest
  • E2E Tests: 17 comprehensive Playwright tests covering:
    • Authentication flows (6 tests)
    • Poll management (8 tests)
    • Integration journeys (2 tests)
    • Complete user workflows from registration to poll creation

Running Tests

# All tests (backend + frontend + E2E)
make test

# Backend only
make test-backend

# Frontend unit tests only
make test-frontend

# E2E tests only
make test-e2e

# E2E with visual debugging
make test-e2e-headed

πŸ”§ Development

Environment Setup

  1. Ensure prerequisites are installed
  2. Run make check-deps to verify tools
  3. Run make quick-start for full setup
  4. Use make dev-bg for daily development

Database Management

# Run migrations
make db-migrate

# Reset database (clean slate)
make db-reset

Common Workflows

# After pulling changes
make stop && make install && make db-migrate && make dev-bg

# Debugging issues
make status && make health && make logs

# Before committing
make fmt && make lint && make test

Troubleshooting

Problem Solution
404 errors make smart-restart
Port conflicts make kill-ports && make dev-bg
Code not updating make fast-restart
Dependency issues make force-restart

πŸ›‘οΈ The Golden Rule: ALWAYS use make commands. Never start services manually.

🚧 Current Status

βœ… Completed Features

  • Complete backend API with authentication
  • RCV tabulation engine with tie-breaking
  • User registration and login system
  • Poll creation and management interface
  • Dashboard with poll listing
  • Comprehensive test coverage (76 total tests)
  • Development environment automation

πŸ”„ In Progress

  • Voting interface with drag-and-drop ranking
  • Email distribution system
  • Results visualization enhancements

πŸ“‹ Planned

  • Real-time updates with WebSockets
  • Advanced analytics dashboard
  • Social media integration
  • AWS deployment with Terraform

See DEVELOPMENT_STATUS.md for detailed progress.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (make test)
  5. Format code (make fmt)
  6. Commit changes (git commit -m 'Add amazing feature')
  7. Push to branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Guidelines

  • Follow existing code patterns and naming conventions
  • Add tests for new functionality
  • Update documentation for API changes
  • Use the provided Makefile commands for consistency

πŸ“Š Performance

  • API Response Time: < 200ms (p95)
  • Frontend Load Time: < 2 seconds
  • Database Queries: Optimized with proper indexing
  • Test Coverage: 59 backend tests + 17 E2E tests
  • Build Time: ~30-60 seconds incremental

πŸ”’ Security

  • Authentication: JWT tokens with Argon2 password hashing
  • Authorization: Role-based access control (RBAC)
  • Input Validation: Comprehensive request validation
  • SQL Injection: Protection via SQLx prepared statements
  • Rate Limiting: Planned for production deployment
  • HTTPS: Required for production deployment

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support


Made with ❀️ for better democracy through ranked-choice voting

About

An open-source app for rank-choice polling.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published