This is the companion code for the blog post Build a multi-tenant SaaS application: A complete guide from design to implementation.
This demo application showcases how to build a SaaS application with multi-tenant support using Logto.
The project consists of a frontend application and a backend service that demonstrate organization management, user authentication, document management, and Logto management API integration features.
This codebase implements the concepts and features discussed in the blog post, including:
- Multi-tenant organization management
- User authentication with Logto
- Document management system
- Organization level role-based access control
- Logto management API integration
frontend/
: React-based frontend applicationbackend/
: Node.js backend service
To run the complete application locally, you'll need to:
- Start the backend service first
- Start the frontend application
- Configure the proper environment variables in both projects
- Ensure your Logto application is properly configured with the correct redirect URIs
- Navigate to the backend directory:
cd backend
- Copy the environment file and configure Logto settings:
cp .env.example .env
- Install dependencies:
npm install
- Start the development server:
npm run dev
The backend server will be running at http://localhost:3000.
- Navigate to the frontend directory:
cd frontend
- Configure the environment variables in
src/env.ts
:
export const APP_ENV = {
logto: {
endpoint: "<YOUR_LOGTO_ENDPOINT>",
appId: "<YOUR_LOGTO_APP_ID>",
},
api: {
baseUrl: "<YOUR_BACKEND_API_BASE_URL>",
resourceIndicator: "<YOUR_API_RESOURCE_INDICATOR>",
},
app: {
redirectUri: "<YOUR_REDIRECT_URI>", // Ensure this matches the redirect URI in your Logto app settings in the Console
signOutRedirectUri: "<YOUR_SIGN_OUT_REDIRECT_URI>", // Ensure this matches the sign out redirect URI in your Logto app settings in the Console
},
};
- Install dependencies:
npm install
- Start the development server:
npm run dev
The frontend application will be running at http://localhost:5173.
For a detailed explanation of the concepts and implementation details, please read the accompanying blog post: Build a multi-tenant SaaS application: A complete guide from design to implementation
This project is licensed under the MIT License - see the LICENSE file for details.