Git Product home page Git Product logo

multi-tenant's Introduction

Multi-tenant architecture software base

This application is powered by django along with django tenant schemas to have multiple tenants via PostgreSQL schemas.

Basically, Tenants are identified via their host name(i.e. tenant.domain.com) but in this project we are identifying the tenant via the api-key header present in request headers. Each tenant can have more than one unique api-key which is stored in the database.

Technologies Used

  • Backend: Python, Django, Postgresql
  • Deploymment tools: Docker, nginx

Project Features:

  1. Create Tenant and Api-Key for that respective tenant.
  2. User Registration with User Login System.
  3. CRUD operation of User Posts.

Project Installation

  1. Extract the code if its in zip format
  2. Setup the virtual environment
  3. Run the command
pip install -r requirements.txt
  1. For the database configuration please refer to the .envs file located under the folder /.envs/.local/ for the respective variables for django and postgres respectively.
  2. Want to run via docker : Use the following command
docker-compose -f local.yml build
docker-compose -f local.yml up -d

Visit localhost:8000 or 0.0.0.0:8000 if you are using docker-compose

Swagger API List Documentation

Creating Tenant and generating api-key for the respective tenant

  1. To create tenant at first open up the shell powered by django
python3 manage.py shell
  1. Import the tenant models app and create tenant object along with Api-Key.
from app.tenants.models import Tenant
from app.api_key.models import ApiKey
tenant = Tenant.objects.create(name="Test Tenant", address="Tenant Address", schema_name="test_tenant")
api_key = ApiKey.objects.create(agency=tenant)
<ApiKey: ebwX8QiJmi6DldUPeIV2WNIzpv8olzyb0ZWcMeq1>
  1. Now pass ebwX8QiJmi6DldUPeIV2WNIzpv8olzyb0ZWcMeq1 as api-key value in request headers. i.e:{'api-key':'ebwX8QiJmi6DldUPeIV2WNIzpv8olzyb0ZWcMeq1'}

Note: If you are using docker then run the following command so that you can get access to the shell

docker-compose -f local.yml run --rm web python manage.py shell

and follow the above mentioned steps to create the tenants and api-key.

Known Bugs:

  1. Make sure to append the trailing slash to the url or else you can encounter errors.
  2. While running the docker compose up you might get following errors:
    1. If you have already run the postgres server on your local machine then the postgres might not be connected to docker which may prompt you to error. To resolve this make sure to change the exposed port or stop the running postgres services on your localhost machine. Error Type: Cannot start service db: driver failed programming external connectivity on endpoint. Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.