Skip to content

leoraclet/django-saas-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Django + Docker Saas Template

license language lastcommit
Language Libraries Size OpenSource

Important

This project is currently under active development. I'm regularly making updates and additions to improve its completeness and functionality.

Table of Contents

🌟 Showcase

Note

Some images coming some day ...

πŸ“– About

This is a fully featured template for building a Django-based SaaS application, containerized with Docker. It includes everything from user authentication and background task processing to a REST API with complete documentation.

The frontend is developed using Vite and Svelte, compiled into static assets and served via Django’s template system.

For development, testing, and production, the stack incorporates tools such as PostgreSQL, Redis, Caddy, MailHog, Sentry, Grafana, and Prometheus.

✨ Features

Project

  • πŸ”„ Reproducibility: The project is built using uv, enabling seamless setup replication across different machines for consistent environments.

  • πŸ“– Well-Documented: Source files include thorough comments and, where applicable, links and explanations to clarify key settings.

Program

  • 🧱 Django-based backend Powerful and extensible backend using Django, ideal for SaaS applications.

  • πŸ” Built-in authentication system User registration, login, password reset, and more out of the box.

  • βš™οΈ Background task support Integrated support for background processing (e.g., with Celery or Django Q).

  • πŸ”Œ REST API with documentation Fully functional REST API with auto-generated documentation (e.g., Swagger or ReDoc).

  • 🎨 Modern frontend with Vite and Svelte Responsive and fast frontend built with Svelte and bundled via Vite, served through Django templates.

  • 🐳 Docker-based development and deployment Consistent environments using Docker for local development, testing, and production.

  • πŸ“Š Monitoring and observability tools Integrated support for Prometheus and Grafana for metrics and monitoring.

  • πŸ“¬ Email testing with MailHog Catch and inspect outgoing emails during development.

  • πŸ“ˆ Error tracking with Sentry Real-time error logging and alerting for faster debugging and maintenance.

  • 🌐 Caddy as a web server and reverse proxy Automatically manages HTTPS and routing for production-ready deployments.

  • 🐘 PostgreSQL database Reliable and robust relational database for handling application data.

  • πŸš€ Redis integration In-memory data store for caching, session management, and background tasks.

πŸ“¦ Structure

Note

The project's structure should speak for itself, but here are the most important parts just in case you're wondering

Directories

  • .github - Contains GitHub Actions CI/CD workflows.
  • .vscode - VS Code-specific settings and helper documentation.
  • ansible - Ansible configuration files (currently empty).
  • assets - Static image resources used in the project.
  • docker - Scripts to run services via Docker (e.g. Django, Celery, Gunicorn).
  • etc - Configuration files for infrastructure components (e.g. Grafana, Traefik, Caddy, Prometheus).
  • frontend - Frontend app using Svelte, Vite, and TypeScript.
  • server - Main Django application, including apps, configuration, static files, templates, and localization.
  • terraform - Infrastructure-as-code configuration with Terraform (currently empty).

Files

  • .dockerignore, .gitignore, .gitattributes - Ignore rules and Git configurations.
  • .editorconfig, .flake8, .pre-commit-config.yaml - Formatting and linting configurations.
  • .env.prod, db.prod.env - Environment variable files for production setup.
  • .python-version - Python version specification (for pyenv and tooling).
  • Dockerfile.test, docker-compose*.yml - Docker configuration files for different environments.
  • Jenkinsfile - CI/CD pipeline configuration for Jenkins.
  • Justfile, Makefile - Task runners for development and automation.
  • Procfile - Process declaration file for deployment (e.g. Heroku).
  • LICENSE, README.md - License and documentation files.
  • pyproject.toml, requirements.txt, uv.lock - Python environment and dependency configuration.

πŸ“š Libraries

Note

Below are some of the key libraries and dependencies used in this project. For the full list, refer to the pyproject.toml file.

  • 🌐 Web Framework & Core

    • django: Full-featured web framework for building modern web apps.
    • django-environ: Environment variable management for 12-factor app configs.
    • whitenoise[brotli]: Efficient static file serving in production.
  • βš™οΈ API & Serialization

  • πŸ” Authentication & Payments

    • django-allauth: Integrated auth with support for social login, MFA, and OIDC.
    • dj-stripe: Connects Django to Stripe for payments and subscriptions.
  • ⚑ Async & Real-time

    • channels: WebSocket and async support for Django.
    • uvicorn: ASGI server for running async Django apps.
  • ⏱️ Task Queue & Scheduling

    • django-celery-beat: Schedule periodic tasks with Celery and Django.
    • redis: In-memory data store used as Celery broker and cache.
  • πŸ“Š Monitoring & Observability

    • sentry-sdk: Real-time error monitoring and performance tracing.
  • πŸͺ΅ Logging & Notifications

    • loguru: Feature-rich logging library with beautiful formatting.
    • apprise: Multi-platform push notification system.

πŸš€ Install & Run

If you'd like to run this Django app on your machine, here are two versions of how to do so by either doing on your system or using docker.

🏠 System

First, make sure the uv Python package manager is installed on your system.

Once that's done, clone the repository

git clone https://github.com/leoraclet/django-saas-template
cd django-saas-template

Then, install the project dependencies:

uv sync

Tip

You may need to create a virtual environment beforehand:

uv venv

Finally, if you have either Make or Just installed, you can launch the development server accordingly.

make migrate  # To migrate the Database (MANDATORY)
make run  # To run the developement server

or you can just run simple commands using

uv run {YOUR_COMMAND}

🐳 Using Docker

Ensure that Docker is installed on your system and that the docker command is available in your terminal.

To start the Docker setup, run:

docker compose up -d

Tip

To rebuild the image from scratch (without using the cache), use the following command:

docker compose build --no-cache

As with local development, you can use the Makefile (or Justfile) to manage Docker-related tasks easily with the following commands:

make up      # Build (if needed) and start the containers
make down    # Stop and remove containers and associated networks
make build   # Build or rebuild the Docker services
make logs    # View the output logs from running containers

❀️ Thanks

Projects and blog posts that inspired this template :

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

🌐 A fully featured template for building a Django-based SaaS application with Docker

Topics

Resources

License

Stars

Watchers

Forks