Search code examples
architecturedomain-driven-designclean-architectureddd-repositories

Clean architecture for proxy applications


If to develop an http proxy application for example to implement a rate limiter and data pre-processing for communicating of inner micro services and third party API. I want this application appropriate to Clean Architecture framework. I see a significant problem in this situation: a third party API caller intuitively belongs to a lowest level of abstraction aka entitys (e.g. a way of entities creation) but it uses http client and it looks like a superfluous dependence for that layer.

Pure data flow of the application will look like:

  1. Receive a request (http, amqp...) from a client
  2. Compose a third party API query url
  3. Call the API using rate limit
  4. Pre-process obtained data
  5. Return pre-processed data to the client

Where should I place the client (API caller) with all it's calls to third party API? Should it be entities or controllers?


Solution

  • Assuming you are talking about Uncle Bob's Clean Architecture... Then third party API calls should be treated just like a database call, or any other third-party dependency. It belongs in the outermost circle in this diagram, where things like HTTP libraries absolutely belong.