A robust backend API for a hotel booking platform built with Express.js, PostgreSQL, and Drizzle ORM. This API handles hotel management, room bookings, user authentication, and reviews.
- User Authentication - Sign up, login with JWT tokens
- Role-Based Access - Admin and user roles with different permissions
- Hotel Management - Create and view hotels (admin only)
- Room Management - Browse available rooms with filters
- Booking System - Book rooms, view bookings, cancel bookings
- Review System - Leave and view reviews for hotels
- Error Handling - Comprehensive error handling middleware
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: PostgreSQL
- ORM: Drizzle ORM
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcrypt
- Validation: Zod
- Database Tool: Docker Compose
- Node.js (v16 or higher)
- PostgreSQL (or Docker)
- npm or yarn
git clone <your-repo-url>
cd hotel-booking-platformnpm installCreate a .env file in the root directory:
PORT=3000
DATABASE_URL=postgresql://hotel_booking_platform:hotel_book123@localhost:5432/hotel_booking_platform
JWT_SECRET=your_jwt_secret_key_here
NODE_ENV=developmentdocker-compose up -dThis starts:
- PostgreSQL on port 5432
- Adminer (database UI) on port 8080
npm run migrateOr use Drizzle Kit:
npx drizzle-kit migratenpm run devServer will run on http://localhost:3000
npm run devnpm run build
npm startsrc/
├── modules/
│ ├── auth/ # Authentication logic
│ ├── hotel/ # Hotel management
│ ├── rooms/ # Room management
│ ├── bookings/ # Booking system
│ └── review/ # Review system
├── middleware/ # Express middleware
├── db/
│ ├── connection.ts # Database connection
│ └── schema.ts # Database schema
├── types/ # TypeScript types
├── utils/ # Helper utilities
└── index.ts # Server entry point
- users - User accounts with roles (admin/user)
- hotels - Hotel information
- rooms - Room details and availability
- bookings - Guest bookings
- reviews - User reviews and ratings
View the full schema in src/db/schema.ts
| Variable | Description | Example |
|---|---|---|
PORT |
Server port | 3000 |
DATABASE_URL |
PostgreSQL connection string | postgresql://user:pass@localhost/db |
JWT_SECRET |
Secret key for JWT signing | your-secret-key |
NODE_ENV |
Environment mode | development or production |
- Create a feature branch:
git checkout -b feature/your-feature - Commit changes:
git commit -m 'Add feature' - Push to branch:
git push origin feature/your-feature - Open a Pull Request
ISC
For issues or questions, please open an issue on GitHub.