Akki-jaiswal / Akki-jaiswal/pong-game

add optional Node.js + Express + MongoDB backend (leaderboard, saved preferences, future multip

Offen
#208 0 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @parv-byte Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
22
Forks
116
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I’d like to propose an optional backend for the Pong Game to enable persistent features and future expansions while keeping the current front‑end fully functional offline. The backend would provide: 1) a public leaderboard per difficulty, 2) saved player preferences (name, theme, preferred difficulty), and 3) a foundation for future multiplayer via WebSockets.

Motivation

Persistence: Current scores and preferences reset on refresh; a backend would store them across sessions.

Community features: A global leaderboard encourages engagement and friendly competition.

Extensibility: A small, well-structured API prepares the project for future features like matchmaking or co-op/versus modes.

Learning value: Great opportunity for contributors to practice full‑stack patterns (routing, validation, storage, deployment).

Proposed Scope (Phase 1 – minimal viable backend)

Stack: Node.js + Express (REST), MongoDB (MongoDB Atlas free tier or docker), with lightweight validation and rate limiting.

Endpoints:

POST /api/scores body: { name, score, difficulty } → stores a score

GET /api/leaderboard?difficulty=medium&limit=10 → returns top scores

POST /api/users body: { name, preferences } → create/update user

GET /api/users/:id → returns user and preferences

Data models:

users: { _id, name, preferences: { theme, difficulty }, createdAt }

scores: { _id, userId (nullable for guests), score, difficulty, createdAt, clientHash }

Front‑end integration:

On Game Over: POST score if online; fail gracefully if offline.

On load: fetch leaderboard and apply saved preferences when available.

Keep all current gameplay working without the backend (progressive enhancement).

Security and Integrity (basic, Phase 1)

Input validation (Joi/Zod).

Simple anti‑tamper heuristics (timestamp + nonce + server HMAC; basic rate limiting).

Score sanity checks (bounds and minimum round duration).

Roadmap (incremental)

Phase 1: Leaderboard + preferences, CI config, .env handling, docs.

Phase 2: Lightweight auth (guest IDs → JWT/OAuth), personal history.

Phase 3: Realtime multiplayer with Socket.IO or native WebSockets (rooms, matchmaking).

Phase 4: Moderation tools, improved anti‑cheat, analytics dashboards.

Backward Compatibility

The game remains fully playable without the backend. API calls are optional and degrade gracefully when the server is unavailable.

Contributor Offer

I can open a PR for Phase 1 with:

Express app skeleton, Mongo models, routes, tests

OpenAPI/Swagger spec for the endpoints

Docker compose or setup docs for local dev

Front‑end integration (POST on game over, GET leaderboard on load)

Basic CORS config for local development

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.