A real-time multiplayer word guessing game platform built with Node.js, Express, Socket.io, and MongoDB. Players compete in interactive game rooms, challenge friends, track statistics, and engage in live chat during gameplay.
- Features
- Project Structure
- Technology Stack
- Installation
- Configuration
- Running the Application
- Database Setup
- API Endpoints
- Socket Events
- Key Models
- Scripts
- Security Features
- Development
- Contributing
- License
- User registration and authentication with password hashing (bcryptjs)
- JWT-based session management
- User profiles with avatars
- Real-time user status tracking (online/offline/in match)
- Last seen timestamp
- Real-time multiplayer word guessing matches
- Multiple game rooms/lobbies
- Competitive scoring system
- Player readiness tracking
- Live game state synchronization
- Friend system with add/remove functionality
- Game invitations to friends
- Real-time notifications
- Live chat during gameplay
- Friend activity tracking
- Comprehensive player statistics:
- Total games played
- Games won/lost/drawn
- Win streaks and best streaks
- Total words guessed
- Average guess time
- Total score
- Match history with detailed game records
- Performance metrics and analytics
- WebSocket-based real-time updates via Socket.io
- Live game events
- Instant notifications
- Chat messaging
- User status updates
Guess_The_Word_Game/
├── controllers/ # Business logic handlers
│ ├── authController.js
│ ├── friendController.js
│ ├── gameController.js
│ ├── notificationController.js
│ └── roomController.js
├── routes/ # API and page route definitions
│ ├── auth.js
│ ├── dashboard.js
│ ├── friendsApi.js
│ ├── friendsPage.js
│ ├── gameLobbyPage.js
│ ├── gameplayRoute.js
│ ├── matchHistoryApi.js
│ ├── matchHistoryPage.js
│ ├── notificationsApi.js
│ ├── notificationsPage.js
│ ├── roomApi.js
│ └── roomPage.js
├── models/ # MongoDB schemas
│ ├── User.js
│ ├── Games.js
│ ├── Room.js
│ ├── Friendship.js
│ ├── GameInvitation.js
│ ├── Notification.js
│ ├── ChatMessage.js
│ └── WordBank.js
├── socket/ # WebSocket server and handlers
│ ├── socketServer.js
│ ├── socketAuth.js
│ └── handlers/
│ ├── gameHandler.js
│ ├── chatHandler.js
│ ├── notificationHandler.js
│ ├── roomHandler.js
│ └── userStatusHandler.js
├── middleware/ # Express middleware
│ ├── authMiddleware.js
│ ├── errorMiddleware.js
│ ├── routeGuards.js
│ └── validation.js
├── utils/ # Utility functions
│ ├── logger.js # Winston-based logging
│ └── wordManager.js
├── public/ # Client-side assets
│ ├── js/ # JavaScript files
│ ├── style/ # CSS stylesheets
│ └── images/ # Images
├── views/ # EJS templates
│ ├── layouts/ # Layout templates
│ ├── auth/ # Authentication pages
│ └── *.ejs # Page templates
├── scripts/ # Database seeding scripts
│ ├── createTestGames.js
│ ├── createTestFriends.js
│ └── createTestNotifications.js
├── logs/ # Application logs
├── server.js # Main server file
├── docker-compose.yml # Docker configuration
├── package.json # Project dependencies
└── friends-api.http # HTTP request examples
- Backend Framework: Express.js (v5.1.0)
- Real-time Communication: Socket.io (v4.8.1)
- Database: MongoDB (v8.16.1) with Mongoose ODM
- Authentication: JWT & bcryptjs
- Template Engine: EJS with Express Layouts
- Security: Helmet.js, CORS, Rate Limiting, Express Validator
- Session Management: Express Session with MongoDB store
- Logging: Winston
- Frontend: Vanilla JavaScript, CSS3
- DevOps: Docker & Docker Compose
{
"express": "^5.1.0",
"socket.io": "^4.8.1",
"mongoose": "^8.16.1",
"jsonwebtoken": "^9.0.2",
"bcryptjs": "^3.0.2",
"helmet": "^8.1.0",
"express-validator": "^7.2.1",
"winston": "^3.17.0",
"chart.js": "^4.5.0"
}- Node.js (v16 or higher)
- npm or yarn
- MongoDB (v5.0 or higher)
- Docker & Docker Compose (optional, for containerized setup)
git clone https://github.com/LoayTarek5/Guess_The_Word_Game.git
cd Guess_The_Word_Gamenpm installCreate a .env file in the root directory:
# Server Configuration
PORT=3000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://admin:admin@mongodb:27017/guess_the_word_game?authSource=admin
# JWT
JWT_SECRET=your_jwt_secret_key_here
JWT_EXPIRE=30d
# Session
SESSION_SECRET=your_session_secret_here
# Client Configuration
CLIENT_URL=http://localhost:3000
# Email (if applicable)
SMTP_HOST=your_smtp_host
SMTP_PORT=587
SMTP_USER=your_email
SMTP_PASS=your_password
# Game Configuration
WORDS_PER_GAME=5
GAME_DURATION=300
MAX_PLAYERS_PER_ROOM=100npm run devnpm startdocker-compose upThe application will be available at http://localhost:3000
docker-compose upThis starts:
- MongoDB on port 27017
- Mongo Express (admin UI) on port 8081
Access Mongo Express at http://localhost:8081
# Start MongoDB locally
mongod
# Connect to MongoDB
mongoThe application automatically connects to MongoDB on startup. Use the seeding scripts to populate test data:
# Seed test games
npm run seedGames
# Seed test friends
npm run seedFriends
# Seed test notifications
npm run seedNotificationsPOST /register- Register a new userPOST /login- Login userPOST /logout- Logout userGET /me- Get current user profile
GET /- Get user's friends listPOST /add/:userId- Send friend requestDELETE /remove/:userId- Remove friendGET /requests- Get pending friend requestsPOST /requests/:userId/accept- Accept friend request
GET /- Get game historyGET /:gameId- Get specific game detailsPOST /create- Create new gamePOST /:gameId/join- Join a gamePOST /:gameId/guess- Submit guess during gameplay
GET /- List available game roomsPOST /create- Create new roomGET /:roomId- Get room detailsPOST /:roomId/join- Join roomPOST /:roomId/leave- Leave room
GET /- Get user's match historyGET /:matchId- Get detailed match information
GET /- Get user notificationsPOST /:notificationId/read- Mark notification as readDELETE /:notificationId- Delete notification
connect- User connects to WebSocketdisconnect- User disconnectsuser:status- Broadcast user status change
game:start- Game session startsgame:guess-submitted- Player submits a guessgame:update-state- Update game state to all playersgame:end- Game concludesgame:player-ready- Player marks as ready
chat:send-message- Send message in game chatchat:receive-message- Receive messages from other playerschat:typing- User typing indicator
room:create- Create new roomroom:join- Player joins roomroom:leave- Player leaves roomroom:update- Room state update
notification:send- Send notificationnotification:receive- Receive notificationnotification:update- Update notification status
user:online- User comes onlineuser:offline- User goes offlineuser:in-match- User starts playing
{
username: String (unique),
email: String (unique),
password: String (hashed),
avatar: String,
currentRoomId: String,
status: enum ["online", "offline", "in match"],
lastSeen: Date,
stats: {
totalGames: Number,
gamesWon: Number,
gamesLost: Number,
gamesDraw: Number,
winStreak: Number,
bestStreak: Number,
totalWordsGuessed: Number,
averageGuessTime: Number,
totalScore: Number
}
}{
gameId: String (unique),
roomId: String,
players: [{ user: ObjectId, score: Number, attempts: Number, ... }],
status: String,
startedAt: Date,
endedAt: Date,
winner: ObjectId
}{
roomId: String (unique),
name: String,
creator: ObjectId,
players: [ObjectId],
capacity: Number,
status: String,
createdAt: Date
}{
requester: ObjectId,
receiver: ObjectId,
status: enum ["pending", "accepted", "blocked"],
createdAt: Date
}Located in /scripts/ directory:
- createTestGames.js - Creates sample game records for testing
- createTestFriends.js - Sets up test friendships between users
- createTestNotifications.js - Generates test notifications
Run any script with:
npm run seed[ScriptName]- Helmet.js - Sets security HTTP headers
- CORS - Cross-Origin Resource Sharing protection
- Rate Limiting - Prevents brute force attacks
- Input Validation - Express Validator middleware
- Password Hashing - bcryptjs with salt rounds
- JWT Authentication - Secure token-based auth
- Content Security Policy - Restricts resource loading
- Session Security - Secure session management with MongoDB store
- XSS Protection - Built-in protection through templating
npm run devnpm run lintnpm run buildnpm run testThe friends-api.http file contains example HTTP requests for testing API endpoints. Use tools like:
- REST Client extension for VS Code
- Postman
- Thunder Client
- cURL
- Fork the repository
- Create a feature branch:
git checkout -b feature/AmazingFeature - Commit changes:
git commit -m 'Add AmazingFeature' - Push to branch:
git push origin feature/AmazingFeature - Open a Pull Request
This project is licensed under the ISC License - see LICENSE file for details.
- Repository: GitHub - Guess_The_Word_Game
- Issues: Report Issues
For issues, questions, or suggestions, please:
- Check existing GitHub issues
- Open a new issue with detailed description
- Include steps to reproduce bugs
- Provide environment details (Node version, OS, etc.)
Last Updated: 2026-03-09
Version: 1.0.0
Author: LoayTarek5