This repository serves as a starter template for developing web applications using Django for the backend and React with Vite for the frontend. It includes a Docker setup for easy environment management and deployment.
- Docker and Docker Compose
- Node.js and npm
- Clone the repository:
git clone git@github.com:EnigmaticMachine/django-react-vite-template.git cd django-react-vite-template
-
Build and run Docker containers:
make dev-up
-
Apply Django migrations:
make dev-migrate
-
Create a superuser:
make dev-createsuperuser
- The Django backend will be running at
http://localhost:8000. - The React frontend will be running at
http://localhost:5173. - The Nginx server will be running at
http://localhost:80and will proxy requests to the backend and frontend services.
To set up and run the Uptime Kuma monitoring service:
-
Build and run Docker containers for monitoring:
make monitoring-up
-
Access Uptime Kuma dashboard:
- The Uptime Kuma monitoring dashboard will be running at
http://localhost:3001.
- The Uptime Kuma monitoring dashboard will be running at
The backend service configuration is managed via environment variables specified in the .env, .env.dev, and .env.test files. The docker-compose files will load these variables accordingly:
POSTGRES_DB: Name of the PostgreSQL database.POSTGRES_USER: PostgreSQL username.POSTGRES_PASSWORD: PostgreSQL password.DEBUG: Django debug mode (set to'1'for development).DJANGO_ALLOWED_HOSTS: Allowed hosts for the Django application.DJANGO_SECRET_KEY: Secret key for Django.
- db: Runs the PostgreSQL database.
- backend: Runs the Django application.
- frontend: Runs the React frontend.
- nginx: Runs the Nginx server.
- uptime-kuma: Runs the Uptime Kuma monitoring service.
postgres_data: Stores the PostgreSQL data files.uptime-kuma-data: Stores Uptime Kuma data.
- Environment Variables: Managed using
django-environ.- Sensitive information is stored in environment variables, not in the codebase.
.env,.env.dev, and.env.testfiles for different environments.
- Django Security Middleware: Enabled to ensure secure HTTP headers.
- PostgreSQL: Configured for production readiness.
- Compression: Enabled Gzip and Brotli compression for responses.
- Code Quality: Enforced with
black,pylint, andflake8. - Documentation: Auto-generated using
drf-spectacularwith Swagger integration. - Testing:
- Unit, integration, and end-to-end tests.
- Database cleanup after each test.
- Project Structure:
- Organized settings with separate files for base, test, dev, and prod configurations.
- Makefile:
- Commands for tests, starting the local server, and starting the production server.
- Application Monitoring and Logging:
- Health endpoint added.
- Separate logging settings for production and development.
- Uptime Kuma setup for monitoring.
- Custom
LogHttpRequestMiddlewareto track error response codes.
- CI/CD Pipelines:
- Set up with GitHub Actions for continuous integration and deployment.
- Workflows for running tests and linters.
To run the backend tests:
- Build and run Docker containers for testing:
make test-run
To be defined.
Feel free to fork this repository and submit pull requests. Contributions are welcome!
This project is licensed under the MIT License. See the LICENSE file for details.
This project is inspired by the need to have a unified starting point for building full-stack applications with Django and React.