A real-time community platform backend inspired by Discord, built with NestJS, Prisma, and MySQL. Kord provides a complete REST API and WebSocket support for building modern chat applications with servers, channels, messaging, threading, reactions, roles, and user profiles.
- Overview
- Features
- Tech Stack
- Getting Started
- Running the Application
- Testing
- API Documentation
- Project Structure
- Development
- Contributing
- License
Kord is a Discord-inspired real-time community platform backend that enables:
- User Authentication: Cookie-based authentication with JWT access and refresh tokens
- Servers: Create and manage community spaces
- Channels: Text and voice channels with public, restricted, and private access
- Messaging: Rich message content with attachments, threading, and soft deletes
- Reactions: Emoji reactions on messages
- Roles & Permissions: Fine-grained role-based access control
- Direct Messages: Private DM channels between users
- User Profiles: Extended user information with social links
- ✅ RESTful API with comprehensive CRUD operations
- ✅ Cookie-based Authentication using JWT (access + refresh tokens)
- ✅ Role-Based Access Control (RBAC) with customizable permissions
- ✅ Real-time WebSocket Support for live updates
- ✅ Threaded Conversations with parent-child message relationships
- ✅ Rich Message Content with JSON-based content and file attachments
- ✅ Server Invites with expiration support
- ✅ User Muting & Channel Blocking for moderation
- ✅ Soft Deletes for message archival
- ✅ Pagination Support for large datasets
- ✅ Comprehensive Validation using class-validator
- ✅ Database Migrations with Prisma
- ✅ Unit & E2E Testing with Jest
- Framework: NestJS 11.x
- ORM: Prisma 6.x
- Database: MySQL
- Authentication: Passport.js (JWT + Local strategies)
- Validation: class-validator & class-transformer
- Testing: Jest & Supertest
- Language: TypeScript 5.x
- WebSockets: Socket.IO
- Node.js 18.x or higher
- npm or yarn
- MySQL 8.x or higher
- Git
- Clone the repository:
git clone https://github.com/nivx18818/kord-api.git
cd kord-api- Install dependencies:
npm installCreate a .env file in the root directory with the following variables:
# Database
DATABASE_URL=mysql://username:password@localhost:3306/kord
# JWT Secrets
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production
# JWT Expiration
JWT_ACCESS_EXPIRATION=15m
JWT_REFRESH_EXPIRATION=7d
# Server
PORT=3000
NODE_ENV=development
# CORS
FRONTEND_URL=http://localhost:5173- Create a MySQL database:
CREATE DATABASE kord CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;- Generate Prisma client:
npx prisma generate --schema prisma/schema.prisma- Run database migrations:
npx prisma migrate dev --name initnpm run start:devThe API will be available at http://localhost:3001/api/v1
npm run build
npm run start:prodnpm run start:debugnpm run testnpm run test:e2enpm run test:covnpm run test:watchThe API is organized into the following modules:
- Authentication - Register, login, logout, token refresh
- Users - User management and profiles
- Servers - Server creation and management
- Channels - Channel operations and DMs
- Messages - Messaging and threading
- Reactions - Emoji reactions
- Roles - Role and permission management
- Memberships - Server member management
All API endpoints are prefixed with /api/v1:
http://localhost:3001/api/v1
Most endpoints require authentication via JWT tokens stored in HTTP-only cookies:
accessToken- Short-lived token for API requests (15 minutes)refreshToken- Long-lived token for obtaining new access tokens (7 days)
See the Frontend Integration Guide for detailed examples of integrating with a frontend application.
kord-api/
├── prisma/
│ ├── schema.prisma # Prisma schema definition
│ └── migrations/ # Database migrations
├── src/
│ ├── common/ # Shared utilities and guards
│ │ ├── constants/ # Constants (permissions, error codes)
│ │ ├── decorators/ # Custom decorators
│ │ ├── dto/ # Shared DTOs
│ │ ├── exceptions/ # Custom exceptions
│ │ └── guards/ # Global guards (roles, etc.)
│ ├── modules/ # Feature modules
│ │ ├── auth/ # Authentication module
│ │ ├── users/ # User management
│ │ ├── servers/ # Server management
│ │ ├── channels/ # Channel management
│ │ ├── messages/ # Messaging
│ │ ├── reactions/ # Reactions
│ │ ├── roles/ # Roles and permissions
│ │ ├── memberships/ # Server memberships
│ │ ├── profiles/ # User profiles
│ │ ├── attachments/ # File attachments
│ │ └── prisma/ # Prisma service
│ ├── app.module.ts # Root module
│ └── main.ts # Application entry point
├── test/ # E2E tests
├── docs/ # Documentation
├── bruno/ # API test collections
└── generated/ # Generated Prisma client- Linting: ESLint with TypeScript support
- Formatting: Prettier
- Validation: class-validator decorators on DTOs
npm run build- Build the applicationnpm run format- Format code with Prettiernpm run lint- Lint and fix code with ESLintnpm run start- Start the applicationnpm run start:dev- Start in watch modenpm run start:debug- Start in debug modenpm run start:prod- Start production build
npx prisma generate- Generate Prisma clientnpx prisma migrate dev- Create and apply migrationnpx prisma migrate deploy- Apply migrations (production)npx prisma studio- Open Prisma Studio GUInpx prisma db push- Push schema changes (dev only)
- Generate module:
nest g module modules/feature-name - Generate controller:
nest g controller modules/feature-name - Generate service:
nest g service modules/feature-name - Create DTOs in
modules/feature-name/dto/ - Update Prisma schema if needed
- Run
npx prisma generateandnpx prisma migrate dev
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Built with ❤️ using NestJS