{"id":22298188,"url":"https://github.com/shubhamch95/real-time-polling-system","last_synced_at":"2026-02-14T18:01:00.862Z","repository":{"id":263498960,"uuid":"890594233","full_name":"shubhamch95/Real-Time-Polling-System","owner":"shubhamch95","description":"A scalable system using Node.js, PostgreSQL, Kafka, and WebSocket for creating polls, casting votes, and real-time result updates. It features RESTful APIs, leaderboards, and dynamic vote tracking.","archived":false,"fork":false,"pushed_at":"2024-12-21T13:32:37.000Z","size":5057,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-11T15:55:19.476Z","etag":null,"topics":["client-server","expressjs-framework","javascript","kafka","kafka-consumer","kafkaproducer","nodejs","rest-api","socket-io","websocket","websocket-server"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shubhamch95.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-18T21:01:43.000Z","updated_at":"2025-07-24T11:11:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5a19a56-c415-455a-9cbf-16ce38ff4c34","html_url":"https://github.com/shubhamch95/Real-Time-Polling-System","commit_stats":null,"previous_names":["shubhamch95/real-time-polling-system"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shubhamch95/Real-Time-Polling-System","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamch95%2FReal-Time-Polling-System","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamch95%2FReal-Time-Polling-System/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamch95%2FReal-Time-Polling-System/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamch95%2FReal-Time-Polling-System/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shubhamch95","download_url":"https://codeload.github.com/shubhamch95/Real-Time-Polling-System/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamch95%2FReal-Time-Polling-System/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29451885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-server","expressjs-framework","javascript","kafka","kafka-consumer","kafkaproducer","nodejs","rest-api","socket-io","websocket","websocket-server"],"created_at":"2024-12-03T18:00:03.764Z","updated_at":"2026-02-14T18:01:00.846Z","avatar_url":"https://github.com/shubhamch95.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Real-Time Polling System\n\nA scalable real-time polling system built with **Node.js**, **Express**, **PostgreSQL**, **Kafka**, and **WebSocket**. This system allows users to create polls, cast votes, and get real-time updates on voting results.\n\n## Features\n\n- Authentication with sign-up and sign-in functionality\n- Only authenticated users can create, update, and delete polls\n- Only authenticated users can vote, and each user can vote only once in a poll\n- Real-time vote tracking using WebSocket\n- Event-driven architecture using Kafka\n- RESTful API endpoints\n- Leaderboard system with time-based filtering\n- Comprehensive statistics and analytics\n- Database persistence with PostgreSQL\n- Scalable and maintainable codebase\n\n## Prerequisites\n\n- **Node.js** (v14 or higher)\n- **PostgreSQL** (v12 or higher)\n- **Apache Kafka**\n- **npm** or **yarn**\n\n## Installation\n\n### 1. Clone the repository:\n\n```bash\ngit clone [repository-url]\ncd polling-system\n```\n\n### 2. Install dependencies:\n\n```bash\nnpm install\n```\n\n### 3. Set up environment variables:\n\nCreate a `.env` file in the root directory and add the following configurations:\n\n```bash\nPORT=3000\nDB_HOST=localhost\nDB_PORT=5432\nDB_USER=postgres\nDB_PASSWORD=your_password\nDB_NAME=polling_system\nJWT_SECRET=your_jwt_secret\n```\n\n### 4. Set up PostgreSQL database:\n\n```bash\nCREATE DATABASE polling_system;\n```\n\n### 5. Start the Kafka server and create the required topics:\n\n#### Start Zookeeper\nTo start the Zookeeper server, run the following command:\n\n```bash\nbin/zookeeper-server-start.sh config/zookeeper.properties\n```\n\n#### Start Kafka\nTo start the Kafka, run the following command:\n```bash\nbin/kafka-server-start.sh config/server.properties\n```\n\n#### Create topic\n```bash\nbin/kafka-topics.sh --create --topic poll-votes --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1\n```\n\n## Project Structure\n\n```bash\nsrc/\n├── config/\n│   ├── database.js\n│   └── kafka.js\n├── controllers/\n│   ├── auth.js\n│   ├── pollController.js\n│   ├── voteController.js\n│   └── leaderboardController.js\n├── middleware/\n│   └── authenticate.js\n├── models/\n│   ├── index.js\n│   ├── Poll.js\n│   ├── Option.js\n│   ├── Vote.js\n│   └── User.js\n├── routes/\n│   ├── pollRoutes.js\n│   ├── voteRoutes.js\n│   ├── leaderboardRoutes.js\n│   └── authRoutes.js\n├── services/\n│   ├── pollService.js\n│   ├── voteService.js\n│   ├── kafkaService.js\n│   ├── websocketService.js\n│   └── leaderboardService.js\n└── server.js\n```\n\n## API Endpoints\n\n#### Authentication\n\nPOST /api/v1/auth/signUp\n - Sign up a new user\n\nPOST /api/v1/auth/signIn\n - Sign in an existing user and get a JWT token\n\n\n#### Polls\n\nPOST /api/v1/polls/createPoll \n- Create a new poll (authenticated users only)\n\nGET /api/v1/polls/getPoll/:id \n- Get poll by ID\n\nGET /api/v1/polls/allpolls \n- List all polls\n\nPUT /api/v1/polls/updatePoll/:id\n - Update a poll (authenticated users only)\n\nDELETE /api/v1/polls/deletePoll/:id\n - Delete a poll (authenticated users only)\n\n#### Votes\n\n###### POST /api/v1/vote/:optionId\n\n - Cast a vote for an option\n\n#### Leaderboard\n\nGET  /api/v1/leaderboard/:pollId?\n- Get a leaderboard for a specific poll\n\nGET /api/v1/leaderboard/:pollId/option/:optionId\n- Get the leaderboard for a specific option within a poll\n\n## WebSocket Events\n\n### Client -\u003e Server\n\n```bash\n// Cast a vote\n{\n    type: 'vote',\n    data: {\n        userId: 'string',\n        optionId: 'string'\n    }\n}\n```\n\n### Server -\u003e Client\n\n```bash\n// Vote update\n{\n    type: 'vote_update',\n    data: {\n        optionId: 'string',\n        newVoteCount: number\n    }\n}\n```\n\n## Running the Application\n\n### Start the server:\n\n```bash\nnpm start\n```\n\n### Test WebSocket connection (optional):\n\n```bash\nnode src/testWebSocketClient.js\n```\n\n### Testing\nTo run the test WebSocket client:\n\n```bash\nnode src/testWebSocketClient.js\n```\n\n## Error Handling\n#### The application includes comprehensive error handling:\n\n- Input validation\n\n- Authentication errors (for protected routes)\n\n- Database connection errors\n\n- WebSocket connection errors\n\n- Kafka producer/consumer errors\n\n- Duplicate vote prevention\n\n## Contributing\n\n- Fork the repository\n\n- Create your feature branch (git checkout -b feature/AmazingFeature)\n\n- Commit your changes (git commit -m 'Add some AmazingFeature')\n\n- Push to the branch (git push origin feature/AmazingFeature)\n\n- Open a Pull Request\n\n## License\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamch95%2Freal-time-polling-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshubhamch95%2Freal-time-polling-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamch95%2Freal-time-polling-system/lists"}