How ssaavedraa/phoenix works
Project type and purpose
• Phoenix is a single‐purpose microservice written in Go. It acts as a Kafka consumer that transforms incoming messages into email sends using templating and localization.
• Its primary goal is reliable, high‐throughput email delivery by reading from a Kafka topic, formatting content, and handing it off to an email‐sending implementation.
File structure
• cmd/main.go: application entrypoint that boots the service.
• config/config.go: centralizes Kafka and environment configuration.
• consumer/kafka_consumer.go: logic to connect to Kafka, subscribe, and consume messages.
• factories/email_factory.go & _Impl.go: abstract factory + implementation that builds and sends emails.
• i18n/: JSON files for localization (English, Spanish) per template.
• templates/: HTML templates keyed by use case (user_invite_mvp).
• .air.toml, Dockerfile, .env.example: dev tooling, containerization, environment variable management.
README for additional insights
• Emphasis on Golang’s concurrency for throughput.
• Mentions an API, but code shows a Kafka‐based consumer pattern—no HTTP server here.
• Aims for security, reliability, and scalability.
a. Main components
• Kafka Cluster (external service)
• Phoenix Service (containerized microservice)
– Configuration Loader
– Kafka Consumer
– Message Handler / Business Logic
– Email Factory (interface + implementation)
– Template Engine + i18n Loader
• External Email Provider (SMTP or third‐party API)
• Optional: Metrics & Logging system
b. Relationships & interactions
1. Phoenix startup reads config (config module) from environment or .env.
2. Kafka Consumer connects to Kafka cluster and subscribes to topic(s).
3. On message receive, Consumer passes raw payload to Message Handler.
4. Handler invokes Email Factory; factory loads appropriate template from templates/, merges i18n JSON, builds email content.
5. Email Factory Impl calls External Email Provider over SMTP/HTTP.
6. Success/failure is logged; metrics emitted to monitoring.
c. Architectural patterns & principles
– Single‐responsibility: each package (config, consumer, factories) handles one concern.
– Factory pattern for pluggable email implementations.
– Concurrency: consumer poll loop with worker pools (implied by Go’s goroutines).
– Containerizable: Dockerfile for immutable deployments.
d. Key technologies & libraries
– Golang runtime & standard library
– Segmentio/kafka-go (or similar) for Kafka client
– html/template for rendering
– JSON for i18n
– Docker for containerization
Detail without over‐partitioning
• Every submodule shown in the file tree for clarity.
• Don’t stop at “backend” vs. “frontend”—instead, break backend into config, consumer, handler, factory, i18n, templates.