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.
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.
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
- Go 1.24 or later
- Docker and Docker Compose
- PostgreSQL
- Protocol Buffers compiler (protoc)
-
Clone the repository
git clone <repository-url> cd go-chat-ai
-
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 -
Generate protobuf code
./scripts/generate.sh
-
Build all services
./scripts/build.sh
-
Start local services
./scripts/deploy.sh -e local -
Run tests
./scripts/test.sh
The project uses Protocol Buffers for API definitions. To regenerate code after changes:
./scripts/generate.shBuild 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/serverOr build all services:
./scripts/build.shRun tests for all services:
./scripts/test.shRun tests for a specific service:
cd services/auth-service
go test ./..../scripts/deploy.sh -e local./scripts/deploy.sh -e staging -s all./scripts/deploy.sh -e production -s all./scripts/deploy.sh -e staging -s auth
./scripts/deploy.sh -e production -s chat- gRPC: Port 50051
- REST: Port 8080
- Health Check:
/health
- gRPC: Port 50052
- REST: Port 8081
- Health Check:
/health
DATABASE_URL: PostgreSQL connection stringJWT_SECRET: Secret for JWT token signingJWT_EXPIRY: JWT token expiry timePORT: Service port (default: 8080)GRPC_PORT: gRPC port (default: 50051)
DATABASE_URL: PostgreSQL connection stringOPENAI_API_KEY: OpenAI API keyPORT: Service port (default: 8081)GRPC_PORT: gRPC port (default: 50052)
go test ./...go test -tags=integration ./...go test -tags=e2e ./...The services expose Prometheus metrics at /metrics endpoints:
- HTTP request metrics
- gRPC request metrics
- Database connection metrics
- Custom business metrics
- JWT-based authentication
- HTTPS/TLS support
- Input validation and sanitization
- SQL injection prevention
- CORS configuration
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the documentation
- Review the architecture guide
- Add notification service
- Implement payment service
- Add API Gateway
- Enhanced monitoring and alerting
- Multi-region deployment support
- Performance testing suite