{"id":30750509,"url":"https://github.com/michaelscollins/nodejs-multiplayer-api","last_synced_at":"2026-04-11T14:03:32.452Z","repository":{"id":312506076,"uuid":"1047719112","full_name":"MichaelSCollins/NodeJS-Multiplayer-API","owner":"MichaelSCollins","description":"A comprehensive REST API and WebSocket server Template for a multiplayer games, built with TypeScript, Node.js, Express, and MongoDB.","archived":false,"fork":false,"pushed_at":"2025-08-31T04:40:33.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-31T06:23:02.882Z","etag":null,"topics":["auth","express","express-js","expressjs","game","history","iwt","iwthealth","jwt","match","matchhistory","mongodb","node-js","nodejs","stats","typescript","unity","unity3d-plugin","unitycloudsave","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MichaelSCollins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-31T04:15:03.000Z","updated_at":"2025-08-31T04:50:56.000Z","dependencies_parsed_at":"2025-08-31T06:23:07.986Z","dependency_job_id":"af2e49cf-042c-47ce-ac04-d5a93aec57e9","html_url":"https://github.com/MichaelSCollins/NodeJS-Multiplayer-API","commit_stats":null,"previous_names":["michaelscollins/player_authentication-stats_and_matchhistory-api"],"tags_count":null,"template":true,"template_full_name":null,"purl":"pkg:github/MichaelSCollins/NodeJS-Multiplayer-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelSCollins%2FNodeJS-Multiplayer-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelSCollins%2FNodeJS-Multiplayer-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelSCollins%2FNodeJS-Multiplayer-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelSCollins%2FNodeJS-Multiplayer-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MichaelSCollins","download_url":"https://codeload.github.com/MichaelSCollins/NodeJS-Multiplayer-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelSCollins%2FNodeJS-Multiplayer-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273567873,"owners_count":25128655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","express","express-js","expressjs","game","history","iwt","iwthealth","jwt","match","matchhistory","mongodb","node-js","nodejs","stats","typescript","unity","unity3d-plugin","unitycloudsave","websocket"],"created_at":"2025-09-04T07:01:32.670Z","updated_at":"2025-12-30T21:31:01.673Z","avatar_url":"https://github.com/MichaelSCollins.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Game API - TypeScript\n\nA comprehensive REST API and WebSocket server for a multiplayer games, built with TypeScript, Node.js, Express, and MongoDB.\n\n## Features\n\n- **User Authentication \u0026 Management**: JWT-based authentication with user registration, login, and profile management\n- **Player Statistics**: Comprehensive tracking of games played, wins, losses, rankings, and performance metrics\n- **Match History**: Complete record of all games with detailed move history and results\n- **Real-time Game Sessions**: WebSocket support for live game updates, moves, and chat\n- **Game Rules Engine**: Support for different board sizes (9x9, 13x13, 19x19), time controls, and game settings\n- **Leaderboards**: Multiple ranking systems based on wins, win rate, points, and streaks\n\n## Tech Stack\n\n- **Language**: TypeScript\n- **Runtime**: Node.js\n- **Framework**: Express.js\n- **Database**: MongoDB with Mongoose ODM\n- **Authentication**: JWT (JSON Web Tokens)\n- **Real-time**: Socket.IO\n- **Validation**: Express-validator\n- **Security**: bcryptjs for password hashing\n- **Development**: ts-node-dev for hot reloading\n\n## Project Structure\n\n```\nsrc/\n├── models/          # MongoDB schemas and models\n│   ├── Player.ts    # User/player data model\n│   ├── Match.ts     # Completed game records\n│   └── Game.ts      # Active game sessions\n├── routes/          # API route handlers\n│   ├── auth.ts      # Authentication endpoints\n│   ├── players.ts   # Player management\n│   ├── matches.ts   # Match history\n│   └── games.ts     # Active games\n├── middleware/      # Custom middleware\n│   └── auth.ts      # JWT authentication\n├── types/           # TypeScript interfaces\n│   └── index.ts     # All type definitions\n└── server.ts        # Main application entry point\n```\n\n## API Endpoints\n\n### Authentication (`/api/auth`)\n- `POST /register` - User registration\n- `POST /login` - User login\n- `POST /logout` - User logout\n- `GET /me` - Get current user profile\n- `PUT /profile` - Update user profile\n- `POST /change-password` - Change password\n- `POST /refresh` - Refresh JWT token\n\n### Players (`/api/players`)\n- `GET /` - List players with pagination and search\n- `GET /leaderboard` - Get leaderboards by different criteria\n- `GET /:id` - Get player by ID\n- `GET /:id/stats` - Get detailed player statistics\n- `GET /:id/matches` - Get player's match history\n- `PUT /:id/rank` - Update player rank\n- `GET /online/status` - Get online players\n\n### Matches (`/api/matches`)\n- `GET /` - List matches with filtering and pagination\n- `GET /:id` - Get match by ID with full details\n- `GET /:id/moves` - Get match moves history\n- `POST /:id/end` - End a match\n- `GET /statistics/overview` - Get overall match statistics\n- `GET /statistics/player/:playerId` - Get player match statistics\n- `DELETE /:id` - Delete a match\n\n### Games (`/api/games`)\n- `POST /` - Create a new game\n- `GET /` - List available games\n- `GET /:gameId` - Get game by ID\n- `POST /:gameId/join` - Join a game\n- `POST /:gameId/ready` - Set player as ready\n- `POST /:gameId/move` - Make a move\n- `POST /:gameId/pass` - Pass turn\n- `POST /:gameId/chat` - Send chat message\n- `POST /:gameId/resign` - Resign from game\n- `DELETE /:gameId` - Delete/abandon game\n\n## WebSocket Events\n\n### Client to Server\n- `join-game` - Join a game room\n- `leave-game` - Leave a game room\n- `game-move` - Send game move data\n\n### Server to Client\n- `new-game-created` - New game available\n- `player-joined` - Player joined game\n- `player-ready` - Player ready status\n- `game-started` - Game has started\n- `move-made` - Move was made\n- `turn-passed` - Turn was passed\n- `chat-message` - New chat message\n- `game-ended` - Game has ended\n- `game-deleted` - Game was deleted\n\n## Installation\n\n1. **Clone the repository**\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd go-game-api\n   ```\n\n2. **Install dependencies**\n   ```bash\n   npm install\n   ```\n\n3. **Set up environment variables**\n   ```bash\n   cp env.example .env\n   # Edit .env with your configuration\n   ```\n\n4. **Set up MongoDB**\n   - Install MongoDB locally or use MongoDB Atlas\n   - Update the `MONGODB_URI` in your `.env` file\n\n5. **Build the project**\n   ```bash\n   npm run build\n   ```\n\n6. **Start the server**\n   ```bash\n   # Development mode with hot reload\n   npm run dev\n   \n   # Production mode\n   npm start\n   ```\n\n## Environment Variables\n\n```env\n# Server Configuration\nPORT=3000\nNODE_ENV=development\n\n# MongoDB Connection\nMONGODB_URI=mongodb://localhost:27017/go-game-db\n\n# JWT Secret\nJWT_SECRET=your-super-secret-jwt-key-here\n\n# CORS Origins (Unity app domains)\nCORS_ORIGIN=http://localhost:3000,http://localhost:8080\n```\n\n## Development\n\n### Available Scripts\n\n- `npm run dev` - Start development server with hot reload\n- `npm run build` - Build TypeScript to JavaScript\n- `npm start` - Start production server\n- `npm run lint` - Run ESLint\n- `npm run lint:fix` - Fix ESLint issues\n- `npm test` - Run tests\n\n### TypeScript Configuration\n\nThe project uses strict TypeScript configuration with:\n- Strict type checking\n- No implicit any\n- Strict null checks\n- Unused variable detection\n- Source maps for debugging\n\n## Database Models\n\n### Player\n- User authentication and profile information\n- Game statistics and rankings\n- Game preferences and settings\n- Online status tracking\n\n### Match\n- Completed game records\n- Move history and board states\n- Player results and scores\n- Game metadata and timing\n\n### Game\n- Active game sessions\n- Real-time board state\n- Player connections and readiness\n- Chat messages and game rules\n\n## API Response Format\n\nAll API responses follow a consistent format:\n\n```typescript\ninterface ApiResponse\u003cT\u003e {\n  message?: string;\n  data?: T;\n  error?: string;\n  errors?: ValidationError[];\n}\n\ninterface PaginationResponse\u003cT\u003e {\n  data: T[];\n  pagination: {\n    currentPage: number;\n    totalPages: number;\n    totalItems: number;\n    hasNext: boolean;\n    hasPrev: boolean;\n  };\n}\n```\n\n## Authentication\n\nThe API uses JWT tokens for authentication. Include the token in the Authorization header:\n\n```\nAuthorization: Bearer \u003cyour-jwt-token\u003e\n```\n\n## Error Handling\n\nThe API provides comprehensive error handling with appropriate HTTP status codes:\n- `400` - Bad Request (validation errors)\n- `401` - Unauthorized (authentication required)\n- `403` - Forbidden (insufficient permissions)\n- `404` - Not Found (resource doesn't exist)\n- `500` - Internal Server Error\n\n## Security Features\n\n- Password hashing with bcrypt\n- JWT token expiration\n- Input validation and sanitization\n- CORS configuration\n- Rate limiting (can be added)\n\n## Unity Integration\n\nThe API is designed to work seamlessly with Unity:\n- RESTful endpoints for game state management\n- WebSocket support for real-time updates\n- JSON responses optimized for Unity's JSON parsing\n- CORS configured for Unity WebGL builds\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests if applicable\n5. Submit a pull request\n\n## License\n\nMIT License - see LICENSE file for details\n\n## Support\n\nFor questions or support, please open an issue on GitHub or contact the development team.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelscollins%2Fnodejs-multiplayer-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelscollins%2Fnodejs-multiplayer-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelscollins%2Fnodejs-multiplayer-api/lists"}