This is the backend API for the Direct real-time chat application. Built with Express.js, TypeScript, Prisma, and Socket.IO, it provides a robust, scalable, and maintainable architecture for real-time messaging, user management, and media uploads.
-
👤 User Management
- Sign up / Login / Authentication
- Get current user (
me) - Get user by ID
- Update user profile (name, avatar, bio)
- Change password with validation
-
💬 Chat Management
- Create new chats / Group chats
- Join & leave chats via invite code
- Get chat by ID
- Fetch all user chats
-
✏️ Message Handling
- Send, edit, delete messages
- Pagination support for chat messages
- Total count & optimized fetching
-
📦 Real-Time Communication
- Socket.IO integration for live messaging
- Real-time updates for edits, deletions, and new messages
-
🖼️ Media & Uploads
- Upload files/images via Cloudinary
- Avatar & chat media handling
-
🔒 Security & Validation
- JWT-based authentication
- Input validation with Zod
- Centralized error handling middleware
- Node.js & Express.js – Backend framework
- TypeScript – Type safety and better developer experience
- Prisma ORM – Database access and migrations
- PostgreSQL – Relational database (via Prisma adapter)
- Socket.IO – Real-time bi-directional communication
- Cloudinary – Image and file uploads
- Bcrypt – Password hashing
- JWT – Authentication & authorization
- Zod – Schema validation
- Nodemon & ts-node-dev – Development hot-reloading
git clone https://github.com/m-mohammad-d/direct-backend.git
cd direct-backendnpm installCreate a .env file in the root directory:
DATABASE_URL=postgresql://user:password@localhost:5432/direct
JWT_SECRET=your_jwt_secret
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
npx prisma migrate dev --name init
npx prisma generatenpm run devServer will start on http://localhost:3000 (default) and hot-reload on changes.
npm run build
npm start- All modules are modularized for maintainability.
- Socket.IO allows real-time updates for messages, edits, and deletions.
- Zod ensures strong validation for all requests.
- Prisma ensures type-safe database access and migrations.
- Cloudinary integration allows secure media handling.
- Centralized error handling middleware provides consistent API responses.