Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ go.work.sum

# Postgres data or dumps
*.sql
*.dump
*go.sum
!**/migrations/*.sql
*.dump
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.PHONY: up down build logs ps clean test tidy help

# Default target
all: up

# Docker Compose Commands
up: ## Start all services with Docker Compose (builds if necessary)
docker compose up --build -d

down: ## Stop and remove all containers
docker compose down

build: ## Rebuild services without starting them
docker compose build

logs: ## Follow logs for all services
docker compose logs -f

ps: ## List running containers
docker compose ps

clean: ## Stop containers and remove volumes/orphans
docker compose down --volumes --remove-orphans

postgres: ## Connect to the main database
docker compose exec hcaas_db psql -U hcaas_user -d hcaas_db

# Go Development Commands
test: ## Run tests for all services
@echo "Running tests for all services..."
cd services/url && go test -v ./...
cd services/auth && go test -v ./...
cd services/notification && go test -v ./...

tidy: ## Run go mod tidy for all services
@echo "Tidying modules..."
cd services/url && go mod tidy
cd services/auth && go mod tidy
cd services/notification && go mod tidy

# Database Migrations

migrate-auth-up: ## Run up migrations for auth service
cd services/auth && go run cmd/migrate/main.go up

migrate-auth-down: ## Run down migrations for auth service
cd services/auth && go run cmd/migrate/main.go down

migrate-auth-create: ## Create a new migration file. Usage: make migrate-auth-create name=migration_name
@if [ -z "$(name)" ]; then echo "Error: name argument is required"; exit 1; fi
cd services/auth && go run cmd/migrate/main.go create $(name)

migrate-notification-up: ## Run up migrations for notification service
cd services/notification && go run cmd/migrate/main.go up

migrate-notification-down: ## Run down migrations for notification service
cd services/notification && go run cmd/migrate/main.go down

migrate-notification-create: ## Create a new migration file. Usage: make migrate-notification-create name=migration_name
@if [ -z "$(name)" ]; then echo "Error: name argument is required"; exit 1; fi
cd services/notification && go run cmd/migrate/main.go create $(name)

help: ## Show this help message
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ This modular design ensures testability and scalability.
*Senior Software Engineer*
Kolkata, India
Passionate about microservices, Go, and scalable system design.
[LinkedIn](https://www.linkedin.com/in/samiul-sk/) | [GitHub](https://github.com/samims)
[LinkedIn](https://www.linkedin.com/in/samiul-sk/) | [GitHub](https://github.com/kernelshard)

---

Expand Down
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
environment:
OTEL_EXPORTER_OTLP_ENDPOINT: hcaas_jaeger_all_in_one:4317
OTEL_SERVICE_NAME: hcaas_auth_service
DB_URL: postgres://hcaas_auth_user:hcaas_auth_pass@hcaas_auth_db:5432/hcaas_auth_db?sslmode=disable
networks:
- hcaas_backend_network

Expand Down Expand Up @@ -128,7 +129,7 @@ services:
- "5433:5432"
volumes:
- hcaas_auth_db_data:/var/lib/postgresql/data
- ./infra/postgres/auth_init.sql:/docker-entrypoint-initdb.d/init.sql

networks:
- hcaas_backend_network

Expand All @@ -147,18 +148,19 @@ services:
retries: 5
start_period: 30s
volumes:

- hcaas_notif_data:/var/lib/postgresql/data
- ./infra/postgres/notif.sql:/docker-entrypoint-initdb.d/init.sql
ports:
- "5434:5432"
networks:
- hcaas_net

hcaas_zookeeper:
image: bitnami/zookeeper:3.8
image: confluentinc/cp-zookeeper:7.5.0
container_name: hcaas_zookeeper
environment:
ALLOW_ANONYMOUS_LOGIN: "yes"
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"
networks:
Expand Down
2 changes: 1 addition & 1 deletion services/auth/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Database Configuration
DB_URL=postgres://hcaas_auth_user:hcaas_auth_pass@hcaas_auth_db:5432/hcaas_auth_db
DB_URL=postgres://hcaas_auth_user:hcaas_auth_pass@localhost:5433/hcaas_auth_db?sslmode=disable

OTEL_EXPORTER_OTLP_ENDPOINT=hcaas_jaeger_all_in_one:4317
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
Expand Down
2 changes: 1 addition & 1 deletion services/auth/cmd/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/kernelshard/otelkit"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/samims/otelkit"

"github.com/kernelshard/hcaas/services/auth/internal/config"
"github.com/kernelshard/hcaas/services/auth/internal/handler"
Expand Down
75 changes: 75 additions & 0 deletions services/auth/cmd/migrate/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"log"
"os"

"fmt"
"path/filepath"
"time"

"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/joho/godotenv"
)

func main() {
if err := godotenv.Load(); err != nil {
log.Println("No .env file found")
}

cmd := os.Args[len(os.Args)-1]

// Handle create command separately as it doesn't need DB connection
if len(os.Args) > 2 && os.Args[1] == "create" {
name := os.Args[2]
if name == "" {
log.Fatal("migration name is required")
}
// timestamp format: YYYYMMDDHHMMSS
timestamp := time.Now().Format("20060102150405")
base := fmt.Sprintf("%s_%s", timestamp, name)

up := filepath.Join("migrations", base+".up.sql")
down := filepath.Join("migrations", base+".down.sql")

if err := os.WriteFile(up, []byte{}, 0644); err != nil {
log.Fatal(err)
}
if err := os.WriteFile(down, []byte{}, 0644); err != nil {
log.Fatal(err)
}

log.Printf("Created migration files:\n%s\n%s", up, down)
return
}

dbURL := os.Getenv("DB_URL")
if dbURL == "" {
log.Fatal("DB_URL environment variable is required")
}

m, err := migrate.New(
"file://migrations",
dbURL,
)
if err != nil {
log.Fatal(err)
}

switch cmd {
case "up":
if err := m.Up(); err != nil && err != migrate.ErrNoChange {
log.Fatal(err)
}
log.Println("Migration up done")
case "down":
if err := m.Down(); err != nil && err != migrate.ErrNoChange {
log.Fatal(err)
}
log.Println("Migration down done")
default:
log.Fatal("unknown command, verify Makefile")
}
}
28 changes: 15 additions & 13 deletions services/auth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@ go 1.24.4
require (
github.com/go-chi/chi/v5 v5.2.2
github.com/golang-jwt/jwt/v5 v5.3.0
github.com/golang-migrate/migrate/v4 v4.19.1
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.7.5
github.com/joho/godotenv v1.5.1
github.com/kernelshard/otelkit v0.4.1
github.com/prometheus/client_golang v1.23.0
github.com/samims/otelkit v0.3.2
github.com/stretchr/testify v1.11.0
go.opentelemetry.io/otel v1.37.0
go.opentelemetry.io/otel/trace v1.37.0
golang.org/x/crypto v0.41.0
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/otel v1.38.0
go.opentelemetry.io/otel/trace v1.38.0
golang.org/x/crypto v0.45.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.65.0 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
Expand All @@ -40,13 +42,13 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.37.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 // indirect
go.opentelemetry.io/otel/metric v1.37.0 // indirect
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
go.opentelemetry.io/otel/metric v1.38.0 // indirect
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250818200422-3122310a409c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250818200422-3122310a409c // indirect
google.golang.org/grpc v1.75.0 // indirect
Expand Down
Loading
Loading