Dreamkart Backend is a multi-tenant e-commerce platform designed to allow businesses to set up and manage their own online shops. Each shop (tenant) operates independently with its own data, products, and customer base, while the platform provides the core infrastructure and management tools.
The primary purpose of this project is to provide a scalable and robust backend system for a multi-tenant e-commerce application. Key features include:
- Tenant registration and management.
- Platform-level administration.
- Secure authentication for both platform and tenant users.
- Tenant-specific data isolation.
- APIs for managing products, categories, and other e-commerce functionalities within each tenant.
- Node.js: Runtime environment for executing JavaScript server-side.
- Express.js: Web application framework for Node.js, used for building APIs.
- TypeScript: Superset of JavaScript that adds static typing for better code quality and maintainability.
- MongoDB: NoSQL database used for storing platform and tenant-specific data.
- Mongoose: ODM (Object Data Modeling) library for MongoDB and Node.js, used for schema definition and data validation.
- JSON Web Tokens (JWT): Used for securing API endpoints and managing user authentication.
-
Clone the repository:
git clone <repository_url> cd dreamkart-backend
-
Install dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile in the root of the project. This file will store sensitive information and configuration settings. Add the following variables, replacing placeholder values with your actual configuration:# Server Configuration PORT=3000 NODE_ENV=development # or 'production' # MongoDB Connection MONGODB_URI=mongodb://localhost:27017/dreamkart_platform # URI for the main platform database # JWT Secrets JWT_SECRET=your_platform_jwt_secret_key # Secret key for platform-level JWTs TENANT_JWT_SECRET=your_tenant_jwt_secret_key # Secret key for tenant-level JWTs # Default Admin User (Optional - for initial platform setup if needed by a script) # DEFAULT_ADMIN_EMAIL=admin@example.com # DEFAULT_ADMIN_PASSWORD=securepassword
Note: The specific environment variables needed might vary. Check
src/config/for more details on how configurations are loaded. -
Ensure MongoDB is running: Make sure you have a MongoDB instance running and accessible with the connection URI provided in your
.envfile.
To start the development server:
npm run devThis command uses ts-node-dev to automatically transpile TypeScript and restart the server on file changes. The server will typically run on the port specified in your .env file (default is 3000).
You should see a console message indicating that the server is listening on the configured port.
This project uses Jest for running unit and integration tests. The following npm scripts are available for testing:
-
Run all tests once:
npm testThis command executes all tests found in the
testsdirectory. -
Run tests in watch mode:
npm run test:watch
This is useful during development, as it re-runs tests automatically when files change.
-
Run tests with coverage report:
npm run test:cov
This command runs all tests and generates a coverage report, showing how much of your code is covered by tests. The report can usually be found in a
coverage/directory.
Make sure you have installed all development dependencies (npm install) before running the tests.
The Dreamkart Backend exposes two main types of API endpoints:
-
Platform APIs:
- These endpoints are used for managing the platform itself, such as tenant registration, platform user authentication, etc.
- Base path:
/api/platform/... - Example:
POST /api/platform/tenants/register
-
Tenant-Specific (Application) APIs:
- These endpoints are used for operations within a specific tenant's shop, like managing products, categories, orders, and tenant user authentication.
- Base path:
/api/tenant/... - Important: All requests to tenant-specific APIs MUST include an
X-Tenant-IDheader. This header specifies the unique slug or ID of the tenant whose data is being accessed. ThetenantResolvermiddleware uses this header to switch to the correct tenant database. - Example:
GET /api/tenant/products(withX-Tenant-ID: my-shop-slugheader)
For detailed information on specific endpoints, please refer to the API documentation.