Skip to content

kbpramod/poll-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🗳️ Votely – Real-Time Polling Platform

A modern, real-time polling and voting application built using Next.js (frontend) and FastAPI (backend) — powered by Redis Pub/Sub and Server-Sent Events (SSE) for instant updates.

This project demonstrates a microservice-oriented architecture that blends frontend reactivity, backend scalability, and real-time communication.


🚀 Overview

Votely allows users to create, vote, and interact with polls in real time.
Whenever a user votes, every connected client automatically receives updated results — no refresh required.

You’ll build the frontend while integrating with backend microservices (PollService, AuthService).


🧱 Architecture

+-------------------+ +-------------------+ | Next.js Frontend| <-----> | API Gateway | | (Votely Client) | | (Simulated Layer)| +-------------------+ +-------------------+ | | | | v v +-------------------+ +-------------------+ | PollService | | AuthService | | FastAPI + Redis | | Spring Boot | | PostgreSQL DB | | JWT Auth / MQ | +-------------------+ +-------------------+

⚙️ Tech Stack Summary

Layer Technology
Frontend Next.js (App Router), TypeScript, Tailwind CSS, shadcn/ui
Backend (PollService) FastAPI, PostgreSQL, Redis (Pub/Sub), asyncio
Auth Service Spring Boot, Redis, RabbitMQ
Real-Time Updates Server-Sent Events (SSE) via Redis Pub/Sub
Deployment (Optional) Docker Compose (Redis + API + Frontend)

🧩 Core Concepts

🔁 Real-Time Communication

Each poll has a unique Redis Pub/Sub channel (e.g., poll_<poll_id>).
When a vote occurs:

  1. FastAPI publishes the updated poll data to Redis.
  2. SSE stream connected to that poll receives the update.
  3. Frontend updates instantly — no reload required.

👥 User Types

  • Registered Users → Authenticated via JWT token from AuthService.
  • Guest Users → Identified by a unique deviceId stored in localStorage or cookies.

🧠 Features

✅ 1. Centralized API Layer

All API interactions (both PollService and AuthService) are routed through a central module in /lib/api.
Handles:

  • Base URL management
  • Token injection (JWT/deviceId)
  • Error handling & response parsing

🏠 2. Homepage (/)

Displays a list of all active public polls with:

  • Poll title
  • Description snippet
  • “View Poll” button

Use shadcn/ui Cards for a clean layout.


📊 3. Single Poll Page (/poll/[pollId])

Displays:

  • Poll title and options
  • Vote buttons (disabled if already voted)
  • Real-time results (progress bar + percentages)
  • Like (❤️) functionality

After voting:

  • The poll locks for the user
  • Results update instantly using SSE

💬 4. Real-Time Updates (SSE)

  • The frontend opens an EventSource stream to /poll/{pollId}/events.
  • When any user votes, the backend publishes via Redis → all clients update.

✍️ 5. Create New Poll (/poll/new)

Form includes:

  • Poll Title / Question
  • 2–5 dynamic option fields
  • Submit button (calls PollService)

⚡ Getting Started

This guide will help you set up and run the Votely project locally, including both the frontend (Next.js) and backend (FastAPI) with Redis for real-time updates.


🧰 Prerequisites

Before you start, make sure you have these installed:


🪜 1. Clone the Repository

git clone https://github.com/kbpramod3/votely.git
cd votely

🧠 2. Setup Backend (FastAPI + Redis)
Option 1: Run with Docker (Recommended)

```bash
git clone https://github.com/kbpramod3/pollservice.git
cd pollservice
docker-compose up -d redis postgres


Then configure .env for your FastAPI backend:
This will start:

Redis (for Pub/Sub real-time communication)

PostgreSQL (for poll data storage)


⚙️ 3. Install and Run Backend
cd backend
pip install -r requirements.txt
uvicorn main:app --reload


Your FastAPI server should now be running at:

http://localhost:8000

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages