Online Voting System

A comprehensive online voting platform built with TypeScript, Hono, React, and SQLite.

Features

  • šŸ—³ļø Poll Creation: Create polls with multiple options
  • šŸ‘„ User Authentication: Secure user registration and login
  • šŸ“Š Real-time Results: Live vote counting and visualization
  • šŸ”’ Vote Security: One vote per user per poll
  • šŸ“± Responsive Design: Works on desktop and mobile
  • šŸ‘‘ Admin Dashboard: Manage polls and users

Project Structure

ā”œā”€ā”€ backend/
│   ā”œā”€ā”€ database/
│   │   ā”œā”€ā”€ migrations.ts    # Database schema setup
│   │   └── queries.ts       # Database query functions
│   ā”œā”€ā”€ routes/
│   │   ā”œā”€ā”€ auth.ts         # Authentication routes
│   │   ā”œā”€ā”€ polls.ts        # Poll management routes
│   │   └── votes.ts        # Voting routes
│   └── index.ts            # Main server entry point
ā”œā”€ā”€ frontend/
│   ā”œā”€ā”€ components/
│   │   ā”œā”€ā”€ App.tsx         # Main application component
│   │   ā”œā”€ā”€ Auth.tsx        # Login/Register forms
│   │   ā”œā”€ā”€ PollList.tsx    # Display all polls
│   │   ā”œā”€ā”€ PollDetail.tsx  # Individual poll view
│   │   ā”œā”€ā”€ CreatePoll.tsx  # Poll creation form
│   │   └── Results.tsx     # Vote results visualization
│   ā”œā”€ā”€ index.html          # Main HTML template
│   └── index.tsx           # Frontend entry point
└── shared/
    └── types.ts            # Shared TypeScript interfaces

API Endpoints

Authentication

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login
  • GET /api/auth/me - Get current user

Polls

  • GET /api/polls - List all polls
  • POST /api/polls - Create new poll
  • GET /api/polls/:id - Get specific poll
  • DELETE /api/polls/:id - Delete poll (admin only)

Voting

  • POST /api/votes - Cast a vote
  • GET /api/polls/:id/results - Get poll results

Getting Started

  1. Set up the database by running the migrations
  2. Start the server with the HTTP trigger
  3. Access the application at the provided URL
  4. Register a new account or login
  5. Create polls and start voting!

Security Features

  • Password hashing with bcrypt
  • JWT-based authentication
  • Vote uniqueness enforcement
  • Input validation and sanitization