- User Authentication: Users should be able to register and log in to the system
- Admins should be able to CRUD different users
- Game Submission: Admins should be able to CRUD different games
- Score Submission: Users should be able to CRUD their scores for different games or activities
- Leaderboard Updates: Display a global leaderboard showing the top users across all games
- User Rankings: Users should be able to view their rankings on the leaderboard
- Top Players Report: Generate reports on the top players for a specific period
A real-time leaderboard system built using Node.js, TypeScript, Express, Redis, and Prisma. This project leverages caching for real-time leaderboard updates and efficient management.
- User Authentication: Secure user authentication system.
- Efficient Updates: Caching mechanism to refresh leaderboard upon score submission.
- Automated Maintenance: Cron jobs for periodic updates and cleanup.
- High Performance: Utilizes Redis sorted sets for efficient score management and retrieval.
- Scalable: Designed for high scalability and fast response times.
- Simple API: Easy-to-use RESTful API for interacting with the leaderboard.
- Node.js: Backend runtime.
- TypeScript: Strongly typed programming language for better development experience.
- Express: Minimalist web framework.
- Prisma: ORM for database management.
- Redis: In-memory data store for sorted sets and caching.
- Cron Jobs: For scheduled leaderboard maintenance.
- Node.js
- Redis
- PostgreSQL (or any supported database for Prisma)
-
Clone the repository:
git clone https://github.com/FreyGold/Live-Leaderboard.git cd Live-Leaderboard -
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile in the root directory and configure the following:PORT= DATABASE_URL= JWT_SECRET=
-
Set up the database:
npx prisma migrate dev --name init
-
Start the server:
npm run dev
- POST
/register- Register a new user.
- POST
/login- Authenticate a user and return a JWT.
- GET
/user/:id- Retrieve user details by their ID.
- PATCH
/user/:id- Update user information by ID.
- GET
/score/:id- Retrieve a score by its ID.
- POST
/score- Submit a new score.
- DELETE
/score/:id- Remove a score by ID.
- PATCH
/score/:id- Update a score by ID.
- GET
/scores- Retrieve all scores.
- GET
/game/:id- Retrieve a game by its ID.
- POST
/game- Add a new game.
- DELETE
/game/:id- Remove a game by ID.
- PATCH
/game/:id- Update game information by ID.
- GET
/games- Retrieve all games.
- GET
/leaderboard/top- Fetch the top players on the leaderboard.
- GET
/leaderboard/rank/:playerId- Get the rank of a player by their ID.
- GET
/flush- Flush the cache, the leaderboard will then be generated again by the cron job
- Start in Development Mode:
npm run dev
- Build for Production:
npm run build
- Implement pagination for large leaderboards.
- Introduce roles and permissions for admins.
- Enhance caching and cron job configurations for better performance.
- Persist the leaderboard in the database to reduce computing task of calculating everything from zero on the server with the user base increasing