Skip to content

emre-onal/messager

Messager - Fast & Strong Messaging Tool πŸš€

Go Reference Go Report Card License: BSD-3-Clause GitHub Release

Messager is a high-performance, scalable messaging service built with Go. It provides a robust platform for message queuing and delivery, featuring real-time status updates, persistent storage, and reliable message processing capabilities.

Banner

πŸ“‘ Table of Contents

Big Picture

Big Picture

The application exposes a REST API that allows users to create a message by providing content and phone data. Users can then retrieve a list of their messages and control the execution of jobsβ€”starting or stopping themβ€”through the same API.

Once a job is initiated, it periodically updates the status of messages that are in the pending state. These database changes are captured by Debezium and published to a Kafka topic. A Kafka consumer within the application listens for these changes and triggers an HTTP request to the corresponding client.

The metadata returned from the client is then stored in Redis. This eventual consistency architecture ensures resilience against common trade-offs such as:

  • The database being updated, but the HTTP request not being sent.
  • The HTTP request being sent, but the database not being updated.
  • Duplicate requests being triggered.

Thanks to the consumer-based design, the application can scale horizontally by running multiple replicas, enabling faster message processing. The overall architecture is designed with high availability in mind.

The application follows Domain-Driven Design (DDD) principles and applies SOLID principles effectively, using appropriate abstractions and design patterns to ensure extensibility and maintainability. Additionally, by avoiding third-party librariesβ€”including HTTP frameworksβ€”the system reduces external dependencies and increases robustness. Any component can be replaced or modified without disrupting the integrity of other application layers.

🌟 Features

Core Features

  • Message Management
    • Create and queue messages with validation
    • Track message status (PENDING β†’ SENT)
    • Phone number validation with international format
    • Message content validation (10-255 characters)

Technical Features

  • High Performance
    • Asynchronous message processing
    • Redis caching for sent message info
    • Kafka-based message queue
    • PostgreSQL for persistent storage

Integration Features

  • Real-time CDC with Debezium
    • Capture database changes in real-time
    • Automatic status updates via Kafka
    • Event-driven architecture

Operational Features

  • Monitoring & Management
    • Health check endpoints
    • Structured JSON logging
    • Correlation ID tracking

πŸ—οΈ System Architecture

Clean Architecture Implementation

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Presentation Layer                β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚   β”‚  REST API   β”‚    β”‚   Jobs   β”‚    β”‚ Kafka   β”‚    β”‚
β”‚   β”‚  Handlers   β”‚    β”‚ Processorβ”‚    β”‚Consumer β”‚    β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                  Application Layer                  β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚   β”‚  Message    β”‚    β”‚ Business β”‚    β”‚ Service β”‚    β”‚
β”‚   β”‚  Services   β”‚    β”‚  Logic   β”‚    β”‚ Layer   β”‚    β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Domain Layer                     β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚   β”‚  Entities   β”‚    β”‚Repositoryβ”‚    β”‚ Domain  β”‚    β”‚
β”‚   β”‚  & Models   β”‚    β”‚Interface β”‚    β”‚Services β”‚    β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                Infrastructure Layer                 β”‚
β”‚β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€-─┐ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚β”‚Postgresβ”‚ β”‚Redisβ”‚ β”‚ Kafka  β”‚ β”‚HTTP  β”‚ β”‚ Logger   β”‚  β”‚
β”‚β”‚  DB    β”‚ β”‚Cacheβ”‚ β”‚ Queue  β”‚ β”‚Clientβ”‚ β”‚& Monitor β”‚  β”‚
β”‚β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ └─────-β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

# Check Go version (requires 1.24+)
go version

# Check Docker version
docker --version
docker-compose --version

Detailed Installation Steps

  1. Clone and Setup

    # Clone repository
    git clone https://github.com/nemre/messager.git
    cd messager
    
    # Create environment file
    cp .env.example .env
    
    # Initialize Go modules
    go mod tidy
  2. Configure Environment

    # Edit .env file with your settings
    nano .env
    
    # Required settings:
    # - Server configuration (SERVER_*)
    # - Database credentials (POSTGRESQL_*)
    # - Redis settings (REDIS_*)
    # - Kafka configuration (KAFKA_*)
    # - Client settings (CLIENT_*)
  3. Start Services

    # Start all services
    docker-compose up -d
    
    # Verify services are running
    docker-compose ps
    
    # Check logs
    docker-compose logs -f
  4. Verify Installation

    # Check API health
    curl http://localhost:2025/health
    
    # Should return:
    # {"status":"green"}

πŸ“š API Reference

Swagger

http://localhost:2025/swagger/index.html

Create Message

curl -X POST http://localhost:2025/messages \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Your message content",
    "phone": "+905321234567"
  }'

List Messages

# Get PENDING messages
curl http://localhost:2025/messages?status=PENDING

# Get SENT messages
curl http://localhost:2025/messages?status=SENT

Manage Message Processing

# Start processing
curl -X POST http://localhost:2025/messages/jobs

# Stop processing
curl -X DELETE http://localhost:2025/messages/jobs

πŸ”§ Configuration

Environment Variables

# Server Configuration
SERVER_HOST=0.0.0.0
SERVER_PORT=2025
SERVER_ID_HEADER=X-Correlation-ID

# PostgreSQL Configuration
POSTGRESQL_HOST=postgres
POSTGRESQL_PORT=5432
POSTGRESQL_USER=messager
POSTGRESQL_PASSWORD=messager
POSTGRESQL_NAME=messager

# Redis Configuration
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=0

# Job Configuration
JOB_INTERVAL=2m

# Kafka Configuration
KAFKA_BROKERS=kafka:9092
KAFKA_TOPIC=messager.public.messages
KAFKA_GROUP_ID=messager

# Client Configuration
CLIENT_URL=https://api.example.com
CLIENT_TOKEN=your-token
CLIENT_TIMEOUT=5s

πŸ’» Development

Project Structure

messager/
β”œβ”€β”€ application/                 # Application Services
β”‚   └── service/
β”‚       └── message/            # Message Service Implementation
β”œβ”€β”€ domain/                     # Domain Layer
β”‚   └── message/               
β”‚       β”œβ”€β”€ entity.go          # Message Entity & Validation
β”‚       β”œβ”€β”€ repository.go      # Repository Interface
β”‚       └── service.go         # Service Interface
β”œβ”€β”€ infrastructure/            # Infrastructure Layer
β”‚   β”œβ”€β”€ client/               # HTTP Client
β”‚   β”œβ”€β”€ config/               # Configuration
β”‚   β”œβ”€β”€ database/             # Database Implementations
β”‚   β”œβ”€β”€ logger/               # Structured Logger
β”‚   β”œβ”€β”€ persistence/          # Repository Implementations
β”‚   └── server/               # HTTP Server
└── presentation/             # Presentation Layer
    β”œβ”€β”€ consumer/             # Kafka Consumers
    β”œβ”€β”€ handler/              # HTTP Handlers
    └── job/                  # Background Jobs

Logging

  • Structured JSON logs
  • Log levels: DEBUG, INFO, WARNING, ERROR, FATAL
  • Correlation ID tracking
  • Separate stdout/stderr streams

πŸ” Security

Security Features

  • TLS support
  • Token-based authentication
  • Input validation
  • Rate limiting
  • Secure defaults

Security Policy

See SECURITY.md for:

  • Supported versions
  • Reporting vulnerabilities
  • Security update policy

πŸ‘₯ Contributing

We welcome contributions! Please see:

Development Process

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

πŸ“ License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

πŸ™ Acknowledgments

Technologies

Libraries