How nurashi/auth_grpc works
Project type and purpose
• This is a standalone authentication microservice implemented in Go, exposing a gRPC API.
• It follows clean-architecture principles and integrates with PostgreSQL, Redis, and Apache Kafka for persistence, caching, and event-driven messaging.
File structure
• Top-level “client” folder holds a sample gRPC client.
• “cmd/” contains the main entrypoint for the service.
• “internal/” implements the core layers:
• cache (Redis adapter)
• config loader
• db (Postgres adapter)
• handler (repository abstractions)
• models (domain objects)
• server (gRPC server & interceptors)
• service (business logic: auth, JWT)
• “proto/” stores Protocol Buffer definitions and generated Go stubs.
• “kafka-local/” provides local Kafka producer/consumer runners for testing.
• “config/” holds YAML configuration.
• Shared utilities (logger, generic helpers) under “shared/”.
• Docker+Compose files orchestrate Postgres, Redis, Kafka, Zookeeper, and the microservice itself.
Extract architecture insights from README
• gRPC transport layer with three RPC methods: RegisterUser, LoginUser, GetUserByID.
• Business logic publishes user-created and user-login events to Kafka.
• A consumer listens to these topics, populating Redis cache.
• Read-through cache strategy: on GetUserByID, read Redis first, fall back to Postgres then repopulate cache.
Main components
a. Client (gRPC test client)
b. API Layer: gRPC Server + Interceptors
c. Application / Service Layer: auth service, JWT generator
d. Persistence:
• PostgreSQL database (persistent user store)
• Redis cache (high-speed user lookup by ID/email)
e. Messaging:
• Kafka Broker + Zookeeper
• Producer inside service for user-created & login events
• Consumer (background process) updating Redis
f. Configuration & Utilities: config loader, custom logger
Relationships & data flow
• Client → gRPC Server: calls RegisterUser/LoginUser/GetUserByID
• Server → Service Layer: validation, hashing or credential check
• Service → DB: Create or read User record
• Service → Kafka Producer: emit “user-created” or “user-login” events
• Kafka Broker → Consumer: subscribe & consume events
• Consumer → Redis: cache user data
• GetUserByID: 1) check Redis; 2) on miss, query Postgres; 3) update Redis
Architectural patterns
• Clean (hexagonal) architecture:
• Domain models (internal/models)
• Ports & adapters (internal/handler + internal/db/cache)
• Framework boundary (gRPC server in internal/server)
• Event-driven integration via Kafka topics
• Read-through caching with Redis