Natours Django is a robust tour booking application built with Django and Docker. It provides a comprehensive backend for managing tours, bookings, user accounts, and more.
- 🚀 Features
- 🛠️ Tech Stack
- 📋 Prerequisites
- 📁 Project Structure
- 🔧 Setup and Installation
- 🚀 Running the Application
- 🧪 Testing
- 📄 API Documentation
- 📊 Database
- 🔑 Environment Variables
- 🐳 Docker Configuration
- 🚀 Deployment
- 🤝 Contributing
- 📄 License
- 👥 Authors
- 🙏 Acknowledgments
- 📧 Contact
- User authentication and authorization
- Tour management with geospatial features
- Booking system
- Review system
- Appointment scheduling
- Social authentication
- Email notifications (using Brevo)
- API documentation with Swagger
- Backend: Django, Django REST Framework
- Database: PostgreSQL with PostGIS extension, RDS
- Containerization: Docker
- Caching: Redis
- Task Queue: Celery
- Reverse Proxy: Nginx
- Cloud Platform: AWS (ECR & EC2)
- Continous Integration/Continous Deployment(CI/CD): CircleCI
- Authentication: JWT
- Docker and Docker Compose
- Python 3.11+
- PostgreSQL with PostGIS
- GDAL library
- AWS Account with appropriate permissions
- AWS CLI installed and configured
- Domain name (optional, but recommended for production)
natours_django/
├── appointments/ # Tour appointment management
├── bookings/ # Booking logic and models
├── dev-data/ # Development data and loaders
├── reviews/ # Tour review system
├── social_auth/ # Social authentication
├── tours/ # Tour management and geospatial features
├── users/ # User management
├── Natours_Django/ # Main project settings
├── nginx/ # Nginx configuration for production
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker configuration for development
├── Dockerfile.prod # Docker configuration for production
├── requirements.txt # Python dependencies
└── manage.py # Django management script
-
Clone the repository:
git clone https://github.com/your-username/natours-django.git cd natours-django
-
Create environment files:
Create
.env
:SECRET_KEY=your_secret_key DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] SQL_ENGINE=django.contrib.gis.db.backends.postgis SQL_DATABASE=natours_dev SQL_USER=natours_user SQL_PASSWORD=natours_password SQL_HOST=db SQL_PORT=5432 DATABASE=postgres DJANGO_INITIALIZE_DATA=true
Create
.env.db
:POSTGRES_USER=natours_user POSTGRES_PASSWORD=natours_password POSTGRES_DB=natours_dev
-
Build and run with Docker:
docker-compose up --build
-
Initialize the database (first time only):
docker-compose exec web python manage.py migrate docker-compose exec web python dev-data/data/data_loader.py --import docker-compose exec web python dev-data/data/data_loader.py --importDates
-
Set up AWS RDS with PostGIS:
- Create PostgreSQL instance
- Enable PostGIS extension
- Configure security groups
-
Update environment variables for production:
- Set DEBUG=0
- Update DATABASE_URL with RDS credentials
- Configure allowed hosts
-
Deploy using Docker:
- For development:
docker-compose -f docker-compose.dev.yml up --build
- For production:
docker-compose -f docker-compose.prod.yml up --build
-
Access development server:
- Main application: http://localhost:8000
- Admin interface: http://localhost:8000/admin
The application will be available at http://localhost:8000
for development and http://localhost:80
for production.
Run tests using:
docker-compose exec web python manage.py test
API documentation is available using Swagger. After running the application, visit:
http://localhost:8000/swagger/
The project uses PostgreSQL with PostGIS extension for geospatial features. The database configuration can be found in the DATABASES
setting in settings.py
:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': os.environ.get('SQL_DATABASE', 'Natours_Django'),
'USER': os.environ.get('SQL_USER', 'postgres'),
'PASSWORD': os.environ.get('SQL_PASSWORD', ''),
'HOST': os.environ.get('SQL_HOST', 'localhost'),
'PORT': os.environ.get('SQL_PORT', '5432'),
}
}
Key environment variables are stored in the .env
and .env.db
files. Make sure to keep these files secure and never commit them to version control.
The project includes separate Dockerfiles for development and production:
Dockerfile
: Development configurationDockerfile.prod
: Production configuration
Docker Compose files:
docker-compose.dev.yml
: Development setupdocker-compose.prod.yml
: Production setup
For AWS production deployment:
-
Update the
DJANGO_ALLOWED_HOSTS
in your.env
file with your domain. -
Build the Docker images:
docker-compose -f docker-compose.staging.yml build
-
Log in to AWS ECR repository:
aws ecr get-login-password --region <aws-region> | docker login --username AWS --password-stdin <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com
-
Tag and Push images to ECR:
docker tag natours-django_web:latest <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com/natours-django:web docker tag natours-django_nginx:latest <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com/natours-django:nginx docker push <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com/natours-django:web docker push <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com/natours-django:nginx
-
On your EC2 instance, copy required files:
scp -i /path/to/your/key.pem \ -r $(pwd)/{app,nginx,.env.staging,.env.staging.proxy-companion,docker-compose.staging.yml} \ ubuntu@<ec2-instance-ip>:/path/to/project
-
SSH into your EC2 instance:
ssh -i /path/to/your/key.pem ubuntu@<ec2-instance-ip> cd /path/to/project
-
Log in to ECR and pull images:
aws ecr get-login-password --region <aws-region> | docker login --username AWS --password-stdin <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com docker pull <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com/django-ec2:web docker pull <aws-account-id>.dkr.ecr.<aws-region>.amazonaws.com/django-ec2:nginx-proxy
-
Run the containers:
docker-compose -f docker-compose.staging.yml up -d
Note: When first accessing your domain, you may see a certificate security warning. This is expected if using a staging certificate. Click "Advanced" and then "Proceed" to access your application.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License.
- Ericsson Raphael - Initial work
- Natours project inspiration
For questions and support, please email: ericssonraphael@gmail.com