My company is designing a new web application that will be used by multiple clients. Each client will have their own database for security and data protection.
What I’m wondering is how to structure the application code and the database credentials file. I’ll be using a .env outside of the root folder.
I haven’t setup a system like this before with tight restrictions on data so my questions are:
- Should I have multiple code bases each with their own .env file connecting to their own DB?
- Single code base with multiple .env files. One for each client. If this, how should I ensure the right file is used for the right client to ensure the right DB connection is used.
I can use subdomains if that’s the best approach however there is another consideration. Some users may have access to multiple client backends. I would like to offer the ability to switch between clients. For this I was thinking a global database with usernames and passwords, join tables with clients and permissions etc. Then store this data in a session or something and log the user into their selected client backend.
Any guidance is appreciated.
I’ve considered multiple approaches however unsure the best approach.