A real-time support chat application built with Express.js and Socket.IO. This boilerplate provides a complete foundation for building scalable chat applications with user authentication, real-time messaging, and a clean modular architecture.
- Real-time messaging with Socket.IO
- User authentication with JWT
- RESTful API with Express.js
- MongoDB integration with Mongoose
- Modular domain-driven architecture
- Request validation with Joi
- Comprehensive error handling
- Logging with Winston
- API documentation with Swagger
- Unit testing with Jest
- Docker support for MongoDB
- Chat widget for easy integration
- Backend: Node.js, Express.js
- Real-time: Socket.IO
- Database: MongoDB with Mongoose
- Authentication: JWT, bcrypt
- Validation: Joi
- Testing: Jest, Supertest
- Documentation: Swagger/OpenAPI
- Logging: Winston
- Development: Nodemon
-
Clone the repository
git clone https://github.com/OwaliShawon/support-chat-express-socket-boilerplate.git cd support-chat-express-socket-boilerplate -
Install dependencies
npm install
-
Set up environment variables Create a
.envfile in the root directory:NODE_ENV=development PORT=3000 MONGODB_URI=mongodb://root:example@localhost:27017/support-chat?authSource=admin JWT_SECRET=your-jwt-secret-key
-
Start MongoDB with Docker
cd docker/mongo-db docker-compose up -d -
Start the development server
npm run dev
The application will be available at http://localhost:3000
src/
βββ app.js # Express app configuration
βββ server.js # Server setup with Socket.IO
βββ routes.js # Main route definitions
βββ start.js # Application entry point
βββ configs/ # Configuration files
βββ domains/ # Domain-driven modules
β βββ auth/ # Authentication domain
β βββ chat/ # Chat functionality
β βββ users/ # User management
βββ libraries/ # Shared libraries
β βββ db/ # Database connection
β βββ error-handling/ # Error handling utilities
β βββ log/ # Logging configuration
β βββ utils/ # Utility functions
βββ middlewares/ # Express middlewares
βββ socket/ # Socket.IO event handlers
β βββ events/ # Socket event handlers
β βββ validators/ # Socket data validation
βββ views/ # EJS templates
POST /api/v1/auth/login- User loginPOST /api/v1/auth/register- User registration
GET /api/v1/users- Get all users (admin only)GET /api/v1/users/:id- Get user by IDPUT /api/v1/users/:id- Update userDELETE /api/v1/users/:id- Delete user
GET /health- Application health status
GET /widget?name=YourName- Chat widget interface
join_room- Join a chat roomleave_room- Leave a chat roomsend_message- Send a messagetyping- Typing indicator
receive_message- Receive a new messageuser_joined- User joined notificationuser_left- User left notificationtyping- Typing indicator broadcastvalidation_error- Data validation errors
Run the test suite:
# Run all tests
npm test
# Run tests in watch mode
npm run test:watchThe API is documented using Swagger. Once the server is running, visit:
- Swagger UI:
http://localhost:3000/api-docs(if configured) - OpenAPI spec: Check
swagger.yamlin the root directory
Start MongoDB and Mongo Express with Docker:
cd docker/mongo-db
docker-compose up -dThis will start:
- MongoDB on port
27017 - Mongo Express (web UI) on port
8081
# Start development server
npm run dev
# Create a new domain module
npm run create-domain
# Run tests
npm test
# Run tests in watch mode
npm run test:watchThis boilerplate follows a domain-driven design pattern:
- Domains: Self-contained modules (auth, chat, users)
- Libraries: Shared utilities and configurations
- Middlewares: Request processing layers
- Socket: Real-time communication handlers
Each domain contains:
api.js- Controller logicservice.js- Business logicroutes.js- Route definitionsdto.js- Data transfer objectsschema.js- Database schemas (if applicable)
- JWT-based authentication
- Password hashing with bcrypt
- Request validation with Joi
- Helmet.js for security headers
- CORS configuration
- Input sanitization
| Variable | Description | Default |
|---|---|---|
NODE_ENV |
Environment mode | development |
PORT |
Server port | 3000 |
MONGODB_URI |
MongoDB connection string | - |
JWT_SECRET |
JWT signing secret | - |
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/your-feature - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please:
- Check the existing issues on GitHub
- Create a new issue with detailed information
- Provide steps to reproduce any bugs
For a quick start with the chat widget:
- Start the server:
npm run dev - Visit:
http://localhost:3000/widget?name=YourName - Open multiple tabs to test real-time messaging
Happy Coding! π