This project is a web application for managing hotel rooms, allowing users to view, add, and list room information.
The Hotel Room Management System is designed to provide an efficient way for hotel staff to manage room inventory. It offers a user-friendly interface for adding new rooms, viewing existing rooms, and managing room details such as floor number and view status. The application is built with Node.js and Express.js, utilizing AWS services like DynamoDB for data storage and App Runner for deployment.
Key features include:
- Add new rooms with details (room number, floor number, view status)
- View a list of all rooms
- Responsive web interface
- Integration with AWS DynamoDB for data persistence
- Deployment automation using AWS App Runner
.
├── app.js # Main application entry point
├── backend.yml # CloudFormation template for infrastructure
├── config.js # Application configuration
├── deploy.sh # Deployment script for AWS App Runner
├── routes
│ ├── add.js # Route handler for adding rooms
│ ├── index.js # Route handler for the home page
│ └── rooms.js # Route handler for listing rooms
├── public # Static assets (CSS, JS)
└── test
├── integration-tests # Integration tests using Cucumber.js
└── unit-tests # Unit tests using Jest
- Node.js (version 14 or higher)
- AWS CLI configured with appropriate credentials
- Docker (for local development and testing)
-
Clone the repository:
git clone <repository-url> cd hotel-room-management
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory and add the following:AWS_REGION=<your-aws-region> DYNAMODB_TABLE=<your-dynamodb-table-name>
-
Start the application:
npm start
-
Access the application at
http://localhost:3000
Run unit tests:
npm run unit-test
Run integration tests:
npm run integration-tests
-
DynamoDB Connection Issues:
- Problem: Unable to connect to DynamoDB
- Error message: "Unable to add room: NetworkingError: connect ECONNREFUSED"
- Diagnostic steps:
- Check AWS credentials in
~/.aws/credentials
- Verify the correct AWS region is set in the config
- Ensure the DynamoDB table exists and is accessible
- Check AWS credentials in
- Resolution: Update AWS credentials or create the DynamoDB table if missing
-
App Runner Deployment Failures:
- Problem: Deployment to App Runner fails
- Error message: "Error: Multiple App Runner services found for environment"
- Diagnostic steps:
- Check the
deploy.sh
script for any environment-specific issues - Verify that only one App Runner service exists for the target environment
- Check the
- Resolution: Remove extra App Runner services or update the deployment script
To enable debug mode:
- Set the
DEBUG
environment variable:export DEBUG=hotel-app:*
- Run the application:
npm start
- Debug output will be visible in the console
Log files are located at:
- Application logs:
/var/log/hotel-app/application.log
- AWS SDK logs:
/var/log/hotel-app/aws-sdk.log
Note: Ensure you have the necessary permissions to access these log files.
The Hotel Room Management System follows a simple request-response flow:
- User interacts with the web interface
- Express.js routes handle incoming requests
- Route handlers interact with DynamoDB for data operations
- Responses are rendered using Pug templates
- Rendered HTML is sent back to the user's browser
[User] <-> [Express Routes] <-> [DynamoDB Client] <-> [AWS DynamoDB]
^ ^
| |
v v
[Web Browser] [Pug Templates]
Note: All data operations are performed asynchronously to ensure optimal performance.
-
Build the Docker image:
docker build -t hotel-app:latest .
-
Push the image to Amazon ECR:
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com docker tag hotel-app:latest <account-id>.dkr.ecr.<region>.amazonaws.com/hotel-app:latest docker push <account-id>.dkr.ecr.<region>.amazonaws.com/hotel-app:latest
-
Deploy to AWS App Runner:
./deploy.sh <branch-name> <account-id>.dkr.ecr.<region>.amazonaws.com/hotel-app:latest
The application's infrastructure is defined in the backend.yml
CloudFormation template. Key resources include:
-
DynamoDB:
- RoomsTable: Stores room information with attributes for id, floor, and hasView
-
IAM:
- AppRunnerInstanceRole: Allows App Runner to access DynamoDB and CloudWatch Logs
- AppRunnerECRAccessRole: Grants App Runner access to ECR for image pulling
-
CloudWatch:
- DynamoDBReadCapacityAlarm: Monitors DynamoDB read capacity utilization