Expert guidance for Trains transportation game: NestJS backend with MongoDB, React frontend with Leaflet maps, abstract service patterns, and multi-tenant architecture.
Expert guidance for the Trains transportation game codebase. This skill helps you work with a multi-tenant NestJS backend, React frontend with interactive maps, and abstract service patterns for rapid API development.
Trains is a transportation game where players send jobs by vehicles between places to earn cash. The architecture uses a multi-tenant model where each game is a separate tenant.
**Technology Stack:**
**Server (NestJS):**
```bash
npm run server-start
npm run start # Runs start:debug (with watch and debug)
npm run start:dev # Development with watch
npm run start:prod # Production mode
```
**Web Frontend (React):**
```bash
npm run web-start
npm run dev # Start dev server with --host
npm run build # Build for production
npm run preview # Preview production build
```
**Server:**
```bash
npm run lint # Run ESLint with auto-fix
npm run format # Format code with Prettier
npm run test # Run Jest tests
npm run test:watch # Run tests in watch mode
npm run test:cov # Run tests with coverage
npm run test:e2e # Run e2e tests
```
**Web:**
```bash
npm run typecheck # Run TypeScript type checking
```
**MongoDB Setup:**
```bash
brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb/brew/mongodb-community
brew services restart mongodb/brew/mongodb-community
mongosh -u admin -p Admin1! --authenticationDatabase admin
trains=db.getSiblingDB('trains');
trains.createUser({
user: 'trains',
pwd: 'trains1!',
roles: [{ role: 'readWrite', db: 'trains' }]
});
```
**Seed Database:**
```bash
npm run seed
```
The server uses abstract base classes for rapid API development. All resources extend these abstractions:
**1. Entity Layer** - `AbstractEntity`
**2. Service Layer** - `AbstractService`
**3. Controller Layer** - `AbstractServiceController`
**4. Mapping Layer** - `AbstractDtoMapper`
Follow the pattern in `server/src/app/api/game.module.ts`:
1. **Define Entity** with TypeORM decorators
2. **Define DTO interface** for data transfer
3. **Create Repository** extending `RepositoryAccessor`
4. **Create Service** extending `AbstractService`
5. **Create Mapper** extending `AbstractDtoMapper`
6. **Create Controller** extending `AbstractServiceController`
7. **Register in Module** with all providers and exports
**Authentication Guards:**
**Key Directories:**
**Routing:**
**Maps:**
**Core Entities:**
- Type PLACE: stored in a place (has `placeId` → PlaceInstance)
- Type VEHICLE: stored in a vehicle (has `vehicleId` → VehicleInstance)
**Multi-tenancy:**
Games can be TEMPLATE or GAME types. Each game instance is a separate tenant.
**Dual MongoDB Support:**
**Common Operations:**
**Server Environment Variables** (`server/.env`):
```
MONGO_USERNAME=trains
MONGO_PASSWORD=trains1!
MONGO_DATABASE=trains
MONGO_HOST=localhost
JWT_SECRET=your-secret-key
JWT_EXPIRATION_TIME=3600
PORT=5001
NODE_ENV=development
```
**Server Settings:**
When implementing new features or debugging, reference these files:
1. **Abstract patterns:**
- `server/src/utils/abstract-service.controller.ts` - Base controller
- `server/src/utils/abstract.service.ts` - Base service
2. **Complete module example:**
- `server/src/app/api/game.module.ts` - Full module structure
3. **Documentation:**
- `docs/README.md` - Comprehensive project docs
- `docs/misc/DesignNotes.md` - Architecture design notes
4. **Database config:**
- `server/src/database/database.module.ts` - MongoDB connection
The project completed a major redesign:
1. **Always extend abstract classes** for new API resources
2. **Use guards** for authentication (`@UseGuards(LoggedIn)`, `@UseGuards(Admin)`)
3. **Follow module structure** from game.module.ts
4. **Prefer TypeORM repositories** for simple operations
5. **Use Mongoose** for complex aggregations
6. **Test both unit and e2e** - mocks available in `server/src/utils/mocks/`
7. **Validate input** - global validation pipe handles DTO validation
8. **Handle errors** - custom exception filter provides consistent error responses
9. **Check docs/** directory for domain terminology and system overview
**Server (Jest):**
**Commands:**
```bash
npm run test # Unit tests
npm run test:watch # Watch mode
npm run test:cov # Coverage report
npm run test:e2e # E2E tests
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/multi-tenant-nestjs-react-game/raw