A real-time chat application built with Go, WebSockets, and PostgreSQL, featuring:
โ
User Authentication (Register & Login with JWT)
โ
Public & Private Messaging (via WebSockets)
โ
User Presence Tracking (Who's online?)
โ
Chat History Retrieval (Stored in PostgreSQL)
โ
Dockerized Deployment (Runs with docker-compose)
git clone https://github.com/your-repo/chatroom.git
cd chatroom
2๏ธโฃ Configure Environment Variables
Create a .env file and add:
POSTGRES_DB=chatroom
POSTGRES_USER=alan
POSTGRES_PASSWORD=secretpassword
POSTGRES_PORT=5422
POSTGRES_HOST=postgres
SERVER_PORT=8080
3๏ธโฃ Start the Application with Docker
docker-compose up --build
Starts PostgreSQL
Builds & runs the Go application
4๏ธโฃ Use the CLI for Chat
go run cmd/cli/main.go
๐ก Features
๐ค User Authentication
Register a new user (/register)
Login to get a JWT token (/login)
Secure endpoints using JWT
๐ฌ WebSocket Real-Time Messaging
Public chat (messages visible to all users)
Private chat (direct messages between users)
Stores messages in PostgreSQL
๐ฅ User Presence Tracking
Tracks who is online (/online-users)
๐ Chat History Retrieval
Fetch previous messages (/chat-history)
๐ฆ Fully Dockerized
PostgreSQL & Go services run in Docker containers
Uses docker-compose for easy deployment
๐ Usage Examples
๐น Register a User
curl -X POST http://localhost:8080/register \
-d '{"name":"alan","email":"alan14alashti@gamil.com","password":"123456"}' \
-H "Content-Type: application/json"
๐น Login & Get JWT Token
curl -X POST http://localhost:8080/login \
-d '{"email":"alice@example.com","password":"123"}' \
-H "Content-Type: application/json"
๐น Start Chat via CLI
go run cmd/cli/main.go
Send public messages: Hello everyone!
Send private messages: @2 Hello, User 2!
Check online users: Choose Option 4
View chat history: Choose Option 5
๐ Next Steps
๐น Add Message Read Receipts
๐น Implement User Typing Indicators
๐น Deploy using Docker + Kubernetes + NATS server implementation