Skip to content

This repository contains a Real-Time Voting Application that allows users to create topics and vote on them in real-time.

License

Notifications You must be signed in to change notification settings

Hossein-Mirazimi/realtime-voting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Voting App

This is a real-time voting application where users can propose topics and vote on them in real-time. The application utilizes Redis and Socket.IO to ensure all connected clients are instantly updated with the latest voting data.

Features

  • Real-Time Voting: Users can propose topics, vote on them, and see the results update in real-time.
  • Socket.IO Integration: Clients are notified immediately when new topics are added or votes are cast.
  • Redis: Used as the main data store to track votes and topics, with Upstash serving as the Redis hosting platform.
  • Separation of Concerns: The project is structured with two distinct folders:
    • Client: Built using Next.js 14 and ShadCN-UI.
    • Server: A Node.js Express server that manages the backend API and handles socket communication.

Preview

Here are some previews of the Real-Time Voting Application:

Desktop View

Desktop View

Mobile View

Mobile View

Project Structure

root/
├── client/
│   ├── app/
│   ├── components/
│   ├── utils/
│   ├── bun.lockb
│   ├── package.json
│   └── ...
└── server/
    ├── index.ts
    ├── bun.lockb
    ├── package.json
    └── ...
  • client/: This folder contains the frontend part of the application.

    • Built with Next.js 14.
    • Uses ShadCN-UI for consistent and easy-to-use UI components.
    • Connects to the backend through API calls and listens for real-time updates using Socket.IO.
  • server/: This folder contains the backend part of the application.

Technologies Used

Client-Side

  • Next.js 14
  • ShadCN-UI
  • Redis (for client-side state management)

Server-Side

  • Node.js
  • Express.js
  • Socket.IO
  • Redis (for real-time data storage and pub/sub functionality)

Other

  • Upstash Redis: Hosted Redis service that powers real-time updates and state management for both client and server.

Prerequisites

  • Bun: Ensure that you have Bun installed. You can install it by running:

    curl -fsSL https://bun.sh/install | bash
  • Redis Upstash Account: You need an Upstash Redis account. You can # here.

Getting Started

Client Setup

  1. Navigate to the client directory:
cd client
  1. Install the dependencies using Bun:
bun install
  1. Configure the environment variables:
  • Create a .env.local file in the client folder with the following content:
NEXT_PUBLIC_UPSTASH_REDIS_REST_URL=<YOUR_UPSTASH_REDIS_REST_URL>
NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN=<YOUR_UPSTASH_REDIS_REST_TOKEN>
NEXT_PUBLIC_SOCKET_SERVER_URL=<YOUR_SERVER_URL>
  1. Start the development server:
bun dev

The client will be running at http://localhost:3000.

Server Setup

  1. Navigate to the server directory:
cd server
  1. Install the dependencies using Bun:
bun install
  1. Configure the environment variables:
  • Create a .env file in the server folder with the following content:
REDIS_CONNECTION_STRING=<YOUR_UPSTASH_REDIS_CONNECTION_STRING>
SOCKET_PORT=<YOUR_SOCKET_PORT>
  1. Start the server:
bun start

The server will be running on the port specified in your .env file.

Usage

  1. Visit the frontend at http://localhost:3000.
  2. Create a new topic or vote on an existing one.
  3. All clients connected to the application will receive real-time updates as votes are cast or new topics are created.
  4. You can open multiple browser windows to test the real-time functionality. Whenever you vote in one window, the updates will be reflected in all other connected windows in real-time.

Deployment

Client-Side

The frontend can be deployed on any platform that supports Next.js application, such as Vercel, Netlify, or similar services.

Server-Side

The backend can be deployed on platforms like Heroku, Railway, or Vercel.

Make sure to adjust the environment variables to reflect your production URLs and settings when deploying.

Contributing

Contributing are welcome! Feel free to submit a pull request, or open an issue on discuss potential changes or new features.

License

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

Acknowledgments

About

This repository contains a Real-Time Voting Application that allows users to create topics and vote on them in real-time.

Resources

License

Stars

Watchers

Forks