Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
# Real-time Leaderboard
# Multi-Tenant API Management

A full-stack system that provides real-time leaderboard tracking for users across multiple games or activities. The project demonstrates real-time data management, ranking logic, and scalable architecture using modern web technologies.

## Table of Contents

- [Overview](#overview)
- [Features](#features)

## Overview

The **Real-time Leaderboard** project provides a platform where users can:

- Register and authenticate securely.
- Submit scores for various games or activities.
- View a global leaderboard that updates dynamically.
- Track their own ranking in real time.
- Generate reports of top players for a specific time period.

The system leverages Redis sorted sets for efficient real-time leaderboard management, making it scalable and performant.

## Features

- **User Authentication:** Secure user registration and login with session or JWT-based auth.
- **Score Submission:** API endpoints to submit and update user scores.
- **Leaderboard Storage:** Uses Redis sorted sets for storing and ranking scores.
- **Real-Time Updates:** Automatic leaderboard refresh on score changes.
- **User Rankings:** Query user rank and score efficiently.
- **Top Players Report:** Generate reports for top players within a given date range.
- **Dockerized Environment:** Full stack runs via Docker for consistent setup across environments.
A **multi-tenant API management platform** is a system that allows multiple organizations (tenants) to manage, secure, and monitor their APIs through a shared infrastructure while keeping their data and configurations completely isolated from each other.
84 changes: 53 additions & 31 deletions docs/PRD-realtime-leaderboard.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,68 @@
# PRD: Real-Time Leaderboard

# PRD: Multi-Tenant API Management
## 1. Project Overview

The goal is to build a real-time leaderboard platform where users can register, submit scores for different games or activities, and view leaderboards that update in real time. Redis will power the leaderboard ranking logic for performance and scalability, while PostgreSQL will store persistent user and score history data.
A **multi-tenant API management platform** is a system that allows multiple organizations (tenants) to manage, secure, and monitor their APIs through a shared infrastructure while keeping their data and configurations completely isolated from each other.

Think of it like an apartment building: multiple tenants live in the same building (shared infrastructure), but each has their own private apartment with locked doors (data isolation). Each tenant can customize their space independently without affecting others.

## 2. Key Features

**Core API Management:**

- API Gateway (routing, load balancing)
- Rate limiting and throttling
- Authentication and authorization (API keys, OAuth, JWT)
- Request/response transformation
- Caching mechanisms
- API versioning

**Multi-Tenancy Specific:**

## 2. Core Features
- **Tenant isolation** - Complete data and configuration separation
- **Custom domains** - Each tenant can use their own domain
- **Role-based access control (RBAC)** - Per-tenant user management
- **Quota management** - Different limits per tenant tier
- **Billing integration** - Usage tracking per tenant

### 1. User Authentication
**Security:**

- Users can register and log in using email and password.
- JWT-based authentication (access + refresh tokens).
- Auth endpoints (register, login, logout, refresh).
- Tech: NestJS (Auth module), PostgreSQL (Users table).
- SSL/TLS termination
- IP whitelisting/blacklisting per tenant
- DDoS protection
- Security policy enforcement
- API key rotation

### 2. Score Submission
**Analytics & Monitoring:**

- Users submit scores for specific games or activities.
- Each submission updates Redis leaderboard and persists in PostgreSQL for history.
- API validation (score must be numeric, positive, and higher than previous if applicable).
- Tech: NestJS (Scores module), Redis (Sorted Sets), PostgreSQL (ScoreHistory table).
- Real-time API metrics (per tenant)
- Usage analytics and reports
- Error tracking and logging
- Performance monitoring
- Custom dashboards

### 3. Leaderboard Display
**Developer Portal:**

- Global leaderboard showing top N players across all games.
- Individual game leaderboard view (e.g., “Top 10 in Chess”).
- Paginated or infinite scroll leaderboard (Redis rank queries).
- Tenant-branded developer portals
- API documentation
- Interactive API testing
- SDK generation
- Developer onboarding workflows

### 4. Real-Time Updates
**Administrative:**

- When a user submits a new score, others viewing the leaderboard see live updates.
- Implemented via WebSocket (Socket.IO).
- Tech: Socket.IO integration between NestJS and React.
- Tenant provisioning and management
- Subscription tier management
- White-labeling options
- Backup and disaster recovery
- Audit logs per tenant

### 5. User Rankings
**Integration:**

- Users can view their personal rank and score among all players.
- Endpoint: /leaderboard/:game/my-rank.
- Tech: Redis rank query (ZREVRANK + ZSCORE).
- CI/CD pipeline integration
- Webhook support
- Third-party service connectors
- Custom plugin/middleware support

### 6. Top Players Report

- Generate reports of top players within a date range.
- Admin or system-generated (JSON or CSV).
- Example: “Top players in Game X between Oct 1–7.”
- Tech: Query PostgreSQL (ScoreHistory) for aggregated data.
---
[Multi-Tenant API Management](https://www.notion.so/Multi-Tenant-API-Management-Platform-AC-2a872cc6fd8580f897fefde03649320f)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "Real-time-Leaderboard",
"name": "Multi-Tenant-API-Management",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"license": "MIT",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
Expand Down