How gs89alberto/image-processor works
Main Components
• Tasks Service – Handles the creation of image processing tasks through REST endpoints (e.g., POST /tasks and GET /tasks/:taskId). Within the tasks service, show layers such as:
• HTTP Interface/Controllers (routing, validators)
• Application Services (TaskService, business logic)
• Domain Entities/Repositories (e.g., Task entity, ITaskRepository)
• Infrastructure including Kafka integration (TaskCreatedProducer, TaskProcessedConsumer), MongoDB repository (MongoTaskRepository), and the webserver.
• Application Services (ImageService)
• Domain layer (Image entity, IImageRepository)
• Infrastructure components that include Kafka consumers (e.g., TaskCreatedConsumer that listens for tasks), and MongoDB repositories (MongoImageRepository).
• Common Package – Contains shared configuration (for DB, Kafka, etc.), DTOs, middleware (error handling, rate limiting, validations), constants, and utilities which are used by both microservices.
• External Systems – Include MongoDB for persistence, Kafka (with Zookeeper where applicable) for asynchronous messaging, and Docker Compose (for orchestration of these services).
Illustrating Interactions and Relationships
• The Tasks Service receives REST API requests from clients.
• After creating a task, the Tasks Service produces a Kafka message signaling that a task has been created.
• The Images Service consumes this event via its Kafka consumer (TaskCreatedConsumer) and then processes the image (transformation, storage).
• Once the processing is complete, if there is any event-driven update needed, an event (or callback) can update the Tasks Service.
• That both microservices share a common configuration and utility layer (represented by the common package) which acts cross-cutting concerns like logging, configuration, and DTO definitions.
Emphasizing Architectural Patterns
• Use of the Hexagonal Architecture pattern in both services – separate the domain logic from infrastructure details such as handling HTTP requests or interacting with Kafka/MongoDB.
• Clearly distinguish between layers:
• Domain Layer: Entities and business rules.
• Application Layer: Service logic and use cases.
• Infrastructure Layer: Controllers, persistence (MongoDB repositories), Kafka producers/consumers, and web server setup.
• Asynchronous event-driven communication layer using Kafka, showing producers and consumers from both microservices.