A Lerna and NPM Workspaces powered monorepo for managing multiple Express.js/TypeScript backend microservices. Currently contains the ai-chat application, which utilizes MongoDB, Clerk, and ImageKit.
Live Demo (AI Thread): https://i-faaza.com/app/ai-thread
Make sure you have the following installed on your machine:
- Node.js (v18 or higher recommended)
- pnpm (v9 or higher)
- Redis (v7 or higher) - Required for Quota Management/Rate Limiting.
- A running MongoDB instance or a MongoDB Atlas connection string.
- A Clerk account for authentication.
- An ImageKit account for media handling.
-
Clone the repository (if you haven't already):
# navigate to your directory cd be-multiapp
-
Install dependencies: Run this from the root directory. PNPM Workspaces will automatically link packages:
pnpm install
-
Set up Environment Variables: Depending on how you plan to run the application, configure your environment variables:
Option A: Using Docker Compose (Recommended) Create a
docker-compose.override.ymlfile in the root directory for your local development secrets. This file is ignored by Git.version: '3.8' services: api: environment: - IMAGE_KIT_ENDPOINT=your_imagekit_endpoint - IMAGE_KIT_PUBLIC_KEY=your_imagekit_public_key - IMAGE_KIT_PRIVATE_KEY=your_imagekit_private_key - CLIENT_URL=http://localhost:5173 - MONGO=your_mongodb_connection_string - CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key - CLERK_SECRET_KEY=your_clerk_secret_key - REDIS_PRIVATE_URL=redis://localhost:6379 - GEMINI_API_KEY=your_gemini_api_key
Option B: Running locally with npm Create a
.envfile in the root directory. You can use the existingenvfile as a template (cp env .env), then populate it:# ImageKit credentials IMAGE_KIT_ENDPOINT=your_imagekit_endpoint IMAGE_KIT_PUBLIC_KEY=your_imagekit_public_key IMAGE_KIT_PRIVATE_KEY=your_imagekit_private_key # Frontend Client URL (for CORS) CLIENT_URL=http://localhost:5173 # MongoDB Connection String MONGO=your_mongodb_connection_string # Clerk Authentication credentials CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key CLERK_SECRET_KEY=your_clerk_secret_key # Redis Connection REDIS_PRIVATE_URL=redis://127.0.0.1:6379 # Gemini API Key GEMINI_API_KEY=your_gemini_api_key
To run ai-chat in development mode:
pnpm --filter ai-chat dev(Or cd apps/ai-chat && pnpm dev)
Note: Pastikan Redis Server sudah berjalan di lokal (atau melalui Docker terpisah) sebelum menjalankan aplikasi.
The server should now be running.
To build and run the application for production locally:
-
Build all apps using Lerna:
npx lerna run build
-
Start the compiled application:
npm start --workspace=apps/ai-chat
You can also run the application using Docker. This ensures a consistent environment and simplifies deployment.
We use Docker Compose overrides to manage environments without relying on a .env file.
Local Development:
- Edit the
docker-compose.override.ymlfile to include your local environment variables. - Run Docker Compose. It will automatically merge the
overridefile with the basedocker-compose.yml:To rebuild the image if you make changes, rundocker-compose up -d
docker-compose up --build -d.
Production Deployment:
- Edit the
docker-compose.prod.ymlfile with your actual production credentials. - Tell Docker Compose to use both the base file and the production file explicitly:
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
- Add a Redis service in your Railway project.
- In your API service settings, add a variable:
REDIS_PRIVATE_URLwith value${{Redis.REDIS_PRIVATE_URL}}. - Railway will handle the connection automatically.
To stop the container in either environment:
docker-compose down- Framework: Express.js
- Language: TypeScript
- Database: MongoDB with Mongoose
- Caching/Rate Limiting: Redis via
ioredis - Authentication: Clerk (
@clerk/express) - Other:
cors,dotenv,pnpm