Skip to content

livingdolls/log-activity-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Activity System

Go Version License API Docs

🚀 Fitur Utama

📊 Core Features

  • Activity Logging: Pencatatan aktivitas API
  • Client Registration: Sistem registrasi client dengan API key otomatis dan JWT authentication
  • Usage Analytics: Statistik penggunaan harian dan peringkat client teratas
  • Real-time Streaming: Server-Sent Events (SSE) untuk update real-time

⚡ Performance Features

  • Rate Limiting: Pembatasan request per jam menggunakan Redis (1000 req/hour default)
  • Batch Processing: Pemrosesan log dalam batch dengan queue system
  • Table Partitioning: Partisi MySQL otomatis berdasarkan bulan untuk performa optimal
  • Multi-level Caching: LRU cache + Redis untuk response caching
  • Durable Queue: File-based fallback storage untuk ketahanan data

🔐 Security Features

  • API Key Authentication: Secure API key generation dan hashing
  • JWT Token: Bearer token authentication untuk protected endpoints
  • Data Encryption: AES-256-GCM encryption untuk sensitive data
  • IP Whitelist Protection: Konfigurasi IP whitelist untuk akses API yang aman
  • HMAC Validation: API key hashing dengan HMAC-SHA256

🛠️ Quick Start

Prerequisites

  • Go 1.24+
  • MySQL 8.0+
  • Redis 6.0+

Install dependencies

go mod download

Setup configuration

cp config/config.yaml.example config/config.yaml

Edit config/config.yaml sesuai environment Anda


### Configuration
```yaml
# config/config.yaml
mode: "development"

database:
  driver: "mysql"
  host: "localhost"
  port: "3306"
  user: "your_user"
  password: "your_password"
  dbname: "logdb"
  max_open_cons: 10
  max_idle_cons: 5
  max_life_time: 5

redis:
  host: "localhost"
  port: "6379"
  password: ""
  db: 0
  pool_size: 10
  min_idle_conns: 5

server:
  port: 3000

# IP Whitelist Configuration
security:
  ip_whitelist:
    enabled: true
    allowed_ips:
      - "127.0.0.1"
      - "::1"

secret:
  jwt_key: "your_jwt_secret_key_here"
  aes_key: "your_base64_encoded_aes_key_here"  # 32 bytes base64

Running the Application

# Development mode
make run

# Build binary
make build
./main

# Generate Swagger docs
make swagger

# Run tests
make test

Run with Docker Compose

# Build dan jalankan semua services
make docker-up

# Atau dengan docker compose langsung
docker compose up --build

# Jalankan di background
docker compose up -d --build

📡 API Documentation

Base URL: http://localhost:3000/api

Swagger UI: http://localhost:3000/swagger/index.html

🗄️ Database Partitioning

Automatic Partition Management

  • Monthly Partitions: Otomatis membuat partisi per bulan
  • Auto Cleanup: Menghapus partisi lama (default: >3 bulan)
  • Future-proof: Partisi p_future untuk data di masa depan

Partition Naming Convention

p_YYYYMM # Contoh: p_202511, p_202512, p_202601

🛡️ IP Whitelist Configuration

IP Format Support

  • Single IP: 192.168.1.100
  • IPv6: 2001:db8::1
  • CIDR Range: 192.168.1.0/24
  • IPv6 CIDR: 2001:db8::/32

IP Detection Priority

  1. X-Forwarded-For (load balancer/proxy)
  2. X-Real-IP (nginx)
  3. X-Client-IP
  4. CF-Connecting-IP (Cloudflare)
  5. RemoteAddr (fallback)

Project Structure

log-activity-system/
├── cmd/server/main.go           # Entry point
├── config/config.yaml           # Configuration
├── docs/                        # Swagger documentation
├── internal/
│   ├── adapter/
│   │   ├── http/               # REST API handlers
│   │   ├── memory/             # Cache implementation
│   │   └── repository/         # Data access layer
│   ├── applications/
│   │   ├── dto/                # Request/Response models
│   │   ├── port/               # Interface definitions
│   │   └── service/            # Business logic
│   ├── domain/                 # Domain entities
│   │   ├── client.go
│   │   ├── log-entry.go
│   │   └── errors.go
│   ├── infrastructure/
│   │   ├── presistence/        # Database & partitioning
│   │   ├── security/           # Crypto & JWT
│   │   ├── memory/             # Redis connection
│   │   └── ratelimit/          # Rate limiting
│   └── utils/                  # Utilities
├── Makefile                     # Build commands
├── go.mod                       # Dependencies
└── README.md

🙏 Acknowledgments

  • Gin Framework untuk HTTP router
  • GORM untuk database ORM
  • Redis untuk caching dan rate limiting
  • JWT-Go untuk token authentication
  • Swagger untuk API documentation

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages