Giter Site home page Giter Site logo

multi-tenancy's Introduction

About This Repository

This is a boilerplate for a BE with multitenancy on row level. Using nestjs as main framework and sequelize as orm

Folders structure

  • config, migrations and seeders are used by sequelize-cli to setup the DB
  • src
    • lib common providers shared accross all tenants
    • models sequelize models
    • shippings module where I want to implement the multi-tenancy

Multi tenancy implementation

To keep it simple there are only essential elements to understand the requirements:

Database models

  • Tenant (list of tenants)
  • TenantsConfig (every tenant should have its own configs)
  • User (list of users)

multi-tananted:

  • Shippings (this table has also a tenantId field for the row level tenancy)

Controllers for shipping

There should be only controller for creating shippings.

POST /shippings should read the x-tenant header and through shippingService load the proper fedexService with the tenant config.

This boilerplate is for example only, you can change it as you think is better.

Shipping module

Inside the shippings.service.ts there is a rough implementation of what i'm trying to achieve

TODO

Im looking for a BE structure that can handle multiple tenants (10-20 tenants)

  1. the BE should be aware of TenantConfig changes, to always use the latest config data (without app reload)

    this can be done moving tenantConfigs store to a class (then invocking the class from the tenant.intercepto, and when updating the db, changing also the tenantConfig store)

  2. ideally providers would be instantiated once for tenant( and then cached somehow, until config changed)
  3. there should be some centralized middleware/interceptor to manage/return tenants configs
  4. there should be some centalized middleware/interceptor to check if user belongs to the declared tenant

    this can be achieved by adding a guard that has loaded all users and tenant, and checks if user belongs to declared tenant

multi-tenancy's People

Contributors

roman991 avatar ostheperson avatar

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.