Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multi-tenant-schemas:dynamic api routing using django restframework

I am newbie to Multi-Tenant architecture, developing SaaS product using django-tenant-schema

my requirement was something like clients would register for product. For every registered client, I was creating new schema by following single database and isolated schemas approach. Whenever client requested from a browser I was able to identify them by using subdomain and giving privilege to acces their specfic schema. While I was starting coding lot of questions were popup in my head. I am really sorry for asking here but stackoverflow is only my last hope. Database was like below

Database

  • Public_Schema
    • auth_user
    • Clients_List_Table
  • ClientA_Schema
    • auth_user
    • ClientA_User_List
  • ClientB_Schema
    • auth_user
    • ClientB_User_List

Q1.What kind of admin actions we can perform on every client?

I have rest api for example http://client.example.com/api/user_list/ here client maybe ClientA or ClientB

Q2. How can we implement api routing which gets client name dynamically when user requested at browser which let us to use corresponding schema to display current client's user_list.

Any reply can be helpful. Thanks in advance.

like image 315
Ramsk Avatar asked Dec 08 '25 20:12

Ramsk


1 Answers

I followed django-tenants ,and their team implemented almost everything required for django multi-tenant SaaS(Software As a Service) application. So I haven't done much work beyond understanding architecture; I just want to answer this question.

First start with admin and their privileges; for the above requirement, I have two admin roles: tenants_admin, tenant_admin.

Here, tenants_admin (who serve the product) are able to manage tenants(individual company who buy the product); tenants_admin can manipulate data of tenants and they are located at tables in public schema.

Now coming to tenant_admin, who has privilege over data of tenant users (let's say employees in single company).

Now clone the project from django-tenants, create app particularly for tenants. These tenant schemas are strongly isolated from each other, include both the app name and rest_framework to tenant apps. Afterwards implement REST API as usual; these API will be navigated automatically by using middleware we created for project.

like image 56
Ramsk Avatar answered Dec 10 '25 21:12

Ramsk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!