The Real-Time Leaderboard project is a backend service designed to manage and display real-time leaderboards for various games. It provides a comprehensive set of features for user authentication, game management, and score tracking. Users can sign up, log in, and submit their scores, which are then used to generate dynamic leaderboards. The service includes robust authentication and authorization mechanisms, ensuring secure access to protected routes. It leverages technologies like TypeScript, NestJS, TypeORM, PostgreSQL, and Redis to deliver high performance and scalability. Additionally.
https://roadmap.sh/projects/realtime-leaderboard-system
-
User authentication and authorization
- JWT-based authentication with access and refresh tokens
- Protected routes with role-based authorization (admin/user)
- Secure password hashing with bcrypt
- Automatic token refresh mechanism
- Session management with Redis
-
User Management
- CRUD operations (create, read, update, delete)
- Profile management
- Friend system with request/accept/reject functionality
- Real-time messaging between users
- Unread message tracking
- Message read status updates
-
Game Management
- CRUD operations for games
- Game rating system
- Game description and metadata
- Admin-only game management operations
-
Score System
- Score submission and validation
- Historical score tracking
- Score timestamps
- Score filtering by date range
- Top players reporting
-
Real-time Features
- WebSocket integration for live updates
- Real-time message delivery
- Real-time leaderboard updates
-
Leaderboard System
- Global leaderboards across all games
- Game-specific leaderboards
- User ranking calculation
- Top players reporting by game
- Date-range based leaderboard filtering
- Redis-powered fast leaderboard queries
-
Data Management
- PostgreSQL database for persistent storage
- Redis caching for performance
- TypeORM for database operations
- Entity relationship management
- Data validation and sanitization
-
API Security
- Rate limiting protection
- Request validation
- Error handling and logging
- Custom exception handling
- Standardized API responses
-
Social Features
- Friend management system
- Private messaging
- Message read receipts
- Friend request system
- Social interactions tracking
- Clone the repository:
git clone https://github.com/AhmedHossam777/real-time-leaderboard
- Navigate to the project directory:
cd real-time-leaderboard
- Setting Up a
.env
File
To configure the environment variables for the project, set up a .env
file with the following parameters:
DB_HOST=your_database_host
DB_PORT=your_database_port
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
DB_DATABASE=your_database_name
JWT_SECRET=your_jwt_secret
ACCESSTOKEN_LIFETIME=access_token_lifetime_in_seconds
REFRESHTOKEN_LIFETIME=refresh_token_lifetime_in_seconds
REFRESH_TOKEN_SECRET=your_refresh_token_secret
REDIS_PASSWORD=your_redis_password
REDIS_HOST=your_redis_host
REDIS_PORT=your_redis_port
Make sure to replace the placeholders with your actual credentials and values for the environment variables.
- Install the dependencies:
npm install
- Start the development server:
npm run start:dev
- The application will be running at
http://localhost:3000
.
- TypeScript
- Node.js
- NestJS
- TypeORM
- PostgreSQL
- Redis
- Passport
- JWT
-
POST /auth/signup
- Description: Sign up a new user.
- Body:
CreateUserDto
-
POST /auth/login
- Description: Log in a user.
- Body:
LoginDto
-
GET /auth/protected
- Description: Access a protected route.
- Headers:
Authorization: Bearer <token>
-
POST /auth/refreshToken
- Description: Refresh the authentication token.
- Body:
{ "refreshToken": "string" }
-
POST /auth/logout
- Description: Log out the current user.
- Headers:
Authorization: Bearer <token>
-
GET /user
- Description: Find a user by email.
- Query:
email
- Headers:
Authorization: Bearer <token>
-
PATCH /user/:id
- Description: Update a user by ID.
- Params:
id
- Body:
UpdateUserDto
- Headers:
Authorization: Bearer <token>
-
DELETE /user/:id
- Description: Delete a user by ID.
- Params:
id
- Headers:
Authorization: Bearer <token>
-
GET /user/me
- Description: Get the current logged-in user.
- Headers:
Authorization: Bearer <token>
-
GET /user/ranking
- Description: Get the ranking of the current user for a specific game.
- Query:
gameName
- Headers:
Authorization: Bearer <token>
-
GET /user/ranking/:gameName
- Description: Get the top players for a specific game.
- Params:
gameName
- Headers:
Authorization: Bearer <token>
-
POST /score
- Description: Submit a score for a game.
- Body:
CreateScoreDto
- Query:
gameName
- Headers:
Authorization: Bearer <token>
-
GET /score
- Description: Get the highest scores for a game.
- Query:
gameName
- Headers:
Authorization: Bearer <token>
-
GET /score/top-players
- Description: Get a report of the top players for a game within a date range.
- Query:
gameId
,startDate
,endDate
,limit
- Headers:
Authorization: Bearer <token>
-
POST /game
- Description: Create a new game.
- Body:
CreateGameDto
-
GET /game/:id
- Description: Find a game by ID.
- Params:
id
-
GET /game
- Description: Find a game by name.
- Query:
name
-
PATCH /game/:id
- Description: Update a game by ID.
- Params:
id
- Body:
UpdateGameDto
-
DELETE /game/:id
- Description: Delete a game by ID.
- Params:
id
-
GET /leaderboard
- Description: Get the highest scores.
- Headers:
Authorization: Bearer <token>
-
GET /leaderboard/game
- Description: Get the leaderboard for a specific game.
- Query:
gameName
- Headers:
Authorization: Bearer <token>
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.