A real-time chat application backend built with Node.js, Express, PostgreSQL, and Socket.IO.
- User authentication (register, login, logout)
- Email verification
- Password reset functionality
- User profile management
- Real-time messaging with Socket.IO
- Direct and group conversations
- Message typing indicators , File attachments
- Group conversation management
-
Clone the repository
-
Install dependencies
npm install
-
Environment variables
- Copy
.env.exampleto.env - Configure environment variables as needed
- Copy
-
Start Docker containers
docker compose up
This will start:
- PostgreSQL database
- Adminer (for database management)
- MailHog (for development email testing)
-
Database setup
npm run db
This will run migrations and seed the database
Start development server
npm run devThe server will start at http://localhost:3000 (or the port specified in your .env file)
API documentation is available via Swagger UI at:
http://localhost:3000/api-docs
POST /api/v1/auth/register- Register a new userPOST /api/v1/auth/login- User loginPOST /api/v1/auth/verify-email- Email verificationPOST /api/v1/auth/logout- User logoutPOST /api/v1/auth/forgot-password- Request password resetPOST /api/v1/auth/reset-password- Reset password
GET /api/v1/user/me- Get current user profileGET /api/v1/user/:id- Get user by IDPATCH /api/v1/user/:id- Update user profilePOST /api/v1/user/update-password- Update password
GET /api/v1/conversation- Get all conversationsGET /api/v1/conversation/:id- Get conversation by IDPOST /api/v1/conversation/direct- Create direct conversationPOST /api/v1/conversation/group- Create group conversationPATCH /api/v1/conversation/:id- Update group detailsDELETE /api/v1/conversation/:id- Delete conversation
POST /api/v1/message- Create messageGET /api/v1/message/conversation/:conversationId- Get conversation messagesPATCH /api/v1/message/:messageId- Update messageDELETE /api/v1/message/:messageId- Delete message
The project follows a modular structure:
src/
├── modules/ # Feature modules
│ ├── auth/ # Authentication
│ │ ├── auth.controller.ts # Handles authentication-related requests
│ │ ├── auth.routes.ts # Defines routes for authentication
│ │ ├── auth.schema.ts # Validation schema for authentication requests
│ │ ├── auth.service.ts # Business logic for authentication
│ │ ├── userToken.model.ts # Defines UserToken model/schema
│ ├── user/ # User management
│ ├── conversation/ # Conversations
│ └── message/ # Messages
├── middlewares/ # Express middlewares
├── utils/ # Utility functions
└── app.ts # Application entry point
The application uses stateless JWT authentication. Tokens are provided upon login and must be included in the Authorization header for protected routes.
npm run dev- Run development servernpm run build- Build production codenpm run start- Run production servernpm run lint- Run ESLintnpm run db- Run migrations and seed databasenpm run db:reset- Drop, create, and seed databasenpm run db:refresh- Reset migrations and run again