How rakeshkumargupt/email-microservice works
1. What this repository is
- A single Spring Boot 2.7 microservice focused on email delivery and email-status tracking.
- It has two ingestion paths: a synchronous REST API and an asynchronous RabbitMQ consumer.
- Persistent tracking is done in PostgreSQL via JPA/Hibernate.
2. Primary runtime boundaries
- HTTP boundary: exposes email-related REST endpoints through EmailController.
- Messaging boundary: consumes messages from a RabbitMQ queue through EmailConsumer.
- Persistence boundary: writes and reads email logs/status via EmailRepository.
- External delivery boundary: sends the actual email through Java Mail, typically using Gmail SMTP as described in the README.
3. Core domain model
- EmailEntity is the persisted domain record for an email transaction.
- EmailDto is the transport object used for inbound/outbound API and queue payloads.
- StatusEmail represents the delivery state, such as sent/failed/tracked status.
- The project keeps transport and persistence concerns separate, which is important for diagramming data flow.
4. Request-driven flow
- A client posts email data to the REST API.
- EmailController passes the request into EmailService.
- EmailServiceImpl performs the business logic, sends the email, and stores the final status in PostgreSQL.
- The response returns the email record, including ID, timestamp, and status.
5. Queue-driven asynchronous flow
- RabbitMQ delivers messages from the configured email queue to EmailConsumer.
- The consumer converts the message payload into EmailEntity or a similar internal model.
- It delegates to the same EmailService used by the REST path.
- This means both sync and async entry points converge on the same business/persistence layer.
6. Business/service layer
- EmailService is the main abstraction for email handling.
- EmailServiceImpl centralizes sending logic and status updates.
- This layer is the key orchestration point between message/HTTP input, mail sending, and database logging.
7. Persistence layer
- EmailRepository is the JPA repository for email log records.
- PostgreSQL is the system of record for historical email data and status lookups.
- The API supports retrieving all logs and a single email by ID, indicating read access is driven from the database, not from transient message state.
8. Messaging configuration
- RabbitMQConfig defines the queue/binding/infrastructure needed for the RabbitMQ integration.
- The README indicates a queue named email-queue and a CloudAMQP-hosted broker.
- This is the main infrastructure dependency for asynchronous processing.
9. External systems
- RabbitMQ / CloudAMQP: message ingestion and decoupled asynchronous processing.
- PostgreSQL: durable storage for email audit/status records.
- Gmail / Java Mail API: actual email delivery channel.
- These external services are not just libraries; they define the service’s operational architecture.
10. Packaging and execution
- The app is packaged as a WAR with embedded Tomcat, so it runs as a self-contained JVM service.
- The README shows a servlet context path of /email-service, which is part of the public API boundary.
- Build and runtime are Maven-based, with the Maven wrapper included in the repo.
11. API surface
- POST /emails creates/sends an email.
- GET /emails returns paginated email logs.
- GET /emails/{id} returns status/details for one email.
- Swagger UI is enabled for API inspection, which helps consumers but does not change the core runtime flow.
12. Repository shape
- The code is organized in a classic layered Spring structure: controller, consumer, service, repository, entity, dto, config.
- There is no separate frontend or multiple microservices in this repository; it is a single deployable backend service with one domain focus.
- The tests are minimal and mainly validate application startup.
Main entry points: EmailServiceImpl.java Email service impl · EmailController.java Email API · EmailConsumer.java Email consumer · EmailService.java Email service
Components 13
Entry points
HTTP and messaging boundaries that accept incoming email requests.
- Email app · Single deployable email delivery and status-tracking microservice.
src/main/java/com/practice/email/emailmicroservice/EmailMicroserviceApplication.java - Email API · HTTP boundary exposing email create and lookup endpoints.
src/main/java/com/practice/email/emailmicroservice/controller/EmailController.java - Email consumer · Asynchronous entry point that receives email messages from the queue.
src/main/java/com/practice/email/emailmicroservice/consumer/EmailConsumer.java
Core service
Orchestration and business logic for sending and tracking emails.
- Email service · Main abstraction for email handling used by both entry points.
src/main/java/com/practice/email/emailmicroservice/service/EmailService.java - Email service impl · Coordinates mail sending, status updates, and persistence.
src/main/java/com/practice/email/emailmicroservice/service/impl/EmailServiceImpl.java - Email repo · Persistence gateway for reading and writing email log records.
src/main/java/com/practice/email/emailmicroservice/repository/EmailRepository.java
Data model
Transport and persistence models used by the service.
- Email DTO · Inbound and outbound request payload for API and queue flows.
src/main/java/com/practice/email/emailmicroservice/dto/EmailDto.java - Status · Represents delivery state such as sent, failed, or tracked.
src/main/java/com/practice/email/emailmicroservice/dto/StatusEmail.java - Email entity · Persisted email transaction record stored in PostgreSQL.
src/main/java/com/practice/email/emailmicroservice/entity/EmailEntity.java
Infrastructure
External systems and configuration supporting delivery and storage.
- Rabbit config · Defines the queue and binding used for RabbitMQ integration.
src/main/java/com/practice/email/emailmicroservice/config/RabbitMQConfig.java - Mail sender · External email delivery channel, typically Gmail SMTP.
- PostgreSQL · System of record for historical email records and status lookups.
- RabbitMQ · Queue-based ingress for asynchronous email processing.
Connections 16
- Email app → Email API: hosts · Application exposes the REST controller as part of the HTTP runtime.
- Email app → Email consumer: hosts · Application also runs the RabbitMQ consumer.
- Email API → Email service: calls · Controller delegates request handling to the service abstraction.
- Email consumer → Email service: delegates · Consumer forwards queue messages into the same service layer.
- Email service → Email service impl: implemented by · Concrete business orchestration lives in the service implementation.
- Email service impl → Mail sender: sends via · Service implementation performs the actual email delivery.
- Email service impl → Email repo: persists through · Service implementation stores and retrieves email records.
- Email repo → PostgreSQL: stores in · Repository writes to PostgreSQL as the durable system of record.
- Email service impl → Email entity: reads/writes · Business logic operates on persisted email entities.
- Email service impl → Email DTO: maps · Service converts transport payloads into internal handling objects.
- Email service impl → Status: updates · Service assigns final delivery status to each email record.
- Email consumer → RabbitMQ: consumes from · Consumer receives messages from RabbitMQ.
- Rabbit config → RabbitMQ: configures · Messaging configuration defines broker queue and binding setup.
- Email API → Email DTO: accepts · REST API accepts email DTOs as request payloads.
- Email API → Email entity: returns · API responses expose the stored email record and status.
- Email consumer → Email entity: converts to · Queue payloads are translated into an internal email record.