Skip to content

Kirara02/Go-Fiber-ChatApp

Repository files navigation

Go Fiber Real-Time Chat Application

Go Version Framework Database Docker License

A high-performance, feature-rich real-time chat application built with Go (Fiber) on the backend and Vanilla JavaScript on the frontend. This project demonstrates a clean backend architecture, WebSocket-based real-time messaging, and secure JWT-based authentication.


📸 Screenshots

Here are some screenshots from the application:

🔐 Login Screen

Login

💬 Chat Room

Chat Room

🏘️ Rooms List

Rooms

✨ Features

  • Secure Authentication: Registration, login, logout using JWT (Access & Refresh Tokens).
  • Multi-Room Chat:
    • Direct Messages (DM): Auto-created 1-on-1 private chat rooms.
    • Group Chats: Create or join group chats with multiple participants.
  • Real-Time Messaging: Instant message delivery via WebSocket.
  • Lobby & Chat History: View joined rooms and load previous messages on entry.
  • Persistent Database: PostgreSQL for users, rooms, and message storage.
  • Dynamic UI: Intuitive frontend with auto-generated avatars and readable user display names.

📦 Tech Stack

Component Technology
Backend Go, Fiber v2, GORM, Google Wire, PostgreSQL, WebSocket
Frontend Vanilla JavaScript (ES6+), HTML5, CSS3
Deployment Docker, Docker Compose
Cloud Storage Cloudinary for image uploads and CDN delivery

📱 Mobile Frontend

This project is compatible with a Flutter-based mobile frontend available here:

🔗 Flutter Chat App Repository


🧱 Architecture

This project follows a layered architecture to ensure clean separation of concerns and maintainability:

+----------------+      +----------------+      +------------------+      +-------------+
|     Client     |----->|     Handler    |----->|      Service     |----->| Repository  |
| (JS/WebSocket) |      | (Validation)   |      | (Business Logic) |      | (Database)  |
+----------------+      +----------------+      +------------------+      +-------------+
  • Handler: Receives HTTP/WebSocket requests and performs validation.
  • Service: Contains application business logic.
  • Repository: Handles communication with the database.
  • Dependency Injection: Managed via Google Wire.

☁️ Cloudinary Integration

This project uses Cloudinary for hosting and delivering profile images with CDN support.

Why Cloudinary?

  • Automatic image optimization and resizing
  • High availability via CDN
  • Public ID–based upload and retrieval
  • Built-in image foldering (e.g., go-chat-app/profiles)

Required .env Configuration

# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
CLOUDINARY_BASE_FOLDER=go-chat-app

🚀 Getting Started

Prerequisites


Method 1: Using Docker (Recommended)

# Clone the repository
git clone https://github.com/your-username/go-fiber-chatapp.git
cd go-fiber-chatapp

# Create a .env file
cp .env.example .env
# Fill in your database, JWT, and Cloudinary credentials

# Build and run
docker-compose up --build

Access the app at http://localhost:8080


Method 2: Manual Setup (Without Docker)

  1. Clone the repo and set up .env as shown above.
  2. Make sure PostgreSQL is running and create the necessary database.
  3. Install Go dependencies:
go mod tidy
  1. Generate Dependency Injection files:
go generate ./...
  1. Run the app:
go run .

🔌 API Endpoints

Method Endpoint Description
POST /api/auth/register Register a new user
POST /api/auth/login Login and get access + refresh tokens
POST /api/auth/logout Invalidate refresh token
POST /api/auth/refresh Refresh access token
GET /api/profile Get current user's profile
PUT /api/profile Update current user's profile
GET /api/users List all users
GET /api/rooms List rooms joined by user
POST /api/rooms Create a new room (group or DM)
GET /chat/ws/:roomId WebSocket endpoint for a room

🛣️ Roadmap

  • Online/Offline user status
  • Typing indicators
  • Unit and integration tests
  • Group management (invite/kick)
  • File and image attachments in chat

📄 License

This project is licensed under the MIT License.

About

A feature-rich, high-performance real-time chat application built using Go (Fiber) for the backend and vanilla JavaScript for the frontend. This project demonstrates a clean backend architecture, the use of WebSockets for bidirectional communication, and secure JWT-based authentication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors