How krishbansal10/wordsense works
Purpose and Top-Level Shape
WordSense is a semantic word-guessing game. A React/Vite frontend drives authenticated gameplay against a Node.js backend. The backend uses local GloVe 100-dimensional embeddings and a vocabulary dataset to rank guesses by semantic proximity rather than spelling.
Primary runtime entry points:
• Backend HTTP server: backend/src/server.js
• Frontend bootstrap and app routing: frontend/src/main.jsx, frontend/src/App.jsx
Backend API and Request Boundary
The backend is organized as route → middleware → controller → service/model. Route modules expose authentication, game, and user-facing endpoints:
• backend/src/routes/authRoutes.js
• backend/src/routes/gameRoutes.js
• backend/src/routes/userRoutes.js
Cross-cutting request controls protect gameplay and normalize failures:
• Authentication enforcement: backend/src/middleware/authMiddleware.js
• Guess and hint throttling: backend/src/middleware/guessRateLimiter.js, backend/src/middleware/hintLimiter.js
• Central error handling: backend/src/middleware/errorMiddleware.js
Identity and Player State
Authentication and player-account operations are handled separately from game logic:
• backend/src/controllers/authController.js
• backend/src/controllers/userController.js
• backend/src/models/User.js
The frontend maintains the authenticated session in React context and uses route protection before rendering game/account pages:
• frontend/src/context/AuthContext.jsx
• frontend/src/components/ProtectedRoute.jsx
• frontend/src/services/authService.js
Game Lifecycle and Persistence
Game requests are orchestrated in the game controller/service layer. This is the main control boundary between HTTP concerns, semantic ranking logic, and persisted game state:
• backend/src/controllers/gameController.js
• backend/src/services/gameService.js
• backend/src/models/Game.js
Individual guesses are persisted independently, enabling game history, latest-guess display, rankings, and statistics:
• backend/src/models/Guess.js
• backend/src/controllers/gameController.js
Database connectivity is initialized through:
• backend/src/config/db.js
Semantic Ranking Engine
The core domain mechanism is offline/precomputed semantic ranking. Embeddings are loaded from the bundled GloVe data; similarity logic computes cosine closeness and game logic caches or retrieves target-specific ranks:
• backend/src/services/embeddingService.js
• backend/src/services/similarityService.js
• backend/src/data/embeddings/glove.6B.100d.wordsense.txt
The valid vocabulary/word source is local rather than an external AI inference service:
• backend/src/data/words.json
• backend/src/services/gameService.js
Gameplay flow is: select hidden target → derive/cache vocabulary similarity rankings → validate guess → look up rank → persist guess/update game → return state, hints, and progress.
Frontend Game Experience
The client separates page-level flows from reusable game presentation components:
• Main gameplay page: frontend/src/pages/GamePage.jsx
• Guess submission UI: frontend/src/components/GuessInput.jsx
• Guess and ranking presentation: frontend/src/components/GuessItem.jsx, frontend/src/components/TopWords.jsx
Frontend service modules form the client/API boundary, with API base configuration centralized in:
• frontend/src/config/api.js
• frontend/src/services/gameService.js
• frontend/src/services/userService.js
Additional routed views cover landing, authentication, leaderboard/closest-word discovery, and player stats:
• frontend/src/pages/HomePage.jsx
• frontend/src/pages/ClosestWordsPage.jsx
• frontend/src/pages/StatsPage.jsx
Material Runtimes and Infrastructure
The system runs a Vite-built React frontend and a Node.js backend, each with its own package manifest:
• frontend/package.json
• backend/package.json
Persistence is database-backed through the backend model layer and connection configuration. Semantic intelligence is provided by checked-in pretrained embedding assets, so gameplay ranking does not require a live external ML or embedding API.
Main entry points: gameService.js Game lifecycle service · api.js API client services · main.jsx App bootstrap & routing · db.js Database connection
Components 21
React frontend
- App bootstrap & routing
frontend/src/main.jsx - Auth session context
frontend/src/context/AuthContext.jsx - Protected routes
frontend/src/components/ProtectedRoute.jsx - Gameplay page
frontend/src/pages/GamePage.jsx - Guess & rank UI · Submits guesses and presents ranks and closest words.
frontend/src/components/GuessInput.jsx - Discovery & stats pages · Landing, closest-word discovery, and player statistics.
frontend/src/pages/ClosestWordsPage.jsx - API client services · Auth, game, and user requests use centralized API configuration.
frontend/src/config/api.js
Node backend
- HTTP server
backend/src/server.js - API routes · Authentication, game, and user endpoints.
backend/src/routes/gameRoutes.js - Auth, limits & errors · Enforces authentication, throttles guesses and hints, and normalizes failures.
backend/src/middleware/authMiddleware.js - Auth & user controllers
backend/src/controllers/authController.js - Game controller · HTTP boundary for game lifecycle, guesses, hints, and progress.
backend/src/controllers/gameController.js - Game lifecycle service · Selects targets, validates guesses, and coordinates ranking and state updates.
backend/src/services/gameService.js
Semantic ranking
- Embedding loader
backend/src/services/embeddingService.js - Cosine similarity · Builds or retrieves target-specific vocabulary ranks.
backend/src/services/similarityService.js - GloVe 100d embeddings
backend/src/data/embeddings/glove.6B.100d.wordsense.txt - Valid vocabulary
backend/src/data/words.json
Persistence
- Database connection
backend/src/config/db.js - Player accounts
backend/src/models/User.js - Game state
backend/src/models/Game.js - Guess history · Each guess is stored independently for history, rankings, and statistics.
backend/src/models/Guess.js
Connections 25
- App bootstrap & routing → Auth session context: provides session
- App bootstrap & routing → Protected routes: guards routes
- Protected routes → Gameplay page: renders
- App bootstrap & routing → Discovery & stats pages: routes to
- Gameplay page → Guess & rank UI: composes
- Auth session context → API client services: auth requests
- Guess & rank UI → API client services: game requests
- Discovery & stats pages → API client services: user/game requests
- API client services → HTTP server: HTTP API
- HTTP server → API routes: mounts
- API routes → Auth, limits & errors: applies
- Auth, limits & errors → Auth & user controllers: auth/user endpoints
- Auth, limits & errors → Game controller: protected game endpoints
- Auth & user controllers → Player accounts: accounts
- Game controller → Game lifecycle service: orchestrates
- Game controller → Guess history: persists guesses
- Game lifecycle service → Game state: creates and updates
- Game lifecycle service → Valid vocabulary: selects and validates words
- Game lifecycle service → Cosine similarity: gets target ranks
- Cosine similarity → Embedding loader: uses vectors
- Embedding loader → GloVe 100d embeddings: loads
- Cosine similarity → Valid vocabulary: ranks vocabulary
- Database connection → Player accounts: connects
- Database connection → Game state: connects
- Database connection → Guess history: connects