For any question contact us through our telegram channel: https://t.me/+uCENCnbnruxiMjA0
A robust NestJS backend API for the LogiQuest puzzle game platform. Built with TypeScript, featuring modular architecture, comprehensive security, and developer-friendly tooling.
- Modular Architecture: Organized into separate modules for users, puzzles, achievements, and game logic
- Type Safety: Full TypeScript support with strict mode enabled
- Security: Helmet, CORS, and rate limiting configured
- Validation: Request validation using class-validator
- Logging: Structured logging with Winston
- Documentation: Auto-generated API docs with Swagger
- Code Quality: ESLint, Prettier, and pre-commit hooks
- Environment Management: Validated environment variables
- Node.js 18+
- npm or yarn
- Git
-
Clone the repository
git clone <repository-url> cd quest_api
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Set up git hooks
npm run prepare
src/
βββ config/ # Configuration files
β βββ configuration.ts # Environment configuration
β βββ env.validation.ts # Environment validation schema
βββ modules/ # Feature modules
β βββ users/ # User management
β βββ puzzles/ # Puzzle management
β βββ achievements/ # Achievement system
β βββ game/ # Game logic
βββ common/ # Shared utilities
β βββ guards/ # Authentication guards
β βββ interceptors/ # Request/response interceptors
β βββ decorators/ # Custom decorators
β βββ filters/ # Exception filters
βββ app.module.ts # Root application module
βββ main.ts # Application entry point
npm run start:dev # Start in development mode with hot reload
npm run start:debug # Start in debug mode
npm run build # Build the application
npm run start:prod # Start in production modenpm run lint # Run ESLint with auto-fix
npm run lint:check # Run ESLint without auto-fix
npm run format # Format code with Prettier
npm run typecheck # Run TypeScript type checkingnpm run test # Run unit tests
npm run test:watch # Run tests in watch mode
npm run test:cov # Run tests with coverage
npm run test:e2e # Run end-to-end testsCopy .env.example to .env and configure the following variables:
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
DATABASE_HOST |
Database host | localhost |
DATABASE_PORT |
Database port | 5432 |
DATABASE_USERNAME |
Database username | postgres |
DATABASE_PASSWORD |
Database password | password |
DATABASE_NAME |
Database name | logiquest |
JWT_SECRET |
JWT secret key | your-secret-key |
JWT_EXPIRES_IN |
JWT expiration time | 24h |
REDIS_HOST |
Redis host | localhost |
REDIS_PORT |
Redis port | 6379 |
CORS_ORIGIN |
CORS allowed origin | http://localhost:3000 |
RATE_LIMIT_TTL |
Rate limit time window (seconds) | 60 |
RATE_LIMIT_MAX |
Max requests per time window | 10 |
Once the server is running, you can access the Swagger documentation at:
http://localhost:3000/api/docs
- Helmet: Security headers middleware
- CORS: Cross-origin resource sharing configuration
- Rate Limiting: Request rate limiting with Redis
- Input Validation: Request validation with class-validator
- Environment Validation: Startup-time environment validation
- Users Module: User registration, authentication, and profile management
- Puzzles Module: Puzzle creation, management, and retrieval
- Achievements Module: Achievement system and progress tracking
- Game Module: Game logic, scoring, and session management
- Guards: Authentication and authorization
- Interceptors: Logging, transformation, and caching
- Decorators: Custom parameter and method decorators
- Filters: Global exception handling
The project includes comprehensive testing setup:
- Unit Tests: Jest-based unit testing for services and controllers
- E2E Tests: End-to-end testing for API endpoints
- Coverage: Code coverage reporting
- Use TypeScript strict mode
- Follow ESLint and Prettier configurations
- Write meaningful commit messages
- Add JSDoc comments for public APIs
- Pre-commit hooks run linting and formatting
- Use conventional commit messages
- Create feature branches for new development
Each module should follow this structure:
module-name/
βββ dto/ # Data transfer objects
βββ entities/ # Database entities
βββ module-name.controller.ts
βββ module-name.service.ts
βββ module-name.module.ts
βββ tests/ # Module-specific tests
npm run build
npm run start:prod- Set
NODE_ENV=production - Configure production database
- Set secure JWT secret
- Configure production CORS origins
- Set up proper logging levels
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the UNLICENSED License.
For support and questions, please open an issue in the repository.
Built with β€οΈ using NestJS