# Better Programming with multi-tenancy

Now when you have multi-tenancy applied in your project, its very important to write clean and modular code for easy understanding and improved readability. Here are some important suggestions to follow that will help you to write better code:

1. Since most of the methods you write will pass through organization and will often be defined in `organization.json`, make sure to define functions specific to particular models inside their own `model.json` and internally call the function with right arguments from `organization.json` file. Example:
   * Define the main function in `product.json` file&#x20;

     ```
     Product.addProductsInBulk = function (id, data) {
       ....
       .... // function algorithm
       ....
       return promise;
     }
     ```
   * And expose a remote method in `organization.json` file, as a wrapper which calls `addProductsInBulk`:

     ```
     Organisation.remoteMethod('addProducts', {
       accepts: [
           {arg: 'id', type: 'string', required: true},
           {arg: 'data', type: 'object', required: true, http: {source: 'body'}}
       ],
       http: {path: '/:id/products/add', verb: 'post'},
       returns: {arg:'products', type: 'object', root: true}
     });
     Organisation.addProducts = function (id, data, cb) {
       app.models.Product.addProductsInBulk(id, data)
       .then(function (response) {
           cb(null, response);
       })
       .catch(function(error){
           cb(error);
       });
     };
     ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shoppinpal.gitbook.io/docs-shoppinpal-com/4.-multi-tenancy-with-loopback/better-programming-with-multi-tenancy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
