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