Skip to content

πŸ’¬ Production-ready real-time chat API featuring JWT auth, WebSocket messaging, Redis Pub/Sub, and PostgreSQL persistence

License

Notifications You must be signed in to change notification settings

Beretta350/gochat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

91 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ GoChat

A full-stack real-time chat application built with Go and Next.js.

⚠️ Security Note: This repository contains example/development credentials. Always use strong, unique secrets in production environments.

πŸ—οΈ Architecture

                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚     Browser     β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  nginx (port 80)β”‚
                            β”‚  Reverse Proxy  β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Ό
              β”‚ /                    β”‚ /api/* & /ws         
              β–Ό                      β–Ό                      
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              
    β”‚    Next.js      β”‚    β”‚   Go + Fiber    β”‚              
    β”‚   (port 3000)   β”‚    β”‚   (port 8080)   β”‚              
    β”‚   Frontend      β”‚    β”‚   Backend API   β”‚              
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜              
                                    β”‚                       
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        
                     β–Ό              β–Ό              β–Ό        
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  
              β”‚  Redis   β”‚  β”‚  Redis   β”‚  β”‚  PostgreSQL  β”‚  
              β”‚  Pub/Sub β”‚  β”‚  Stream  β”‚  β”‚              β”‚  
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  

πŸ“ Project Structure

gochat/
β”œβ”€β”€ backend/                # Go API (Fiber + WebSocket)
β”‚   β”œβ”€β”€ cmd/                # Application entrypoint
β”‚   β”œβ”€β”€ internal/           # Private application code
β”‚   β”œβ”€β”€ pkg/                # Reusable packages
β”‚   β”œβ”€β”€ database/           # SQL migrations & schema
β”‚   β”œβ”€β”€ docs/               # API documentation
β”‚   └── README.md           # Backend-specific docs
β”‚
β”œβ”€β”€ frontend/               # Next.js Web App
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/            # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ components/     # React components
β”‚   β”‚   β”œβ”€β”€ hooks/          # Custom hooks
β”‚   β”‚   β”œβ”€β”€ store/          # Redux state management
β”‚   β”‚   β”œβ”€β”€ lib/            # Utilities
β”‚   β”‚   └── types/          # TypeScript types
β”‚   └── README.md           # Frontend-specific docs
β”‚
β”œβ”€β”€ nginx.conf              # Production reverse proxy config
β”œβ”€β”€ nginx-dev.conf          # Development reverse proxy config
β”œβ”€β”€ docker-compose.yml      # Full stack orchestration
β”œβ”€β”€ Makefile                # Project commands
└── README.md               # You are here

πŸš€ Tech Stack

Layer Technology
Frontend Next.js 14, React 18, TypeScript, Tailwind CSS
State Management Redux Toolkit, RTK Query
UI Components Radix UI, Framer Motion (LazyMotion)
Forms React Hook Form, Zod
Backend Go 1.23, Fiber v2, Uber Fx
Database PostgreSQL 16
Cache/Realtime Redis 7 (Pub/Sub + Streams)
Auth JWT (HttpOnly cookies)
Realtime WebSocket
Reverse Proxy nginx
Infrastructure Docker, Docker Compose

πŸ› οΈ Getting Started

Prerequisites

  • Docker & Docker Compose
  • Make
  • Go 1.23+ (for backend development)
  • Node.js 20+ (for frontend development)

Quick Start (Docker)

# Clone the repository
git clone https://github.com/Beretta350/gochat.git
cd gochat

# Start all services (builds and runs everything)
make docker-up

# Access the application:
# - App: http://localhost
# - Redis Commander: http://localhost:8081

Development Mode (Hot Reload)

# Start infrastructure + nginx (for local development)
make docker-dev

# In one terminal - run backend with hot reload
make dev-api

# In another terminal - run frontend with hot reload
make dev-web

# Access the application:
# - App: http://localhost (nginx proxies to local services)
# - Redis Commander: http://localhost:8081

# Stop dev environment
make docker-dev-down

πŸ“‹ Available Commands

make help                # Show all commands

# Docker - Full Stack
make docker-up           # Build and start all services
make docker-down         # Stop all services
make docker-logs         # View all logs
make docker-build        # Build all images
make docker-restart      # Rebuild and restart all

# Docker - Development
make docker-dev          # Start infra + nginx (for local dev with hot reload)
make docker-dev-down     # Stop dev environment
make docker-infra        # Start only PostgreSQL + Redis
make docker-infra-down   # Stop infrastructure

# Docker - Backend Only
make docker-api-up       # Start API + infra
make docker-api-build    # Build API image
make docker-api-logs     # View API logs
make docker-api-restart  # Rebuild and restart API

# Docker - Frontend Only  
make docker-web-up       # Start Web + API + infra
make docker-web-build    # Build Web image
make docker-web-logs     # View Web logs
make docker-web-restart  # Rebuild and restart Web

# Development (Local)
make dev-api             # Run backend with hot reload
make dev-web             # Run frontend dev server

# Backend (Go)
make api-build           # Build backend binary
make api-test            # Run backend tests
make api-lint            # Lint backend code
make api-fmt             # Format backend code

# Frontend (Next.js)
make web-install         # Install dependencies
make web-build           # Build frontend
make web-lint            # Lint frontend code
make web-test            # Run frontend tests

πŸ”— API Endpoints

Method Endpoint Description
POST /api/v1/auth/register Create account
POST /api/v1/auth/login Login
POST /api/v1/auth/refresh Refresh token
GET /api/v1/auth/me Get current user
POST /api/v1/conversations Create conversation
GET /api/v1/conversations List conversations
GET /api/v1/conversations/:id/messages Get messages
WS /ws?token=<jwt> WebSocket connection

πŸ“– See backend/README.md for detailed API documentation.

✨ Features

Backend

  • User authentication (register, login, JWT)
  • Real-time messaging via WebSocket
  • Direct messages (1:1)
  • Group conversations
  • Message history with pagination
  • Multi-device support (Redis Pub/Sub)
  • Offline message queue

Frontend

  • Modern responsive UI (mobile-first)
  • Dark theme with custom color palette
  • Smooth animations (Framer Motion)
  • Form validation (React Hook Form + Zod)
  • State management (Redux Toolkit)
  • Data caching (RTK Query)

Coming Soon

  • Typing indicators
  • Read receipts
  • File sharing
  • Push notifications
  • PWA support

πŸ“„ License

⚠️ PROPRIETARY LICENSE - All Rights Reserved

This project is published for portfolio and demonstration purposes only.

  • βœ… View source code for educational purposes
  • ❌ Commercial use prohibited without authorization
  • ❌ Copying, modifying, or distributing prohibited
  • ❌ Using as base for other projects prohibited

For licensing inquiries, contact: GitHub

See LICENSE for full terms.