The Event Management API is a backend system that handles user authentication, event creation, ticket reservation, and waiting list management. It leverages RabbitMQ for managing reservation queues and PostgreSQL as the database. This API is designed using Node.js with Express and Sequelize as ORM for database interaction.
- Features
- Technologies Used
- Setup and Installation
- API Endpoints
- API Documentation
- Environment Variables
- Tests
- User authentication (sign-up, login)
- Create events
- Book tickets for an event
- Manage waiting lists for events
- Cancel reservations and assign tickets to users on the waiting list
- Integration with RabbitMQ for asynchronous ticket reservations
- Node.js: Server-side runtime environment.
- Express.js: Web framework for Node.js.
- Sequelize: ORM for managing PostgreSQL.
- PostgreSQL: Relational database management.
- RabbitMQ: Message broker for asynchronous reservation handling.
- Redis: In-memory data structure store (optional for caching).
- Docker: Containerization platform.
- Docker Compose: For orchestrating multi-container Docker applications.
- Node.js and npm installed
- Docker and Docker Compose installed
- PostgreSQL installed (for local setup)
-
Clone the repository:
Clone the project from your version control system.
-
Create a
.envand.env.compose(for docker compose) files: Copy the.env.exampleand configure your environment variables. -
Build and run the Docker containers:
Use the
docker-compose --env-file .env.compose upBuild and start all containers defined in the Docker Compose file.
-
Docker Compose Services:
- PostgreSQL: Running on port
5432 - RabbitMQ: Running on port
5672(RabbitMQ management interface on port15672) - API: Available on port
3000
Access the app at:
http://localhost:3000 - PostgreSQL: Running on port
-
Stopping the containers:
Use the
docker-compose downcommand to stop and remove containers.
-
Clone the repository:
Clone the project to your local machine.
-
Install dependencies:
Run
npm installto install all required packages. -
Create and configure
.env:Copy the
.env.examplefile and configure the environment variables. -
Start PostgreSQL and RabbitMQ:
Ensure PostgreSQL and RabbitMQ are running locally.
-
Run database migrations:
Use the Sequelize CLI to run the migrations.
-
Start the application:
Use the
npm startcommand to start the server. The application will run onhttp://localhost:3000.
-
POST
/api/user/signup- Request Body:
{ "email": "user@example.com", "password": "password" } - Response:
{ "message": "User created successfully", "data": {...} }
- Request Body:
-
POST
/api/auth/signin- Request Body:
{ "email": "user@example.com", "password": "password" } - Response:
{ "message": "Login successful", "accessToken": "..." }
- Request Body:
-
POST
/api/event/initialize- Request Body:
{ "name": "Event Name", "totalTickets": 50 } - Response:
{ "message": "Event created successfully", "data": {...} }
- Request Body:
-
GET
/api/event/status/:eventId- Response:
{ "message": "Event fetched successfully", "data": {...} }
- Response:
-
POST
/api/reservation/book- Request Body:
{ "eventId": "event-uuid" } - Response:
{ "message": "Reservation queued successfully", "status": "booked" }
- Request Body:
-
POST
/api/reservation/cancel- Request Body:
{ "eventId": "event-uuid" } - Response:
{ "message": "Reservation canceled" }
- Request Body:
-
GET
/api/status/:eventId- Response:
{ "EventId": "...", "availableTickets": 5, "waitingList": 3 }
- Response:
For detailed API documentation and examples, refer to the Postman Documentation.
The application uses the following environment variables. Make sure they are set in your .env file.
DB_USER='your_postgres_user'
DB_HOST='localhost'
DB_NAME='your_database_name'
DB_PASSWORD='your_db_password'
DB_PORT=5432
RABBITMQ_URL='amqp://rabbitmq:rabbitpassword@localhost:5672'
REDIS_URL='redis://localhost:6379'
ACCESS_TOKEN_SECRET='your_secret_key'
REFRESH_TOKEN_SECRET='your_refresh_secret'The application uses Jest for unit and integration tests.
-
Running Tests:
Run
npm testto execute the tests. -
Test Coverage:
Run
npm run test:coverageto get test coverage reports.