# byte2code/telecom-subscription-service architecture

> Architecture diagram of the GitHub repository byte2code/telecom-subscription-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/byte2code/telecom-subscription-service
- Repository: https://github.com/byte2code/telecom-subscription-service

## Overview

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: [`src/main/java/Telecom/SubscriptionService/service/SubscriptionService.java`](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/service/SubscriptionService.java) (Subscription service), [`src/main/java/Telecom/SubscriptionService/messaging/BillingEventListener.java`](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingEventListener.java) (Event listener), [`src/main/java/Telecom/SubscriptionService/SubscriptionServiceApplication.java`](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/SubscriptionServiceApplication.java) (Boot app), [`src/main/java/Telecom/SubscriptionService/controller/UserController.java`](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/controller/UserController.java) (User API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_app_main(("Boot app"))
end

subgraph group_api["API Layer"]
  node_controller_user["User API<br/>REST controller"]
  node_controller_account["Account API<br/>REST controller"]
  node_controller_subscription["Subscription API<br/>REST controller"]
  node_dto_local["API DTOs<br/>request/response DTOs"]
end

subgraph group_core["Core Domain"]
  node_model_user[("User<br/>JPA entity<br/>[User.java]")]
  node_model_account[("Account<br/>JPA entity<br/>[Account.java]")]
  node_model_subscription[("Subscription<br/>JPA entity<br/>[Subscription.java]")]
  node_model_status{{"Status enum<br/>lifecycle enum"}}
  node_repo_user["User repo<br/>Spring Data repo"]
  node_repo_account["Account repo<br/>Spring Data repo"]
  node_repo_subscription["Subscription repo<br/>Spring Data repo"]
  node_service_user["User service<br/>business service<br/>[UserService.java]"]
  node_service_account["Account service<br/>business service"]
  node_service_subscription["Subscription service<br/>business service"]
end

subgraph group_integrations["Outbound Integrations"]
  node_billing_client["Billing client<br/>Feign client"]
  node_support_client["Support client<br/>Feign client"]
  node_billing_dto["Billing DTOs<br/>external contract<br/>[InvoiceDto.java]"]
  node_support_dto["Support DTOs<br/>external contract<br/>[TicketDto.java]"]
end

subgraph group_async["Async Billing"]
  node_msg_event["Billing event<br/>domain event<br/>[BillingEvent.java]"]
  node_msg_publisher["Event publisher<br/>RabbitMQ publisher"]
  node_msg_listener["Event listener<br/>RabbitMQ consumer"]
  node_msg_dlq["Dead-letter<br/>DLQ handler"]
  node_msg_config["Rabbit config<br/>messaging config"]
end

node_app_main -->|"starts"| node_controller_user
node_app_main -->|"starts"| node_controller_account
node_app_main -->|"starts"| node_controller_subscription
node_controller_user -->|"uses"| node_dto_local
node_controller_account -->|"uses"| node_dto_local
node_controller_subscription -->|"uses"| node_dto_local
node_controller_user -->|"calls"| node_service_user
node_controller_account -->|"calls"| node_service_account
node_controller_subscription -->|"calls"| node_service_subscription
node_service_user -->|"reads/writes"| node_repo_user
node_service_account -->|"reads/writes"| node_repo_account
node_service_subscription -->|"reads/writes"| node_repo_subscription
node_service_subscription -->|"enforces"| node_model_status
node_service_subscription -->|"requests"| node_billing_client
node_service_subscription -->|"escalates"| node_support_client
node_service_user -->|"uses"| node_model_user
node_service_account -->|"uses"| node_model_account
node_service_subscription -->|"uses"| node_model_subscription
node_billing_client -->|"formats"| node_billing_dto
node_support_client -->|"formats"| node_support_dto
node_service_subscription -->|"publishes"| node_msg_publisher
node_msg_publisher -->|"creates"| node_msg_event
node_msg_config -->|"wires"| node_msg_publisher
node_msg_config -->|"wires"| node_msg_listener
node_msg_listener -->|"consumes"| node_msg_event
node_msg_listener -->|"updates"| node_service_subscription
node_msg_listener -->|"invokes"| node_billing_client
node_msg_dlq -->|"handles"| node_msg_event
node_msg_listener -->|"routes on failure"| node_msg_dlq
node_service_subscription -->|"fallback/escalate"| node_support_client

click node_app_main "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/SubscriptionServiceApplication.java"
click node_controller_user "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/controller/UserController.java"
click node_controller_account "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/controller/AccountController.java"
click node_controller_subscription "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/controller/SubscriptionController.java"
click node_dto_local "https://github.com/byte2code/telecom-subscription-service/tree/main/src/main/java/Telecom/SubscriptionService/dto"
click node_model_user "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/User.java"
click node_model_account "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/Account.java"
click node_model_subscription "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/Subscription.java"
click node_model_status "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/SubscriptionStatus.java"
click node_repo_user "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/repository/UserRepository.java"
click node_repo_account "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/repository/AccountRepository.java"
click node_repo_subscription "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/repository/SubscriptionRepository.java"
click node_service_user "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/service/UserService.java"
click node_service_account "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/service/AccountService.java"
click node_service_subscription "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/service/SubscriptionService.java"
click node_billing_client "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/feign/BillingService.java"
click node_support_client "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/feign/SupportService.java"
click node_billing_dto "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/BillingDtos/InvoiceDto.java"
click node_support_dto "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/SupportDtos/TicketDto.java"
click node_msg_event "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingEvent.java"
click node_msg_publisher "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingEventPublisher.java"
click node_msg_listener "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingEventListener.java"
click node_msg_dlq "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingDeadLetterListener.java"
click node_msg_config "https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingRabbitConfig.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_main toneBlue
class node_controller_user,node_controller_account,node_controller_subscription,node_dto_local toneAmber
class node_model_user,node_model_account,node_model_subscription,node_model_status,node_repo_user,node_repo_account,node_repo_subscription,node_service_user,node_service_account,node_service_subscription toneMint
class node_billing_client,node_support_client,node_billing_dto,node_support_dto toneRose
class node_msg_event,node_msg_publisher,node_msg_listener,node_msg_dlq,node_msg_config toneIndigo
```

## Components

### Application

Spring Boot entrypoint and runtime configuration

- [Boot app](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/SubscriptionServiceApplication.java): Spring 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](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/controller/UserController.java): REST controller · User-facing REST endpoints · `src/main/java/Telecom/SubscriptionService/controller/UserController.java`
- [Account API](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/controller/AccountController.java): REST controller · Account management REST endpoints · `src/main/java/Telecom/SubscriptionService/controller/AccountController.java`
- [Subscription API](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/controller/SubscriptionController.java): REST controller · Subscription lifecycle REST endpoints · `src/main/java/Telecom/SubscriptionService/controller/SubscriptionController.java`
- [API DTOs](https://github.com/byte2code/telecom-subscription-service/tree/main/src/main/java/Telecom/SubscriptionService/dto): request/response 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](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/User.java): JPA entity · Persisted user aggregate · `src/main/java/Telecom/SubscriptionService/model/User.java`
- [Account](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/Account.java): JPA entity · Persisted account aggregate · `src/main/java/Telecom/SubscriptionService/model/Account.java`
- [Subscription](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/Subscription.java): JPA entity · Persisted subscription aggregate and lifecycle state · `src/main/java/Telecom/SubscriptionService/model/Subscription.java`
- [Status enum](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/model/SubscriptionStatus.java): lifecycle enum · Subscription states such as REQUESTED, ACTIVE, SUSPENDED, CANCELLED, and PAYMENT_FAILED · `src/main/java/Telecom/SubscriptionService/model/SubscriptionStatus.java`
- [User repo](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/repository/UserRepository.java): Spring Data repo · Persistence access for users · `src/main/java/Telecom/SubscriptionService/repository/UserRepository.java`
- [Account repo](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/repository/AccountRepository.java): Spring Data repo · Persistence access for accounts · `src/main/java/Telecom/SubscriptionService/repository/AccountRepository.java`
- [Subscription repo](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/repository/SubscriptionRepository.java): Spring Data repo · Persistence access for subscriptions · `src/main/java/Telecom/SubscriptionService/repository/SubscriptionRepository.java`
- [User service](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/service/UserService.java): business service · Coordinates user workflows · `src/main/java/Telecom/SubscriptionService/service/UserService.java`
- [Account service](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/service/AccountService.java): business service · Coordinates account workflows · `src/main/java/Telecom/SubscriptionService/service/AccountService.java`
- [Subscription service](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/service/SubscriptionService.java): business 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](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/feign/BillingService.java): Feign client · Synchronous billing integration · `src/main/java/Telecom/SubscriptionService/feign/BillingService.java`
- [Support client](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/feign/SupportService.java): Feign client · Synchronous support integration · `src/main/java/Telecom/SubscriptionService/feign/SupportService.java`
- [Billing DTOs](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/BillingDtos/InvoiceDto.java): external contract · Outbound invoice payload shape · `src/main/java/Telecom/SubscriptionService/BillingDtos/InvoiceDto.java`
- [Support DTOs](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/SupportDtos/TicketDto.java): external contract · Outbound ticket payload shape · `src/main/java/Telecom/SubscriptionService/SupportDtos/TicketDto.java`

### Async Billing

RabbitMQ event flow, retries, and dead-letter handling

- [Billing event](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingEvent.java): domain event · Event model and event type for async billing flows · `src/main/java/Telecom/SubscriptionService/messaging/BillingEvent.java`
- [Event publisher](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingEventPublisher.java): RabbitMQ publisher · Publishes billing events · `src/main/java/Telecom/SubscriptionService/messaging/BillingEventPublisher.java`
- [Event listener](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingEventListener.java): RabbitMQ consumer · Consumes billing events and advances subscription outcomes · `src/main/java/Telecom/SubscriptionService/messaging/BillingEventListener.java`
- [Dead-letter](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingDeadLetterListener.java): DLQ handler · Handles poison messages after retries fail · `src/main/java/Telecom/SubscriptionService/messaging/BillingDeadLetterListener.java`
- [Rabbit config](https://github.com/byte2code/telecom-subscription-service/blob/main/src/main/java/Telecom/SubscriptionService/messaging/BillingRabbitConfig.java): messaging config · RabbitMQ topology and wiring · `src/main/java/Telecom/SubscriptionService/messaging/BillingRabbitConfig.java`

## Connections

- 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
