This is a test project demonstrating NestJS with PostgreSQL, GraphQL, and RabbitMQ integration.
A comprehensive NestJS application featuring REST API, GraphQL API, database integration with TypeORM, and asynchronous task processing with RabbitMQ.
- NestJS Framework with TypeScript
- PostgreSQL database integration with TypeORM
- GraphQL API with Apollo Server
- REST API endpoints
- RabbitMQ Integration for task queue processing
- User Management System with CRUD operations
- Task Queue System with producer/consumer pattern
- Environment Configuration
- Code Quality Tools (ESLint, Prettier)
pnpm installCopy the example environment file and configure your settings:
cp .env.example .envConfigure the following environment variables:
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=test_db
# RabbitMQ Configuration
RABBITMQ_URL=amqp://localhost:5672Make sure you have PostgreSQL running and create a database:
CREATE DATABASE test_db;Install and start RabbitMQ server:
# Docker
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4-managementRabbitMQ Management UI will be available at: http://localhost:15672 (guest/guest)
# development with hot reload
pnpm run start:dev
# development
pnpm run start
# production mode
pnpm run start:prodGET /- Hello World endpointGET /users- Get all usersPOST /users- Create a new userPOST /tasks- Create a new task (publishes to RabbitMQ queue)
- Endpoint:
/graphql - Playground available at:
http://localhost:3000/graphql
Tasks created via POST /tasks are automatically:
- Published to
task_exchangewith routing keytask.create - Consumed from
task_queueby the consumer - Processed by printing task details to console
Use the requests.http file to test all API endpoints including RabbitMQ task examples:
- User management (REST & GraphQL)
- Task creation and queue processing
- Various request patterns
# unit tests
pnpm run test
# watch mode
pnpm run test:watch
# e2e tests
pnpm run test:e2e
# test coverage
pnpm run test:cov# run linter with auto-fix
pnpm run lint
# format code
pnpm run format
# build project
pnpm run build- Framework: NestJS
- Language: TypeScript
- Database: PostgreSQL
- ORM: TypeORM
- GraphQL: Apollo Server
- Message Queue: RabbitMQ (@golevelup/nestjs-rabbitmq)
- Package Manager: pnpm
- Code Quality: ESLint, Prettier
- Testing: Jest, Supertest
src/
├── app.controller.ts # Main application controller
├── app.module.ts # Root application module
├── app.service.ts # Main application service
├── main.ts # Application entry point
├── tasks/ # Task queue module
│ ├── create-task.dto.ts # Task data transfer objects
│ ├── tasks.controller.ts # Task REST endpoints
│ ├── tasks.consumer.ts # RabbitMQ message consumer
│ ├── tasks.module.ts # Task module configuration
│ └── tasks.service.ts # Task producer service
└── users/ # User management module
├── dto/
│ └── create-user.input.ts
├── user.entity.ts
├── users.controller.ts
├── users.module.ts
├── users.resolver.ts
└── users.service.ts
The application implements a Producer/Consumer pattern:
- Client sends
POST /taskswith task data TasksServicecreates task with unique ID and timestamp- Task is published to
task_exchangewith routing keytask.create - Response is returned to client immediately
TasksConsumerlistens totask_queue- When task is received, it processes by logging task details
- Task is automatically acknowledged after successful processing
- Exchange:
task_exchange(topic) - Queue:
task_queue - Routing Key:
task.create
- Follow existing code style and patterns
- Use TypeScript strict mode
- Write tests for new features
- Use meaningful commit messages
- Update documentation when adding new features
- Ensure RabbitMQ is running for full functionality
- Application:
http://localhost:3000 - GraphQL Playground:
http://localhost:3000/graphql - RabbitMQ Management:
http://localhost:15672(guest/guest)
This project is licensed under the UNLICENSED license.