Project 42 is a multiplayer strategy game inspired by Werewolf (Loups-Garous de Thiercelieux) and Mafia, but set in a unique universe. Players take on different roles, collaborate, and deceive each other to achieve their objectives. The game blends social deduction mechanics with strategic gameplay elements, offering a fresh take on the genre.
It is a RESTful API built using Node.js, TypeScript, Express, and Sequelize.
- Features
- Technologies
- Installation
- Environment Variables
- Database Setup
- Seeding the Database
- Running the Application
- API Endpoints
- Error Handling
- Contributing
- License
- Core Game Features
- Lobby & Room Management
- Real-time Communication
- Authentication & Security
- Game Mechanics
- Frontend Features
- Backend Features
- Multiplayer social deduction game inspired by Werewolf and Mafia.
- Players have different roles and must deceive or collaborate to win.
- A game master or automated logic drives the game phases.
- Players can create rooms with custom settings.
- Room settings include:
- Room name
- Maximum number of players
- Role selection
- Anonymous voting toggle
- Private room with password protection
- Room list:
- Displays waiting and active games.
- Shows the host, number of players, and game status.
- Interactive hover effects to reveal player details and a "Join" button.
- Players can join rooms if they are not full.
- Password-protected rooms prompt users for a password before joining.
- Room state updates in real-time.
- Integrated Socket.io for real-time interactions.
- Chat system allowing players to communicate during the game.
- Messages are saved in a database and broadcasted to connected players.
- Events are handled dynamically to sync players across all devices.
- User authentication using OAuth (Google).
- Role-based access control (e.g., game master privileges).
- Secure password handling (hashed for private rooms).
- Turn-based system where players take actions each round.
- Game phases:
- Discussion phase
- Voting phase
- Night actions
- Players can mark themselves as "ready" before the game starts.
- Game starts only when all non-creator players are ready.
- Backend enforces game logic and validates actions.
- Built using React & TypeScript for a modular structure.
- Material-UI for a clean and responsive UI.
- Dynamic UI updates based on game state.
- Tables for room lists, with hover effects to reveal additional details.
- Password input modal for private rooms instead of inline prompts.
- Sequelize ORM for managing the database.
- Class-based structure for handling room operations (
Game
class). setRoomVar(key, value)
: Updates any room attribute dynamically.sendTchatMessage(sender, message)
: Saves and broadcasts messages in real-time.- Server-side game state management using an event-driven system.
- Node.js: TypeScript runtime environment.
- Express: Web framework for Node.js.
- Sequelize: ORM for database management.
- MySQL: Relational database management system.
- JWT: JSON Web Tokens for secure authentication.
- Node.js (version 14 or higher)
- npm or yarn
- MySQL database
- Clone the repository:
git clone https://github.com/Sorok-Dva/project42-backend
- Navigate to the project directory:
cd project42-backend
- Install the dependencies:
npm install
# or
yarn install
- Set up environment variables:
Create a .env
file in the root directory and add the following:
# APP
NODE_ENV=development
SERVICE_NAME=p42-api
WEBSITE_URL=localhost:3010
DEBUG=p42-api:*
DEBUG_COLORS=true
DEBUG_DEPTH=10
JWT_SECRET=your_jwt_secret
CORS_ORIGIN=http://localhost:3011
PORT=3010
# DB
DB_NAME=project42
DB_USER=root
DB_PASS=root
DB_HOST=localhost
# Mailjet
MJ_APIKEY_PUBLIC=xxxxxxxxxxx
MJ_APIKEY_PRIVATE=xxxxxxxxxxx
# Email options
EMAIL_SENDER_ADDRESS=support@project-42.fr
EMAIL_SENDER_NAME="Lisa du Project 42"
EMAIL_ERRORS_REPORT=errors-reporting@project-42.fr
# Sentry
SENTRY_DSN=xxx
- Create a database and Run the database migrations and seeders:
npx sequelize db:create
npx sequelize db:migrate
npx sequelize db:seed:all
- Start the development server:
npm run dev
# or
yarn dev
The server should now be running on http://localhost:3011
.
To run tests, use the following command:
npm run test
# or
yarn test
project42-backend/
├── @types/ # Type definitions for TypeScript (custom or third-party)
├── assets/ # Static assets such as images, fonts, or other resources
├── config/ # Configuration files for the application (e.g., database, environment)
├── migrations/ # Database migration files (managed by Sequelize or another tool)
├── node_modules/ # Installed dependencies (auto-managed by npm or yarn)
├── seeders/ # Seeder files for populating the database with initial data
├── src/ # Core source code for the backend application
│ ├── connectors/ # Connections to external systems (e.g., APIs, databases)
│ ├── errors/ # Custom error classes and handlers
│ ├── helpers/ # General-purpose helper functions
│ ├── lib/ # Shared libraries or modules
│ ├── middleware/ # Middleware functions for request validation and processing
│ ├── models/ # Sequelize models representing database tables
│ ├── routes/ # API route definitions
│ ├── services/ # Business logic and reusable service classes
│ ├── socket/ # Socket.io event handlers and configuration
│ ├── utils/ # Utility functions (e.g., formatting, logging)
│ ├── sentry.ts # Sentry integration for error tracking
│ ├── sequelize.ts # Sequelize initialization and configuration
│ ├── server.ts # Main entry point for starting the backend server
│ └── sync-db.ts # Script for syncing the database schema
├── test/ # Automated test files
├── .editorconfig # Editor configuration for consistent code style
├── .env # Environment variables for production
├── .env.defaults # Default environment variables for local development
├── .eslintignore # Files and directories to ignore during linting
├── .eslintrc.js # ESLint configuration file
├── .gitignore # Files and directories to ignore in Git repositories
├── .mocharc.js # Configuration for Mocha testing framework
├── .node-version # Specifies the Node.js version to use
├── .sentryclirc # Configuration for Sentry (error tracking)
├── CHANGELOG.md # Changelog of the project
├── generate-changelog.sh# Script to generate the changelog
├── LICENSE # Project license file
├── package.json # NPM configuration and dependency management
├── package-lock.json # Lockfile for NPM dependencies
The API uses standard HTTP status codes to indicate the success or failure of API requests:
200 OK
- The request was successful.201 Created
- The resource was successfully created.400 Bad Request
- The request was invalid or cannot be served.401 Unauthorized
- Authentication failed.404 Not Found
- The requested resource was not found.500 Internal Server Error
- An error occurred on the server.
The API documentation is available at http://localhost:3000/api-docs
once the server is running. It provides detailed information about each endpoint, including request parameters, responses, and examples.
- Fork the repository.
- Create a new branch for your feature:
git checkout -b feature-name
. - Commit your changes:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature-name
. - Open a pull request.
- Developed by Сорок два. All rights reserved.
- Developed with love through
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International - see the LICENSE file for details.
For any inquiries or feedback, please visit our GitHub Repository or contact the developers directly.