Skip to content

alan14alashti/chatroom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Chatroom Project (CLI & WebSocket)

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)

πŸ›  Setup & Installation

1️⃣ Clone the Repository

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages