/django-saas-boilerplate

A Django + django-rest-framework + Heroku + SaaS application boilerplate

Primary LanguagePythonMIT LicenseMIT

pixelpassion.io

🥜 django-saas-boilerplate

A boilerplate to get started with Django, django-rest-framework on Heroku. It is great to start a API-first SaaS-application.

Deploy

Features

Layout

django-rest-boilerplate
├── .circleci                           // CircleCI configuration
|   ├── config.yml  
├── .github  
|   ├── ISSUE_TEMPLATE  
|   |   ├── bug---problem.md            // A Github template for reporting bugs
|   |   └── feature_request.md          // A Github template for posting new features
|   ├── PULL_REQUEST_TEMPLATE.md        // A Github template layout for Pull requests
├── apps  
|   ├── core                            // Django core app
|   ├── users                           // Django Users app
├── conf                                // Django configuration folder
|   ├── urls.py                         // The main url.py file
|   ├── wsgi.py                         // The WSGI handler
|   ├── settings                        // Django settings
|   |   ├── base.py                     // General settings
|   |   ├── local.py                    // Local settings
|   |   ├── production.py               // Production settings
|   |   ├── test.py                     // Test settings
├── devops                              // Devops + Infastructure
|   ├── Docker                          // Docker container
|   |   ├── postgres                    // Postgres Docker
|   |   ├── redis                       // Redis Docker
├── .coveragerc  
├── .env.example                        // Copy to .env for local development  
├── .gitignore                          // Default .gitignore  
├── .pre-commit-config.yaml  
├── .prospector.yaml  
├── LICENSE  
├── Pipfile                             // Pipenv file  
├── Pipfile.lock                        // Pipenv lock file  
├── Procfile                            // Declaration of Heroku processes  
├── README.md  
├── app.json                            // For automated Heroku deployment  
├── conftest.py  
├── docker-compose.yml                  // Docker handling for local development  
├── manage.py  
├── pytest.ini  
├── runtime.txt                         // Python version for Heroku deployment  
├── setup.cfg  
├── tasks.py  

Documentation

Read our documentation at ..

Local setup

Download & install the Docker Community edition

Run the following commands, it will build & start the needed containers (Django, Worker, Postgres DB, Redis, Mailhog):

pipenv install --dev
docker-compose up -d
./manage.py migrate
./manage.py runserver

Open your browser and go to http://localhost:8000/

Deployment

You can deploy project to Heroku using Deploy button or Heroku instructions https://devcenter.heroku.com/categories/working-with-django

Environment variables required to deploy project

Name What is it? Default
DATABASE_URL Database's url postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${DOCKER_POSTGRES_PORT}/postgres for local, Heroku sets it automatically
REDIS_URL Redis's url redis://redis:${DOCKER_REDIS_PORT} for local, Heroku sets it automatically
ENV App's environment
SECRET_KEY Secret key that django requires for security Heroku sets it automatically

All other envs you can find in env.example

Install & Run Locally

This project contains docker integration. You can run it with pipenv run go-docker.

In any case before you need to write your .env file with correct variables: when using the dockerized local development setup, copy .env.local; otherwise copy .env.example to .env, and modifiy accordingly.

Add git hooks

We are using prospectr + pre-commit to make things workable and clear. Before write any code you need to install dev dependencies and run pre-commit install -f after that. Then whenever you run git commit you'll have a fancy output with checks according to our code standards.

Prepare a new branch for your work

Work on new bug/features will be done in a new branch (*) There is a convention in the name of the branches used: 1-short-description-of-purpose

Naming a Branch: - Start branch name with the Issue Number: #1 Initial Issue > 1-initial-branch-name - Use lowercase only - Use dashes to separate words

Make awesome commits

Commits are the smallest portion of code that can be reviewed and has a purpose in the codebase. Each commit counts in a branch, not only the full set of changes.

Please follow this guideline: https://udacity.github.io/git-styleguide/

To use cool github linking to the issue please add #taskNumber in the end. E.g.:

docs: add changes to the Readme #123

Documentation

Please make sure that each public class, method and function has meaningful documentation which describes the purpose of the code. To make things easier to follow we use Python annotations to the public functions and method. Cheat sheet: https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html

More info here: https://docs.python.org/3/library/typing.html