An open API service indexing awesome lists of open source software.

https://github.com/hoan02/puchi-user-service


https://github.com/hoan02/puchi-user-service

go microservices puchi

Last synced: 10 months ago
JSON representation

Awesome Lists containing this project

README

          

# Puchi User Service

A microservice for user management and translation functionality built with Go, following clean architecture principles.

## ๐Ÿš€ Features

- **Translation Service**: Translate text using Google Translate API
- **History Management**: Store and retrieve translation history
- **Multiple Protocols**: HTTP REST API, gRPC, and AMQP RPC
- **Swagger Documentation**: Auto-generated API documentation
- **Health Checks**: Built-in health monitoring endpoints
- **Metrics**: Prometheus metrics integration

## ๐Ÿ—๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ HTTP API โ”‚ โ”‚ gRPC API โ”‚ โ”‚ AMQP RPC โ”‚
โ”‚ (Port 8002) โ”‚ โ”‚ (Port 9002) โ”‚ โ”‚ (Port 5672) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ โ”‚ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Application โ”‚
โ”‚ Layer โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Repository โ”‚
โ”‚ Layer โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โ”‚ โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ PostgreSQL โ”‚ โ”‚ Google API โ”‚ โ”‚ RabbitMQ โ”‚
โ”‚ (Port 5432) โ”‚ โ”‚ (External) โ”‚ โ”‚ (Port 5672) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## ๐Ÿ› ๏ธ Tech Stack

- **Language**: Go 1.24
- **Framework**: Fiber (HTTP), gRPC, AMQP
- **Database**: PostgreSQL
- **Message Queue**: RabbitMQ
- **Documentation**: Swagger/OpenAPI
- **Monitoring**: Prometheus
- **Containerization**: Docker & Docker Compose

## ๐Ÿ“‹ Prerequisites

- Go 1.24+
- Docker & Docker Compose
- PostgreSQL
- RabbitMQ

## ๐Ÿš€ Quick Start

### Using Docker Compose

```bash
# Start all services
make compose-up-all

# Or start only dependencies
make compose-up
```

### Manual Setup

```bash
# Install dependencies
make deps

# Run migrations
make migrate-up

# Start the service
make run
```

## ๐Ÿ“š API Endpoints

### HTTP API (Port 8002)

- `GET /v1/translation/history` - Get translation history
- `POST /v1/translation/do-translate` - Translate text
- `GET /healthz` - Health check
- `GET /metrics` - Prometheus metrics
- `GET /swagger/*` - API documentation

### gRPC API (Port 9002)

- Translation service with history management

### AMQP RPC (Port 5672)

- Asynchronous translation requests

## ๐Ÿงช Testing

```bash
# Run all tests
make test

# Run integration tests
make integration-test

# Run pre-commit checks
make pre-commit
```

## ๐Ÿ“Š Monitoring

- **Health Check**: `http://localhost:8002/healthz`
- **Metrics**: `http://localhost:8002/metrics`
- **Swagger UI**: `http://localhost:8002/swagger/`

## ๐Ÿ”ง Development

```bash
# Format code
make format

# Run linter
make linter-golangci

# Generate mocks
make mock

# Generate swagger docs
make swag-v1
```

## ๐Ÿ“ฆ Environment Variables

```bash
# App
APP_NAME=puchi-user-service
APP_VERSION=1.0.0

# HTTP settings
HTTP_PORT=8002
HTTP_USE_PREFORK_MODE=false

# gRPC
GRPC_PORT=9002

# Database
PG_URL=postgres://user:password@localhost:5432/userdb
PG_POOL_MAX=2

# RabbitMQ
RMQ_URL=amqp://guest:guest@localhost:5672/
RMQ_RPC_SERVER=user_rpc_server
RMQ_RPC_CLIENT=user_rpc_client

# Features
METRICS_ENABLED=true
SWAGGER_ENABLED=true
LOG_LEVEL=debug
```

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Run pre-commit checks (`make pre-commit`)
4. Commit your changes (`git commit -m 'Add amazing feature'`)
5. Push to the branch (`git push origin feature/amazing-feature`)
6. Open a Pull Request

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.