Skip to content

Reg-Kris/pyairtable-notification-service-go

Repository files navigation

notification-service

Multi-channel notification service for email, SMS, push, and in-app notifications

Overview

notification-service is a Go microservice built with Fiber v3, providing a robust foundation for scalable applications with built-in monitoring, authentication, and cloud-native deployment capabilities.

Features

  • High Performance: Built with Fiber v3 for fast HTTP handling
  • Database Integration: PostgreSQL with GORM ORM
  • Caching: Redis for session management and caching
  • Authentication: JWT-based authentication middleware
  • Monitoring: Prometheus metrics and health checks
  • Logging: Structured logging with configurable levels
  • Container Ready: Docker multi-stage builds
  • Kubernetes Native: Complete K8s manifests with HPA
  • CI/CD Ready: GitHub Actions workflows
  • Security: Built-in security middleware and best practices

Quick Start

Prerequisites

  • Go 1.21+
  • Docker & Docker Compose
  • PostgreSQL 15+
  • Redis 7+

Local Development

  1. Clone and setup:

    git clone <repository-url>
    cd notificationservice
    cp .env.example .env
  2. Start dependencies:

    make dev
  3. Run the service:

    make run

The service will be available at http://localhost:8083

Using Docker

# Build and run with Docker Compose
make docker-compose-up

# Or build and run individually
make docker-build
make docker-run

API Endpoints

Method Endpoint Description Auth Required
GET /health Health check No
GET /metrics Prometheus metrics No
GET /api/v1/ping Service ping No
GET /api/v1/protected Protected endpoint example Yes

Authentication

Protected endpoints require a valid JWT token in the Authorization header:

curl -H "Authorization: Bearer <jwt-token>" \
     http://localhost:8083/api/v1/protected

Configuration

Configuration is managed through environment variables:

Variable Description Default
PORT Server port 8083
DB_HOST Database host localhost
DB_PORT Database port 5432
DB_NAME Database name notification_service_db
REDIS_HOST Redis host localhost
REDIS_PORT Redis port 6379
JWT_SECRET JWT signing secret your-secret-key
LOG_LEVEL Logging level info

See .env.example for a complete list.

Development

Available Commands

make help          # Show all available commands
make deps          # Download dependencies
make build         # Build the application
make run           # Run the application
make test          # Run tests
make test-coverage # Run tests with coverage
make bench         # Run benchmarks
make lint          # Run linter
make format        # Format code
make clean         # Clean build artifacts

Project Structure

notificationservice/
├── cmd/notification-service/           # Application entrypoint
├── internal/                      # Private application code
│   ├── config/                   # Configuration management
│   ├── handlers/                 # HTTP handlers
│   ├── services/                 # Business logic
│   ├── repositories/             # Data access layer
│   ├── middleware/               # Custom middleware
│   └── models/                   # Data models
├── pkg/                          # Public packages
│   ├── database/                 # Database utilities
│   ├── redis/                    # Redis utilities
│   ├── logger/                   # Logging utilities
│   └── metrics/                  # Metrics utilities
├── test/                         # Test files
├── deployments/                  # Deployment configs
│   ├── docker/                   # Docker configs
│   └── k8s/                      # Kubernetes manifests
└── .github/workflows/            # CI/CD workflows

Testing

# Run all tests
make test

# Run with coverage
make test-coverage

# Run only unit tests
go test ./test/unit/...

# Run only integration tests
go test ./test/integration/...

# Run benchmarks
make bench

Adding New Features

  1. Add models in internal/models/
  2. Create repositories in internal/repositories/
  3. Implement services in internal/services/
  4. Add handlers in internal/handlers/
  5. Register routes in cmd/notification-service/main.go
  6. Add tests in test/unit/ and test/integration/

Deployment

Docker

# Build image
make docker-build

# Run container
make docker-run

Kubernetes

# Deploy to Kubernetes
kubectl apply -k deployments/k8s/

# Check deployment status
kubectl get pods -n notificationservice

Environment-specific Deployments

The service includes Kustomize configurations for different environments:

  • Development: Basic setup with minimal resources
  • Staging: Production-like setup with monitoring
  • Production: Full setup with HPA, ingress, and security policies

Monitoring

Health Checks

  • Liveness: GET /health
  • Readiness: GET /health (customize as needed)

Metrics

Prometheus metrics are available at /metrics:

  • HTTP request metrics (count, duration)
  • Database connection metrics
  • Redis connection metrics
  • Custom business metrics

Logging

Structured JSON logging with configurable levels:

{
  "time": "2024-01-01T12:00:00Z",
  "level": "INFO",
  "msg": "Server started",
  "port": "8083"
}

Security

  • JWT Authentication: Secure token-based auth
  • CORS: Configurable cross-origin policies
  • Rate Limiting: Built-in request rate limiting
  • Security Headers: Helmet middleware for security headers
  • Input Validation: Request validation and sanitization

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Code Standards

  • Follow Go best practices and conventions
  • Write tests for new features
  • Update documentation as needed
  • Run linter and formatter before submitting

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support and questions:


Generated with Go Microservice Template

About

Notification service for PyAirtable

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published