Skip to content

codaxa/z-chat

Repository files navigation

Z-Chat

A real-time chat application built with Go, WebSockets, and a PostgreSQL backend.

Features

  • Real-time messaging via WebSockets
  • User Authentication with JWT
  • REST API for registration, login, and message history
  • PostgreSQL Integration for data persistence
  • Database Migrations managed by Atlas and GORM
  • Hub Pattern for concurrent client management
  • Configuration Management using environment variables
  • Containerized development environment with Docker

Prerequisites

Before you begin, ensure you have the following installed:

Quick Start

  1. Clone the repository:

    git clone https://github.com/codaxa/z-chat
    cd z-chat
  2. Configure your environment: Create a .env file in the root directory. You can use the following template, replacing the placeholder values with your local configuration.

    # PostgreSQL Settings
    DB_USER=admin
    DB_PASSWORD=your_secure_password
    DB_NAME=z-chat
    DB_HOST=localhost
    DB_PORT=5432
    
    # For Docker Compose
    POSTGRES_USER=${DB_USER}
    POSTGRES_PASSWORD=${DB_PASSWORD}
    POSTGRES_DB=${DB_NAME}
    
    # JWT Settings
    JWT_SECRET=your_strong_jwt_secret
  3. Start the database:

    docker-compose up -d
  4. Set up the database schema: This command will create the database, run migrations, and get everything ready.

    task setup
  5. Run the application:

    task run

    The server will start on localhost:8080.

Development

This project uses Taskfile as a command runner.

  • Run tests:

    task test
  • Run with hot-reloading (requires Air):

    go install github.com/cosmtrek/air@latest
    task dev-air
  • Run code quality checks:

    task lint
  • Create a new database migration: After making changes to GORM models in internal/domain/models/, run:

    task migrate-new
  • See all available tasks:

    task --list

Architecture

cmd/chatserver/     # Application entry point
internal/
├── config/         # Configuration management
├── context/        # Context keys for request-scoped values
├── domain/         # Core domain models and repository interfaces
├── handlers/       # HTTP and WebSocket handlers
├── hub/            # WebSocket hub & client management
├── middleware/     # HTTP middleware (e.g., authentication)
├── services/       # Business logic (e.g., authentication service)
├── storage/        # Database implementation (PostgreSQL)
└── transport/http/ # HTTP routing and server setup
migrations/         # Database migration files

Dependencies

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages