Note
A full-stack hotel booking web app utilizing Express.js with TypeScript to architect a RESTful API server, facilitating data flow and integration between front-end React application and MongoDB back-end
- Cloning the repository
- Back-end configuration
- Front-end configuration
- Start the application
- Running Docker π³
- Running End-to-End test suite π§ͺ
- Technologies π§©
- Features (What problems can this application solve?) π
- Time taken β³
- Optimizations π
- Contributing
Start by cloning the repository to your local machine:
git clone https://github.com/jayden-n/room-wise.git
cd room-wise-
Environment Files: Navigate to the
backendfolder and create two files:.envand.env.e2e. Add the following contents to both files:MONGODB_CONNECTION_STRING= JWT_SECRET_KEY= FRONTEND_URL= # Cloudinary Variables CLOUDINARY_CLOUD_NAME= CLOUDINARY_API_KEY= CLOUDINARY_API_SECRET= # Stripe STRIPE_API_KEY= -
MongoDB Setup:
- Sign up for an account at MongoDB Atlas.
- Create a new cluster and follow the instructions to set up a new database.
- Once set up, obtain your MongoDB connection string and add it to the
MONGODB_CONNECTION_STRINGvariable in your.envfiles. - For the
.env.e2esetup see "running automated tests" below
-
Cloudinary Setup:
- Create an account at Cloudinary.
- Navigate to your dashboard to find your cloud name, API key, and API secret.
- Add these details to the respective
CLOUDINARY_*variables in your.envfiles.
-
Stripe Setup:
- Sign up for a Stripe account at Stripe.
- Find your API keys in the Stripe dashboard.
- Add your Stripe API key to the
STRIPE_API_KEYvariable in your.envfiles.
-
JWT_SECRET_KEY:
- This just needs to be any long, random string (one ideal option is google "secret key generator").
-
Frontend URL:
- The
FRONTEND_URLshould point to the URL where your frontend application is running (typicallyhttp://localhost:5173if you're running it locally).
- The
-
Environment Files: Navigate to the
frontendfolder and create a file:.env:VITE_API_BASE_URL= VITE_STRIPE_PUB_KEY= -
VITE_API_BASE_URLL:
- The
VITE_API_BASE_URLshould point to the URL where your backend application is running (typicallyhttp://localhost:8000if you're running it locally).
- The
-
Backend:
- Navigate to the
backenddirectory - Install dependencies:
npm install - Start the server:
npm run dev - Start the e2e database by
npm run e2e(Only if you want to run e2e tests)
- Navigate to the
-
Frontend:
- Open a new terminal and navigate to the
frontenddirectory - Install dependencies:
npm install - Start the frontend application:
npm run dev - The application should now be running on
http://localhost:5173but verify this in your command line terminal
- Open a new terminal and navigate to the
Build Docker images and run them as Docker containers
docker-compose -f docker-compose.yaml -p room-wise up -dTo ensure a stable testing environment, create a dedicated MongoDB database for end-to-end tests. Follow these steps:
- Sign up for a MongoDB Atlas account at MongoDB Atlas.
- Create a new project (e.g., "e2e tests").
- Establish a new cluster following the provided instructions.
- Once set up, retrieve the MongoDB connection string and incorporate it into the
MONGODB_CONNECTION_STRINGvariable within your.env.e2efile.
Utilize the provided JSON files in the /e2e-tests/data folder to import test user and hotel data into MongoDB:
- Locate the test user file (e.g.,
test-user.json) in thedatafolder. - Open MongoDB Compass and connect to your database.
- Select the database used for automated tests (created in step 1).
- Import user data:
- Navigate to the
userscollection (create it if necessary). - Click "Add Data" and choose "Import File."
- Select the
test-user.jsonfile, choose JSON as the format, and click "Import." - The test user data will be added to the
userscollection. - Sample user login:
test@test.com/password123
- Navigate to the
- Locate the test hotel file (e.g.,
test-hotel.json) in thedatafolder. - Navigate to the
hotelscollection in your database (create it if necessary). - Repeat the import process, selecting the
test-hotel.jsonfile. - Ensure the file format is set to JSON and click "Import."
- The test hotel data will be added to the
hotelscollection.
Follow these steps to execute end-to-end tests:
- Install the Playwright extension in Visual Studio Code.
- Navigate to the
e2e-testsdirectory. - Install dependencies:
npm install. - Start the frontend and backend servers as outlined above.
- Refer to Using the Playwright extension to run the tests for guidance on executing tests using the Playwright extension.
-
Front-end:
- React for building UI out of components
- TypeScript for ensuring a self-documenting & type-safe codebase
- React Context API for handling app state management
- React-hook-form for efficiently creating and managing forms data in React
- React-router-dom for managing client-side routing strategies
- TanStack Query (F.K.A React Query) for data feching, caching, synchronizing and updating server state
- Framer-motion for integrating interactive animations
- TailwindCSS for responsive web design
-
Back-end:
- Express.js & Node.js for developing RESTful API endpoints, handling HTTP methods (CRUD operations) with layered validations
- MongoDB for Cloud Database (data storage)
- Cloudinary for uploading & storing hotel images
- Multer for hotel images uploading & file validation
- bcrypt.js for secure hashing of user passwords
- JSON Web Token (JWT) for securely authenticating & authorizing user login/register through HTTP Cookies
- Stripe for securely handling online booking transactions
-
E2E Testing:
- Playwright for achieving 99% test coverage through a comprehensive End-to-End test suite, accurately simulating diverse real-world scenarios based on end-user behavior
-
Fully-Functional Web App: Developed using MERN Stack with TypeScript, facilitating seamless hotel room booking -
CRUD Operations: Users can add, update, delete, and book rooms with ease -
RESTful API: Adhering to RESTful principles for designing API endpoints, ensuring interoperability, scalability, and ease of integration with external systems -
Filtering and Sorting Options: Users can filter and sort hotels based on price and hotel types, enhancing their browsing experience and enabling them to find the perfect accommodation easily -
Secure Transactions: Integration with Stripe API ensures secure online booking transactions -
JWT Authentication: Integrating JSON Web Tokens (JWT) for robust user authentication, enhancing security with stateless, token-based authorization -
Data Integrity: Multi-layered validation system within API endpoints ensures the integrity of user data -
Persistent Booking Records: User accounts store booking history for future reference -
Codebase Quality: Achieved 100% test coverage through an extensive End-to-End test suite using Playwright -
Real-world Simulation: Playwright accurately simulates diverse scenarios based on end-user behavior -
Containerization with Docker: Dockerizing application components for streamlined deployment and scalability across diverse computing environments
Note
2 months, and counting...
Future improvements will aim for optimization in:
-
managing all hotel rooms through an ADMIN panel, which performs CRUD operations on hotel rooms for USERS' booking conveniences
-
controlling & limiting the rate of incoming requests from a set of IP addresses in order to protect the Server from potential brute-force attacks
If you're interested in improving Room Wise, here's how you can get involved:
-
Fork the repositoryto your own GitHub account. -
Clone the forked repository to your local machine:
git clone https://github.com/your-username/room-wise.git
-
Create a new branch for your contributions:
git checkout -b feature/your-feature-name
-
Implement your changes and improvements on the new branch.
-
Test your changes thoroughly to ensure they work as expected.
-
Commit your changes with meaningful commit messages:
git commit -m "Add your detailed commit message here"
Once you're satisfied with your changes, push your branch to your forked repository:
git push origin feature/your-feature-name-
Visit your forked repository on GitHub.
-
Create a Pull Request (PR) from your feature branch to the original repository's
developmentbranch. -
Provide a detailed description of your changes in the PR.
-
Your PR will be reviewed, and any necessary feedback will be provided.
Thank you for contributing to Room Wise. Pull requests are welcomed and highly appreciated.
If you have any questions or need assistance, feel free to open an issue and start a discussion.
Happy Coding! π