- Overview
- Architecture
- Features
- Tech Stack
- Quick Start
- API Endpoints
- Monitoring & Logging
- Development
- Contributing
This project demonstrates a complete microservice architecture with:
- Go REST API for user management
- PostgreSQL database with GORM
- ELK Stack (Elasticsearch, Logstash, Kibana) for centralized logging
- Docker Compose for easy deployment
- Structured logging with Zap logger
- Performance monitoring and analytics
graph TB
subgraph "Client Layer"
C[Web Browser]
API[API Client]
end
subgraph "Application Layer"
GO[Go User Service<br/>Port 8080]
end
subgraph "Data Layer"
PG[(PostgreSQL<br/>Port 5432)]
end
subgraph "Logging Layer"
LS[Logstash<br/>Port 5000]
ES[(Elasticsearch<br/>Port 9200)]
KB[Kibana<br/>Port 5601]
FB[Filebeat]
end
C --> GO
API --> GO
GO --> PG
GO --> LS
LS --> ES
ES --> KB
FB --> LS
style GO fill:#00ADD8,stroke:#333,stroke-width:2px,color:#fff
style PG fill:#336791,stroke:#333,stroke-width:2px,color:#fff
style LS fill:#FEC514,stroke:#333,stroke-width:2px,color:#000
style ES fill:#005571,stroke:#333,stroke-width:2px,color:#fff
style KB fill:#F04E98,stroke:#333,stroke-width:2px,color:#fff
style FB fill:#005571,stroke:#333,stroke-width:2px,color:#fff
- CRUD operations for users
- Password hashing with bcrypt
- Email & username uniqueness validation
- Soft delete support
- Pagination for user lists
- Structured JSON logging with Zap
- Request/response logging with middleware
- Performance metrics (response time, status codes)
- Business event logging (user creation, updates)
- Centralized log storage in Elasticsearch
- Docker containerization
- Health checks for all services
- Environment-based configuration
- Graceful shutdown handling
- Makefile for common operations
| Component | Technology | Version |
|---|---|---|
| Backend | Go | 1.23+ |
| Web Framework | Gin | 1.9.1 |
| ORM | GORM | 1.25.5 |
| Database | PostgreSQL | 15 |
| Logger | Zap | 1.27.0 |
| Search Engine | Elasticsearch | 8.11.0 |
| Log Processor | Logstash | 8.11.0 |
| Visualization | Kibana | 8.11.0 |
| Containerization | Docker | 20.10+ |
- Docker & Docker Compose
- Make (optional, for convenience)
git clone https://github.com/ozturkeniss/ELK-Stackgin.git
cd ELK-Stackgin# Using Docker Compose
docker-compose up -d
# Or using Makefile
make setup# Check service status
docker-compose ps
# Test Go API
curl http://localhost:8080/health
# Test Elasticsearch
curl http://localhost:9200/_cluster/health
# Open Kibana
open http://localhost:5601curl -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "123456",
"first_name": "Test",
"last_name": "User",
"age": 25
}'| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Service health check |
POST |
/users |
Create new user |
GET |
/users |
Get all users (paginated) |
GET |
/users/:id |
Get user by ID |
GET |
/users/email |
Get user by email |
PUT |
/users/:id |
Update user |
DELETE |
/users/:id |
Delete user (soft delete) |
{
"level": "INFO",
"timestamp": "2025-08-27T23:00:28.473Z",
"msg": "User created successfully",
"request_id": "20250827230028-PFIyvAFJ",
"user_id": 1,
"username": "dockeruser",
"email": "docker@example.com",
"response_time": "63.701874ms",
"status_code": 201,
"service": "user-service",
"environment": "development"
}- Open Kibana: http://localhost:5601
- Create Index Pattern:
go-app-logs-* - Time Field:
@timestamp - Discover: View and search logs
- Dashboard: Create visualizations
- Response times by endpoint
- Error rates and status codes
- User activity patterns
- Database performance
- Service health status
elk-stack-user/
βββ cmd/
β βββ main.go # Application entry point
βββ internal/
β βββ database/ # Database connection & migrations
β βββ handler/ # HTTP handlers
β βββ logger/ # Logging configuration
β βββ middleware/ # HTTP middleware
β βββ model/ # Data models
β βββ repository/ # Data access layer
β βββ router/ # Route configuration
β βββ service/ # Business logic
βββ logstash/ # Logstash configuration
βββ filebeat/ # Filebeat configuration
βββ docker-compose.yml # Service orchestration
βββ Dockerfile # Go app containerization
βββ Makefile # Development commands
# Database
DB_HOST=postgres
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres123
DB_NAME=user_service
# Application
ENV=development
PORT=8080
# ELK Stack
ELK_LOGSTASH_ADDR=logstash:5000# Build and start
make setup
# View logs
make logs
make logs-app
make logs-elasticsearch
# Test services
make test
make test-elasticsearch
make test-kibana
# Clean up
make clean
make down- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.