Monorepo with a Discord bot and NestJS API sharing a Prisma database and connected via an HTTP bridge. Full TypeScript, single-command build, and Docker support.
apps/discord-bot– Discord.js bot (CommandKit, Prisma, bridge server for API → bot, optional API client for bot → API)apps/api– NestJS backend (Prisma, health, Discord bridge client, events endpoint)packages/database– Shared Prisma schema and client (PostgreSQL)
-
Install and generate Prisma client
npm install npm run build:db
-
Environment
Copy
.env.exampleto.envand set:DATABASE_URL– PostgreSQL connection stringBOT_TOKEN– Discord bot tokenBRIDGE_SECRET– Shared secret for API ↔ bot bridge (optional but recommended)PORT– API port (default 3000)BOT_BRIDGE_URL– In Docker:http://discord-bot:3100; locally:http://localhost:3100API_URL– In Docker:http://api:3000; locally:http://localhost:3000
-
Database
npm run db:migrate:dev
All build output goes to a single dist/ folder at the repo root:
-
dist/api/– NestJS API -
dist/bot/– Discord bot -
Build everything:
npm run build -
Run API:
npm run start:api(afternpm run build) -
Run bot:
npm run start:bot(afternpm run build) -
Dev (both):
npm run dev -
Dev (single app):
npm run dev:apiornpm run dev:bot
- API → Discord:
POST /api/discord/send-messagewith{ channelId, content }– API calls the bot’s bridge; the bot sends the message. - Bot → API: Bot can call
POST /api/events/discord(e.g. viareportDiscordEvent()inapps/discord-bot/src/api-client).
cp .env.example .env
# Set BOT_TOKEN and optionally BRIDGE_SECRET in .env
docker compose up --build- postgres – PostgreSQL 16 on port 5432
- api – NestJS on port 3000 (runs migrations on start)
- discord-bot – Bot + bridge on internal port 3100
| Script | Description |
|---|---|
build |
Build db, api, bot (in order) |
build:db |
Prisma generate |
build:api |
NestJS build |
build:bot |
TypeScript build for bot |
start:api |
Run built API |
start:bot |
Run built bot |
dev |
Run API and bot in watch mode |
db:migrate |
Run Prisma migrations (deploy) |
db:migrate:dev |
Create/apply migrations (dev) |
ISC.