A Django application for a simple booking system where users can book available slots for a facility.
The Mini Booking System is a comprehensive facility booking platform built with Django. It enables users to register, browse available facilities, make bookings, and manage their reservations. The application is fully containerized for easy deployment and includes background task processing for email notifications.
The project follows a modular architecture with the following components:
- Django Backend - Handles all business logic, user authentication, and database operations
- PostgreSQL Database - Stores all application data with optimized indexes and constraints
- Redis - Used as a message broker for Celery tasks
- Celery - Processes background tasks like sending notification emails
- Nginx - Serves static files and handles HTTP requests (in production)
booking/
├── booking/ # Main Django project
│ ├── apps/ # Django applications
│ │ ├── accounts/ # User management
│ │ ├── bookings/ # Booking functionality
│ │ ├── core/ # Core functionality
│ │ └── facilities/ # Facility management
│ ├── settings/ # Project settings
│ ├── static/ # Static assets
│ └── templates/ # HTML templates
├── docker/ # Docker configuration
├── staticfiles/ # Collected static files
├── .env # Environment variables
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker build instructions
└── requirements.txt # Python dependencies
- Docker and Docker Compose
- Git
-
Clone the repository:
git clone <repository-url> cd booking
-
Execute the
init_project.sh
script to initialize the Docker deployment:
chmod 777 init_project.sh
./init_project.sh
- Execute the
insert_data.sh
script to load the data:
chmod 777 insert_data.sh
./insert_data.sh
- Access the application at
http://localhost:8000
or http://103.106.189.176/ (Since I have already deployed it on the server at 103.106.189.176 and configured port 80 mapping in Nginx.)
-
Build and start the development containers:
docker-compose up -d --build
-
Access the development server at
http://localhost:8000
-
View logs:
docker-compose logs -f web
Execute Django management commands inside the container:
docker-compose exec web python manage.py <command>
For example:
docker-compose exec web python manage.py createsuperuser
The application includes comprehensive tests for models, forms, and views. Test cases ensure that:
- Data models work correctly
- Forms validate properly
- Views render the expected templates
- Authentication and permissions work as intended
- Business logic rules are enforced
Run all tests:
docker-compose exec web python manage.py test
Run specific app tests:
docker-compose exec web python manage.py test booking.apps.bookings
Or with pytest:
docker-compose exec web pytest
With coverage report:
docker-compose exec web pytest --cov=booking
The database schema is optimized in several ways:
The application uses strategic indexes to improve query performance:
- Booking Model: Indexes on
user
,facility
,status
, and a composite index onstart_time
andend_time
fields - Facility Model: Indexes on
name
,is_active
, andlocation
fields
Database constraints help maintain data integrity:
- Check constraint to ensure
end_time
is always greater thanstart_time
- Foreign key constraints with appropriate cascade behavior
select_related
andprefetch_related
are used to reduce database queries- Celery tasks handle heavy operations asynchronously
- Pagination is implemented for list views
- Custom User model extending Django's AbstractUser, allowing for additional fields like phone number and address
- Standard Django authentication views for login, logout, password reset
- Class-based views for consistent pattern implementation
- Permission-based access control (users can only view/modify their own bookings)
- Validation for booking time conflicts and capacity limits
- Bootstrap 5 for responsive, mobile-friendly design
- Form validation feedback
- Django messages for user notifications
- Clean, intuitive interface
- Background task processing with Celery for email notifications
- Docker containerization for easy scaling
- Health checks for monitoring application status
The Django admin interface is customized for easier management:
- Access the admin interface at
http://localhost:8000/admin
- Default admin credentials (if using the initialization script):
- Username:
admin
- Password:
admin
- Username:
- Users' credentials:
Username | Password | |
---|---|---|
john_smith | [email protected] | password123 |
sarah_johnson | [email protected] | password123 |
michael_brown | [email protected] | password123 |
emily_davis | [email protected] | password123 |
david_wilson | [email protected] | password123 |
GET /health/
- Check application health status
GET /accounts/login/
- User loginGET /accounts/logout/
- User logoutGET /accounts/password_reset/
- Password reset
GET /facilities/
- List all facilitiesGET /facilities/<id>/
- View facility details
GET /bookings/
- List user's bookingsGET /bookings/<id>/
- View booking detailsGET /bookings/create/
- Create a new bookingGET /bookings/<id>/update/
- Update an existing bookingGET /bookings/<id>/delete/
- Delete a booking
Potential areas for enhancement:
- Add WebSocket support for real-time updates
- Implement a REST API for mobile application support
- Add a calendar view for facility availability
- Implement recurring bookings
- Add multi-language support