How hmrc/eori-common-component works
Project type and purpose
• This is a Scala/Play Framework backend microservice (“EORI Common Component”) that implements HTTP APIs for subscription management and interacts with multiple downstream HMRC services and a MongoDB datastore.
• It sits behind a frontend UI (EORI Common Component Frontend) and supports journeys like subscriber lookup, subscription handling, VAT info retrieval, email notifications, and tax enrolment.
File structure to infer architecture
• app/controllers – HTTP entry points (Play Controllers) that validate headers, parse JSON, invoke services, handle responses.
• app/services – Business logic layer coordinating data flows, building requests for connectors, orchestrating domain workflows (e.g. SubscriptionCompleteBusinessService).
• app/connectors – HTTP client adapters to downstream services (Customs Data Store, Email, GetVatCustomerInformation, MicroserviceAuth, SubscriptionDisplay, TaxEnrolments).
• app/repository – MongoDB repositories for Save4Later and RecipientDetails.
• app/domain & app/models & app/services/dto – Domain and DTO classes for request/response models.
• config & conf – Application configuration (AppConfig), routes, logging.
• audit – Audit trait to capture events for downstream reporting.
• it/test & test – Integration and unit tests.
Key architectural insights from README
• Uses Play MVC pattern: HTTP → Controller → Service → Connector/Repository → External Systems/Mongo.
• Requires external services: MongoDB, various HMRC microservices.
• Supports integration via Service Manager or Docker for local development.
• No separate frontend component here; it is purely a backend API service.
Main components and their relationships
a. External Clients & Triggers
• HTTP consumers (frontend or API clients) send requests to this service.
b. Play HTTP Layer
• Controllers receive requests, validate headers, parse JSON.
• ErrorResponses handle validation failures.
c. Business Logic Layer
• Services implement domain flows (e.g., retrieve VAT info, store interim data, invoke subscriptions, send email notifications).
• Audit trait mixed in to record key events.
d. Persistence Layer
• MongoDB repositories (Save4Later, RecipientDetails) persist state during journeys.
e. Connector Layer
• Each connector handles HTTP calls to an external HMRC system.
• MicroserviceAuthConnector obtains tokens, HttpStatusCheck/HandleResponses enforce status handling.
f. External Dependencies
• Customs Data Store service
• Email service
• Get VAT Customer Information service
• Subscription Display service
• Tax Enrolments service
• MongoDB
• (Optional) Authorization & auditing pipelines
Architectural patterns & design principles
• Layered architecture (Controllers → Services → Connectors/Repositories).
• Dependency injection via Play’s built‑in DI for services and connectors.
• Separation of concerns: domain models vs. transport DTOs.
• Fault handling and retry abstracted in connectors (HandleResponses).
• Audit cross‑cutting concern via trait mixing.
Diagramming suggestions
• “HTTP request/response” between Clients and Controllers
• “invoke” between Controllers → Services → Connectors/Repositories
• “persist/read” between Services and MongoDB endpoints
• “audit event” from Services to Audit pipeline
• API Layer (blue)
• Business Logic (green)
• Persistence (orange)
• External Systems (gray)
Detail level
• Save4Later flow: Controller → Services → Save4LaterRepository → MongoDB → Retrieval.
• Subscription workflow: HandleSubscriptionController → SubscriptionCompleteBusinessService → TaxEnrolmentsConnector → SubscriptionDisplayConnector → EmailService.