A full-stack real-time chat application built with Go backend and Next.js frontend.
- Real-time WebSocket messaging
- MongoDB for message persistence
- Redis for job queuing
- Email notifications via MailHog
- Room-based chat system
- User presence management
- CORS-enabled API
- Docker containerization
- Modern React with TypeScript
- Real-time messaging interface
- Connection testing & diagnostics
- Responsive design with Tailwind CSS
- shadcn/ui components
- User presence indicators
``` gochat-server/ βββ cmd/ β βββ main.go # Application entry point βββ internal/ β βββ config/ # Configuration management β βββ database/ # MongoDB connection β βββ handlers/ # HTTP & WebSocket handlers β βββ hub/ # WebSocket hub & client management β βββ models/ # Data models β βββ queue/ # Job queue management β βββ services/ # Business logic services βββ frontend/ # Next.js frontend application β βββ app/ # Next.js app directory β βββ components/ # React components β βββ lib/ # Utility functions βββ docker-compose.yaml # Docker services configuration βββ dockerfile # Go application container βββ go.mod # Go dependencies βββ README.md # This file ```
- Go 1.23+
- Node.js 18+
- Docker & Docker Compose
```bash git clone cd gochat-server ```
```bash
docker-compose up -d
docker-compose ps ```
```bash cd frontend npm install npm run dev ```
- Frontend: http://localhost:3000
- Backend API: http://localhost:8080
- Connection Test: http://localhost:3000/test
Create a .env file in the root directory:
```env
PORT=8080
MONGO_URI=mongodb://admin:password123@localhost:27017/chatdb?authSource=admin DATABASE_NAME=chatdb
REDIS_ADDR=localhost:6379
SMTP_HOST=localhost SMTP_PORT=1025 SMTP_USER= SMTP_PASS=
CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000 ```
- Visit http://localhost:3000/test
- Click "Run All Tests" to verify backend connectivity
- Ensure all tests pass before proceeding
- Go to http://localhost:3000
- Enter your username, user ID, and room ID
- Click "Join Room" to start chatting
- Open multiple browser tabs to test real-time messaging
- MailHog UI: http://localhost:8025 (Email testing)
- Mongo Express: http://localhost:8082 (Database admin)
- Redis Commander: http://localhost:8081 (Redis admin)
- Asynq Monitor: http://localhost:8083 (Job queue monitoring)
``` βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β WebSocket β β REST API β β Job Queue β β Handlers β β Handlers β β Workers β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β β β βββββββββββββββββββββββββΌββββββββββββββββββββββββ β βββββββββββββββββββββββββββββββββββββββββββββββββββ β Hub (Message Broker) β βββββββββββββββββββββββββββββββββββββββββββββββββββ β βββββββββββββββββββββββββΌββββββββββββββββββββββββ β β β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β MongoDB β β Redis β β SMTP β β (Messages) β β (Queues) β β (MailHog) β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ ```
``` βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β Next.js Frontend β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β HomePage β ChatRoom β ConnectionTest β UI Components β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β WebSocket Client & REST API Client β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β βββββββββββββββββββββββ β Go Backend API β β (localhost:8080) β βββββββββββββββββββββββ ```
ws://localhost:8080/ws/{roomID}/{userID}?username={username}
GET /health- Health checkGET /test- Frontend connectivity testGET /rooms/{roomID}/messages?limit={limit}- Get message historyGET /rooms/{roomID}/users- Get room usersPOST /queue-email- Queue email notification
-
CORS Errors
- Ensure CORS middleware is properly configured in
cmd/main.go - Check that frontend URL is in allowed origins
- Ensure CORS middleware is properly configured in
-
WebSocket Connection Failed
- Verify Go server is running on port 8080
- Check WebSocket upgrader configuration
- Ensure no firewall blocking connections
-
Database Connection Issues
- Verify MongoDB is running:
docker-compose ps - Check MongoDB credentials in environment variables
- Ensure database is accessible on port 27017
- Verify MongoDB is running:
-
Frontend Build Errors
- Run
npm installin frontend directory - Check Node.js version (18+ required)
- Verify all dependencies are installed
- Run
```bash
docker-compose ps
docker-compose logs gochat-server
docker-compose exec mongodb mongosh
docker-compose exec redis redis-cli ping
curl http://localhost:8080/health ```
- Update environment variables for production
- Build frontend:
cd frontend && npm run build - Build Go binary:
go build -o main cmd/main.go - Deploy using Docker or your preferred platform
```bash
docker-compose -f docker-compose.prod.yml build
docker-compose -f docker-compose.prod.yml up -d ```
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Test thoroughly using the connection test
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Echo Framework for the Go web framework
- Gorilla WebSocket for WebSocket implementation
- Next.js for the React framework
- shadcn/ui for the UI components
- MongoDB for data persistence
- Redis for job queuing
- MailHog for email testing