A modern, full-stack real-time chat application built with Go (Golang) backend and React frontend. Features instant messaging, user authentication, online status tracking, and a beautiful responsive UI.
- User registration and login system
- JWT-based authentication
- Password hashing with bcrypt
- Protected routes and middleware
- Input validation and sanitization
- Instant message delivery via WebSocket
- Online/offline user status tracking
- Real-time user presence indicators
- Message broadcasting to connected users
- Persistent message history
- Responsive design with Tailwind CSS
- Beautiful and intuitive chat interface
- Dark/light theme support
- Loading skeletons and smooth animations
- Toast notifications for user feedback
- Clean MVC architecture
- Modular component structure
- State management with Zustand
- RESTful API design
- WebSocket integration
- Framework: Gorilla Mux for HTTP routing
- Database: MongoDB with official Go driver
- Real-time: WebSocket connections
- Authentication: JWT tokens
- Security: Password hashing, input validation
- Environment: dotenv for configuration
- Framework: React 19 with Vite
- State Management: Zustand
- Styling: Tailwind CSS + DaisyUI
- HTTP Client: Axios
- Routing: React Router DOM
- Icons: Lucide React
- Notifications: React Hot Toast
go-chat/
├── backend/
│ ├── src/
│ │ ├── main.go # Application entry point
│ │ ├── controllers/ # HTTP request handlers
│ │ │ ├── auth.controller.go
│ │ │ └── messages.controller.go
│ │ ├── lib/ # Core libraries
│ │ │ ├── db.go # Database connection
│ │ │ └── socket.go # WebSocket handling
│ │ ├── middleware/ # HTTP middleware
│ │ │ ├── authenticate.go
│ │ │ └── cors.go
│ │ ├── models/ # Data models
│ │ │ ├── messages.go
│ │ │ └── users.go
│ │ └── routes/ # API routes
│ │ ├── auth.route.go
│ │ └── messages.route.go
│ ├── internals/ # Internal utilities
│ │ ├── security.go
│ │ └── validate.go
│ ├── utils/ # Helper functions
│ │ ├── json.go
│ │ └── jwt.go
│ ├── go.mod
│ └── go.sum
├── frontend/
│ ├── src/
│ │ ├── App.jsx # Main app component
│ │ ├── main.jsx # App entry point
│ │ ├── components/ # Reusable components
│ │ │ ├── ChatContainer.jsx
│ │ │ ├── Sidebar.jsx
│ │ │ ├── MessageInput.jsx
│ │ │ └── ...
│ │ ├── pages/ # Route components
│ │ │ ├── HomePage.jsx
│ │ │ ├── LoginPage.jsx
│ │ │ └── SignUpPage.jsx
│ │ ├── store/ # State management
│ │ │ ├── useAuthStore.js
│ │ │ ├── useChatStore.js
│ │ │ └── useThemeStore.js
│ │ └── lib/ # Utilities
│ │ ├── axios.js
│ │ └── utils.js
│ ├── package.json
│ └── vite.config.js
└── README.md
- Go 1.24.2 or higher
- Node.js 18+ and npm/yarn
- MongoDB database
- Git
-
Clone the repository
git clone https://github.com/muskiteer/go-chat cd go-chat/backend -
Install Go dependencies
go mod download
-
Environment Configuration Create a
.envfile in the backend directory:PORT=8000 MONGODB_URI=mongodb://localhost:27017 JWT_SECRET=your-super-secret-jwt-key NODE_ENV=development
-
Start MongoDB Make sure MongoDB is running on your system:
# For local MongoDB installation mongod # Or using Docker docker run -d -p 27017:27017 --name mongodb mongo:latest
-
Run the backend server
cd src go run main.goThe server will start on
http://localhost:8000
-
Navigate to frontend directory
cd ../frontend -
Install dependencies
npm install # or yarn install -
Environment Configuration Create a
.envfile in the frontend directory:VITE_API_URL=http://localhost:8000
-
Start the development server
npm run dev # or yarn devThe frontend will start on
http://localhost:5173
POST /api/auth/signup- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutGET /api/auth/check- Check authentication status
GET /api/messages/users- Get all users for chatGET /api/messages/:id- Get messages with specific userPOST /api/messages/send/:id- Send message to user
WS /ws?userId={userId}- WebSocket connection for real-time features
{
_id: ObjectId,
username: String,
email: String,
hashed_password: String,
created_at: Date
}{
_id: ObjectId,
sender_id: ObjectId,
receiver_id: ObjectId,
content: String,
created_at: Date
}github.com/golang-jwt/jwt/v5 v5.2.2
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
github.com/joho/godotenv v1.5.1
github.com/microcosm-cc/bluemonday v1.0.27
go.mongodb.org/mongo-driver v1.17.4
golang.org/x/crypto v0.33.0{
"react": "^19.1.0",
"zustand": "^5.0.6",
"axios": "^1.10.0",
"react-router-dom": "^7.6.3",
"tailwindcss": "^3.4.17",
"daisyui": "^4.12.23",
"lucide-react": "^0.525.0",
"react-hot-toast": "^2.5.2"
}- WebSocket connections for instant messaging
- Online user status tracking
- Real-time message delivery
- Connection management and cleanup
- JWT-based authentication
- Password hashing with bcrypt
- Input validation and sanitization
- CORS protection
- Protected routes
- Responsive design for all devices
- Dark/light theme toggle
- Loading states and skeletons
- Error handling with toast notifications
- Smooth animations and transitions
# Backend tests
cd backend
go test ./...
# Frontend tests
cd frontend
npm test# Backend
cd backend/src
go build -o ../bin/chat-app main.go
# Frontend
cd frontend
npm run build- Build the Go binary
- Set up environment variables
- Configure MongoDB connection
- Deploy to your preferred platform (AWS, GCP, Heroku, etc.)
- Build the React app
- Deploy to static hosting (Vercel, Netlify, AWS S3, etc.)
- Update API URLs for production
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Go community for excellent libraries
- React team for the amazing framework
- MongoDB for reliable database solutions
- All contributors and testers
Made with ❤️ by Muskiteer
For questions or support, please open an issue or contact the maintainers.