How byte2code/telecom-subscription-service works
1. Overall shape
This is a single Spring Boot 2.7 service, not a multi-module system. The SubscriptionServiceApplication bootstraps one deployable API that owns user, account, and subscription workflows, plus outbound integrations to billing and support systems.
2. API boundary
The ingress layer is split into three controllers: UserController, AccountController, and SubscriptionController. They expose REST endpoints under /api/user, /account, and /api/subscription, returning lightweight DTOs and ResponseMessage objects rather than entities.
3. Domain model
Persistence is centered on JPA entities in model/: User, Account, Subscription, and SubscriptionStatus. The important domain boundary is the subscription lifecycle, which is explicit rather than CRUD-only: REQUESTED, ACTIVE, SUSPENDED, CANCELLED, and PAYMENT_FAILED.
4. Service layer
Business logic lives in service/ with UserService, AccountService, and SubscriptionService. These services coordinate repository access, map request/response DTOs, enforce lifecycle transitions, and trigger downstream actions such as invoice creation or support escalation.
5. Persistence layer
repository/ contains Spring Data JPA repositories for the three core entities. This service owns its own MySQL-backed data model, and the architecture implies transactional consistency within the service boundary for user/account/subscription state changes.
6. DTO and contract separation
The dto/ package holds request/response shapes for internal API contracts, while BillingDtos/ and SupportDtos/ define outbound payloads for other services. This separation is important: local REST APIs and external service contracts are intentionally decoupled from JPA entities.
7. Outbound service integration
feign/BillingService and feign/SupportService are the declarative HTTP clients to downstream services. Billing is used for invoice/payment-related flows; support is used for ticket retrieval and escalation-related behavior. These are the main synchronous integration points outside the service boundary.
8. Messaging and async billing flow
The messaging/ package is the async billing subsystem. BillingEventPublisher emits billing events, BillingEventListener consumes them, BillingRabbitConfig defines RabbitMQ wiring, and BillingDeadLetterListener handles poisoned messages. The event model (BillingEvent, BillingEventType) drives state changes like subscription creation, invoice requests, and payment failure handling.
9. Retry and dead-letter boundary
Messaging is designed for failure isolation: billing events are retried, then routed to a dead-letter exchange/queue if they keep failing. This means the event pipeline is a separate reliability boundary from the synchronous REST path.
10. Resilience boundary
The README indicates Resilience4j is used around support-ticket lookup, with circuit breaker, retry, timeout, and fallback behavior. Architecturally, this means the user-facing API can survive support-service degradation without taking down the whole service.
11. External infrastructure
The service depends on Eureka for registration/discovery, RabbitMQ for billing events, and MySQL for persistence. Those are not just libraries; they are runtime dependencies that shape deployment and data flow.
12. End-to-end subscription flow
The key business flow is: a subscription is created in REQUESTED, a billing event is published, billing success promotes it to ACTIVE, and failures can move it to PAYMENT_FAILED and trigger support escalation. Separate endpoints then allow explicit lifecycle transitions such as suspend, activate, and cancel.
13. Test coverage
Tests are focused on the two risky subsystems: messaging and service logic. The presence of BillingEventListenerTest, BillingEventPublisherTest, BillingRabbitConfigTest, plus SubscriptionServiceTest and UserServiceTest, suggests the architecture relies on isolated verification of async flow and domain rules.
14. Diagramming takeaway
For an architecture diagram, draw one Spring Boot service with three REST controllers on the left, JPA repositories/MySQL beneath, Feign-based billing and support clients on the right, and RabbitMQ event handling as a separate async lane. The main cross-cutting concerns are lifecycle state management, resilience around support calls, and retry/DLQ handling for billing events.
Main entry points: SubscriptionService.java Subscription service · BillingEventListener.java Event listener · SubscriptionServiceApplication.java Boot app · UserController.java User API
Components 24
Application
Spring Boot entrypoint and runtime configuration
- Boot app · Application entrypoint for the subscription service
src/main/java/Telecom/SubscriptionService/SubscriptionServiceApplication.java
API Layer
REST controllers and local DTO contracts
- User API · User-facing REST endpoints
src/main/java/Telecom/SubscriptionService/controller/UserController.java - Account API · Account management REST endpoints
src/main/java/Telecom/SubscriptionService/controller/AccountController.java - Subscription API · Subscription lifecycle REST endpoints
src/main/java/Telecom/SubscriptionService/controller/SubscriptionController.java - API DTOs · Local request and response contracts for the REST API
src/main/java/Telecom/SubscriptionService/dto
Core Domain
Entities, repositories, and services that own subscription state
- User · Persisted user aggregate
src/main/java/Telecom/SubscriptionService/model/User.java - Account · Persisted account aggregate
src/main/java/Telecom/SubscriptionService/model/Account.java - Subscription · Persisted subscription aggregate and lifecycle state
src/main/java/Telecom/SubscriptionService/model/Subscription.java - Status enum · Subscription states such as REQUESTED, ACTIVE, SUSPENDED, CANCELLED, and PAYMENT_FAILED
src/main/java/Telecom/SubscriptionService/model/SubscriptionStatus.java - User repo · Persistence access for users
src/main/java/Telecom/SubscriptionService/repository/UserRepository.java - Account repo · Persistence access for accounts
src/main/java/Telecom/SubscriptionService/repository/AccountRepository.java - Subscription repo · Persistence access for subscriptions
src/main/java/Telecom/SubscriptionService/repository/SubscriptionRepository.java - User service · Coordinates user workflows
src/main/java/Telecom/SubscriptionService/service/UserService.java - Account service · Coordinates account workflows
src/main/java/Telecom/SubscriptionService/service/AccountService.java - Subscription service · Coordinates subscription lifecycle, billing, and escalation rules
src/main/java/Telecom/SubscriptionService/service/SubscriptionService.java
Outbound Integrations
Feign clients and external service payloads
- Billing client · Synchronous billing integration
src/main/java/Telecom/SubscriptionService/feign/BillingService.java - Support client · Synchronous support integration
src/main/java/Telecom/SubscriptionService/feign/SupportService.java - Billing DTOs · Outbound invoice payload shape
src/main/java/Telecom/SubscriptionService/BillingDtos/InvoiceDto.java - Support DTOs · Outbound ticket payload shape
src/main/java/Telecom/SubscriptionService/SupportDtos/TicketDto.java
Async Billing
RabbitMQ event flow, retries, and dead-letter handling
- Billing event · Event model and event type for async billing flows
src/main/java/Telecom/SubscriptionService/messaging/BillingEvent.java - Event publisher · Publishes billing events
src/main/java/Telecom/SubscriptionService/messaging/BillingEventPublisher.java - Event listener · Consumes billing events and advances subscription outcomes
src/main/java/Telecom/SubscriptionService/messaging/BillingEventListener.java - Dead-letter · Handles poison messages after retries fail
src/main/java/Telecom/SubscriptionService/messaging/BillingDeadLetterListener.java - Rabbit config · RabbitMQ topology and wiring
src/main/java/Telecom/SubscriptionService/messaging/BillingRabbitConfig.java
Connections 30
- Boot app → User API: starts · Bootstraps REST ingress
- Boot app → Account API: starts · Bootstraps REST ingress
- Boot app → Subscription API: starts · Bootstraps REST ingress
- User API → API DTOs: uses · Maps requests and responses
- Account API → API DTOs: uses · Maps requests and responses
- Subscription API → API DTOs: uses · Maps requests and responses
- User API → User service: calls · Delegates user workflows
- Account API → Account service: calls · Delegates account workflows
- Subscription API → Subscription service: calls · Delegates subscription workflows
- User service → User repo: reads/writes · Persists users
- Account service → Account repo: reads/writes · Persists accounts
- Subscription service → Subscription repo: reads/writes · Persists subscriptions
- Subscription service → Status enum: enforces · Applies lifecycle transitions
- Subscription service → Billing client: requests · Triggers billing/invoice interactions
- Subscription service → Support client: escalates · Raises support tickets or fetches support data
- User service → User: uses · Operates on user entities
- Account service → Account: uses · Operates on account entities
- Subscription service → Subscription: uses · Operates on subscription entities
- Billing client → Billing DTOs: formats · Uses outbound billing payloads
- Support client → Support DTOs: formats · Uses outbound support payloads
- Subscription service → Event publisher: publishes · Emits async billing events
- Event publisher → Billing event: creates · Builds billing event messages
- Rabbit config → Event publisher: wires · Declares RabbitMQ publishing setup
- Rabbit config → Event listener: wires · Declares RabbitMQ consumption setup
- Event listener → Billing event: consumes · Handles billing events
- Event listener → Subscription service: updates · Advances subscription state from async outcomes
- Event listener → Billing client: invokes · May call billing during processing
- Dead-letter → Billing event: handles · Processes failed billing messages
- Event listener → Dead-letter: routes on failure · Sends exhausted messages to dead-letter handling
- Subscription service → Support client: fallback/escalate · Uses resilient support lookups and escalation paths