The high-performance, real-time messaging engine for Bero Talker. Built with NestJS, this API provides a robust foundation for instant communication, secure authentication, and scalable data management.
- Real-time Communication: Fully functional Chat Gateway using
Socket.iofor instant messaging. - Advanced Authentication: Dual-token security system (Access & Refresh Tokens) with JWT and
Passport.js. - Conversation Management: Create group chats or direct messages, manage participants, and admin controls.
- Live Features:
- Typing indicators (User is typing...).
- Read receipts (Message status).
- Online/Offline presence tracking.
- Database Excellence: Type-safe database queries using Prisma ORM with PostgreSQL.
- Automated Documentation: Fully documented API endpoints using Swagger UI.
- Mailing System: Integrated
Nodemailerfor password resets and notifications. - Security: Password hashing with
bcrypt, CORS enabled, and strict validation pipes.
- Framework: NestJS (Node.js)
- Real-time: Socket.io
- Database: PostgreSQL
- ORM: Prisma
- Documentation: Swagger/OpenAPI
- Security: JWT, Passport, Bcrypt
- Language: TypeScript
The project follows the standard NestJS modular architecture, ensuring high maintainability and scalability:
src/
├── auth/ # Authentication logic (JWT, AT/RT Strategies, Guards)
├── user/ # User profile management and status tracking
├── conversation/ # Group & Direct chat management (Participants, Roles)
├── message/ # Message persistence, editing, and deletion logic
├── mail/ # Email service for notifications and password reset
├── prisma/ # Database connection and global Prisma service
└── chat/ # Real-time engine (WebSocket Gateway & Events)
└── chat.gateway.ts # The core Hub for all Socket.io interactions
Before running the project, ensure you have:
- Node.js (v18 or higher)
- PostgreSQL database instance
npmoryarn
-
Clone the repository:
git clone https://github.com/ibrahimdayoub/talker-backend.git cd talker-backend -
Install dependencies:
yarn install -
Environment Configuration: Create a .env file in the root directory and add your credentials:
DATABASE_URL="postgresql://USER:PASSWORD@localhost:5432/bero_talker?schema=public" # Access token JWT_SECRET="jwt-secret-123" JWT_EXPIRY="15m" # Refresh token RT_SECRET="rt-secret-456" RT_EXPIRY="7d" # Email Service (Nodemailer) MAIL_HOST="smtp.example.com" MAIL_PORT=2525 MAIL_USER="your-email@example.com" MAIL_PASS="your-password" MAIL_FROM=support@berotalker.com -
Database Migration:
npx prisma migrate dev --name init -
Start the server:
# Development mode yarn start:dev # Production mode yarn start:prod
Once the server is running, you can access the interactive Swagger documentation at: http://localhost:3000/api/docs
EVENT DIRECTION DESCRIPTION
__________________________________________________________________________________________________________________
sendMessage Client ➡️ Server Sends a new message to a specific conversation.
receiveMessage Server ️➡️ Client Broadcasts the saved message to all participants in the room.
typing Client ➡️ Server Informs others that the user is currently typing.
messagesRead Client ➡️ Server Updates the read status for messages in a conversation.
joinConversation Client ➡️ Server Validates membership and joins the specific room for real-time updates.
editMessage Client ➡️ Server Updates an existing message and notifies participants.
deleteMessage Client ➡️ Server Removes a message for all participants in real-time.
userStatusChanged Server ➡️ Client System Event: Triggered automatically on connection/disconnection.
This API powers the Bero Talker Web App


