Skip to content

devrob-go/go-chat-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Go Chat AI - Microservices Monorepo

A modern, scalable microservices architecture built with Go, featuring authentication and AI-powered chat services. This project follows Go best practices and domain-driven design principles.

๐Ÿ—๏ธ Architecture Overview

This monorepo contains two main microservices:

  • Auth Service: Handles user authentication, authorization, and user management
  • Chat Service: Provides AI-powered chat functionality with OpenAI integration

Both services support both gRPC and REST APIs, with shared libraries for common functionality.

๐Ÿ“ Project Structure

go-chat-ai/
โ”œโ”€โ”€ api/                    # API definitions (protobuf, OpenAPI)
โ”‚   โ”œโ”€โ”€ auth/              # Auth service API definitions
โ”‚   โ”œโ”€โ”€ chat/              # Chat service API definitions
โ”‚   โ””โ”€โ”€ common/            # Shared protobuf definitions
โ”œโ”€โ”€ pkg/                   # Shared, reusable packages
โ”‚   โ”œโ”€โ”€ auth/              # JWT, authentication utilities
โ”‚   โ”œโ”€โ”€ logger/            # Structured logging
โ”‚   โ”œโ”€โ”€ middleware/        # HTTP/gRPC middleware
โ”‚   โ”œโ”€โ”€ metrics/           # Prometheus metrics
โ”‚   โ”œโ”€โ”€ database/          # Database connection and migrations
โ”‚   โ”œโ”€โ”€ config/            # Configuration management
โ”‚   โ”œโ”€โ”€ errors/            # Error handling utilities
โ”‚   โ””โ”€โ”€ utils/             # Common utilities
โ”œโ”€โ”€ services/              # Microservices
โ”‚   โ”œโ”€โ”€ auth-service/      # Authentication service
โ”‚   โ””โ”€โ”€ chat-service/      # Chat service
โ”œโ”€โ”€ deployments/           # Deployment configurations
โ”‚   โ”œโ”€โ”€ local/            # Local development
โ”‚   โ”œโ”€โ”€ staging/          # Staging environment
โ”‚   โ””โ”€โ”€ production/       # Production environment
โ”œโ”€โ”€ scripts/               # Build and deployment scripts
โ”œโ”€โ”€ docs/                  # Documentation
โ””โ”€โ”€ tools/                 # Development tools

๐Ÿš€ Quick Start

Prerequisites

  • Go 1.24 or later
  • Docker and Docker Compose
  • PostgreSQL
  • Protocol Buffers compiler (protoc)

Local Development

  1. Clone the repository

    git clone <repository-url>
    cd go-chat-ai
  2. Set up environment variables

    cp services/auth-service/env.example services/auth-service/.env
    cp services/chat-service/env.example services/chat-service/.env
    # Edit .env files with your configuration
  3. Generate protobuf code

    ./scripts/generate.sh
  4. Build all services

    ./scripts/build.sh
  5. Start local services

    ./scripts/deploy.sh -e local
  6. Run tests

    ./scripts/test.sh

๐Ÿ› ๏ธ Development

Code Generation

The project uses Protocol Buffers for API definitions. To regenerate code after changes:

./scripts/generate.sh

Building

Build individual services:

cd services/auth-service
go build -o bin/auth-service ./cmd/server

cd services/chat-service
go build -o bin/chat-service ./cmd/server

Or build all services:

./scripts/build.sh

Testing

Run tests for all services:

./scripts/test.sh

Run tests for a specific service:

cd services/auth-service
go test ./...

๐Ÿšข Deployment

Local Development

./scripts/deploy.sh -e local

Staging

./scripts/deploy.sh -e staging -s all

Production

./scripts/deploy.sh -e production -s all

Deploy Specific Service

./scripts/deploy.sh -e staging -s auth
./scripts/deploy.sh -e production -s chat

๐Ÿ“š API Documentation

Auth Service

  • gRPC: Port 50051
  • REST: Port 8080
  • Health Check: /health

Chat Service

  • gRPC: Port 50052
  • REST: Port 8081
  • Health Check: /health

๐Ÿ”ง Configuration

Environment Variables

Auth Service

  • DATABASE_URL: PostgreSQL connection string
  • JWT_SECRET: Secret for JWT token signing
  • JWT_EXPIRY: JWT token expiry time
  • PORT: Service port (default: 8080)
  • GRPC_PORT: gRPC port (default: 50051)

Chat Service

  • DATABASE_URL: PostgreSQL connection string
  • OPENAI_API_KEY: OpenAI API key
  • PORT: Service port (default: 8081)
  • GRPC_PORT: gRPC port (default: 50052)

๐Ÿงช Testing

Unit Tests

go test ./...

Integration Tests

go test -tags=integration ./...

End-to-End Tests

go test -tags=e2e ./...

๐Ÿ“Š Monitoring

The services expose Prometheus metrics at /metrics endpoints:

  • HTTP request metrics
  • gRPC request metrics
  • Database connection metrics
  • Custom business metrics

๐Ÿ”’ Security

  • JWT-based authentication
  • HTTPS/TLS support
  • Input validation and sanitization
  • SQL injection prevention
  • CORS configuration

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

For support and questions:

๐Ÿ”ฎ Roadmap

  • Add notification service
  • Implement payment service
  • Add API Gateway
  • Enhanced monitoring and alerting
  • Multi-region deployment support
  • Performance testing suite

About

microservices-based chat system built with Go, gRPC, and mTLS, featuring authentication via an auth-service and AI-powered conversations through OpenAI integration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors