Anti Corruption Translator
Description
Part of an Anti-Corruption Layer (ACL), responsible for translating data between different Bounded Contexts or between the local domain and an external system.
Definition Schema
The definition for a anti_corruption_translator
component expects the following structure:
{
"example": {
"description": "Translates external order DTOs to internal domain Order aggregates.",
"name": "ExternalOrderToDomainOrderTranslator",
"source_type_module": "app_root_name.services.external_order_api.dtos",
"source_type_name": "ExternalOrderDTO",
"target_type_module": "app_root_name.domain.ordering.aggregates.order_aggregate",
"target_type_name": "Order"
},
"properties": {
"name": {
"description": "Name of the Translator class (e.g., ExternalOrderToOrderTranslator).",
"title": "Name",
"type": "string"
},
"source_type_name": {
"description": "Name of the source type (e.g., ExternalOrderDTO).",
"title": "Source Type Name",
"type": "string"
},
"source_type_module": {
"description": "Module path for the source type (e.g., app_root_name.infrastructure.external_service.dtos).",
"title": "Source Type Module",
"type": "string"
},
"target_type_name": {
"description": "Name of the target type (e.g., Order).",
"title": "Target Type Name",
"type": "string"
},
"target_type_module": {
"description": "Module path for the target type (e.g., app_root_name.domain.orders.aggregates.order).",
"title": "Target Type Module",
"type": "string"
},
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Optional docstring for the class.",
"title": "Description"
},
"implement_async_primarily": {
"default": false,
"description": "If true, translate_async will contain the primary logic and translate might raise NotImplementedError.",
"title": "Implement Async Primarily",
"type": "boolean"
}
},
"required": [
"name",
"source_type_name",
"source_type_module",
"target_type_name",
"target_type_module"
],
"title": "TranslatorEngineInputDTO",
"type": "object"
}
Naming and Location Conventions
Class: PascalCase, typically ends with 'Translator'. File: ${anti_corruption_translator_name}.py
(based on ${anti_corruption_translator_name}
). Location: app/infrastructure/persistence/${bounded_ctx}/anti_corruption/translators
. (Requires context: ['bounded_ctx'])
Example Definition
{
"name": "ExternalOrderToDomainOrderTranslator",
"source_type_name": "ExternalOrderDTO",
"source_type_module": "app_root_name.services.external_order_api.dtos",
"target_type_name": "Order",
"target_type_module": "app_root_name.domain.ordering.aggregates.order_aggregate",
"description": "Translates external order DTOs to internal domain Order aggregates."
}