Skip to content
/ gochat Public

gochat is backend implemented in Go, designed as a simplified Telegram-style chat system. This project was built as a technical challenge for backend engineering interviews & job applications, demonstrating practical skills in backend architecture, secure authentication, & real-time messaging logic.

Notifications You must be signed in to change notification settings

asm2212/gochat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gochat

A Go backend for a Telegram-style chat system.

Features:

  • User signup & login (JWT, bcrypt)
  • Direct one-to-one messages
  • Group chat (create, send, fetch)
  • Global broadcast messaging

📁 Project Structure

gochat/
  main.go             # Entry point
  internal/
    api.go            # HTTP handlers
    auth.go           # JWT middleware
    user.go           # User logic
    chat.go           # Messaging logic
    model.go          # Data models
    redis.go          # Redis connection
  go.mod
  README.md

🚀 Quick Start

  1. Clone the repository

    git clone https://github.com/asm2212/gochat.git
    cd gochat
  2. Start a Redis server
    You must have Redis running on your local machine (localhost:6379).

  3. Install Go dependencies

    go mod tidy
  4. Run the server

    go run .

    The server will start on port :8080.


📖 API Endpoints

All endpoints except /signup and /login require JWT authentication.
Provide the token in the Authorization: Bearer <token> HTTP header.


🔒 Authentication

Sign Up

  • Endpoint: POST /signup
  • Request Body:
    {
      "username": "your_username",
      "password": "your_password"
    }
  • Response:
    • 201 Created on success:
      { "message": "user registered" }
    • 409 Conflict if user exists:
      { "error": "username already exists" }

Login

  • Endpoint: POST /login
  • Request Body:
    {
      "username": "your_username",
      "password": "your_password"
    }
  • Response:
    • 200 OK on success:
      { "token": "<JWT_TOKEN>" }
    • 401 Unauthorized on failure:
      { "error": "invalid credentials" }

💬 Direct Messages

Send a Direct Message

  • Endpoint: POST /dm/send
  • Headers:
    Authorization: Bearer <token>
  • Request Body:
    {
      "to": "recipient_username",
      "content": "Hello!"
    }
  • Response:
    • 200 OK
      { "message": "sent" }
    • 500 Internal Server Error
      { "error": "..." }

Fetch Direct Message History

  • Endpoint: GET /dm/history?user=recipient_username
  • Headers:
    Authorization: Bearer <token>
  • Response:
    • 200 OK
      [
        {
          "id": "b7c9...",
          "from": "alice",
          "to": "bob",
          "content": "Hello Bob!",
          "type": "direct",
          "timestamp": "2025-07-06T05:00:00Z"
        },
        ...
      ]
    • 500 Internal Server Error
      { "error": "..." }

👥 Group Chat

Create a Group

  • Endpoint: POST /group/create
  • Headers:
    Authorization: Bearer <token>
  • Request Body:
    {
      "group": "group_name"
    }
  • Response:
    • 201 Created
      { "message": "group created" }
    • 500 Internal Server Error
      { "error": "..." }

Send a Group Message

  • Endpoint: POST /group/send
  • Headers:
    Authorization: Bearer <token>
  • Request Body:
    {
      "group": "group_name",
      "content": "Group message!"
    }
  • Response:
    • 200 OK
      { "message": "sent" }
    • 500 Internal Server Error
      { "error": "..." }

Fetch Group Chat History

  • Endpoint: GET /group/history?group=group_name
  • Headers:
    Authorization: Bearer <token>
  • Response:
    • 200 OK
      [
        {
          "id": "a1b2...",
          "from": "alice",
          "group": "mygroup",
          "content": "Hi everyone",
          "type": "group",
          "timestamp": "2025-07-06T05:00:00Z"
        },
        ...
      ]
    • 500 Internal Server Error
      { "error": "..." }

📢 Broadcast

Send a Broadcast Message

  • Endpoint: POST /broadcast/send
  • Headers:
    Authorization: Bearer <token>
  • Request Body:
    {
      "content": "Message to everyone!"
    }
  • Response:
    • 200 OK
      { "message": "broadcasted" }
    • 500 Internal Server Error
      { "error": "..." }

Fetch Broadcast Messages

  • Endpoint: GET /broadcast/history
  • Headers:
    Authorization: Bearer <token>
  • Response:
    • 200 OK
      [
        {
          "id": "xxxx",
          "from": "alice",
          "content": "Hello all!",
          "type": "broadcast",
          "timestamp": "2025-07-06T05:00:00Z"
        },
        ...
      ]
    • 500 Internal Server Error
      { "error": "..." }

About

gochat is backend implemented in Go, designed as a simplified Telegram-style chat system. This project was built as a technical challenge for backend engineering interviews & job applications, demonstrating practical skills in backend architecture, secure authentication, & real-time messaging logic.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages