Tuesday, 23 May 2017

Clean architecture - complex use case

Currently I don't use Clean architecture principles but I would like to.
I found an example where I can't figure how to implement it using Clean architecture.

Here is the Flow:

  1. Client send file with HTTP request
  2. Router handle request and create file on disk
  3. Router call the converter module with the file path
  4. Converter module is really complex and do a lot of things:
    • Convert file data in other data structure (to do so, it's interacting with domain entities)
    • Convertion involve computational methods and a lot of complex parsing
    • Extract images contained in this file and save it in the local disk
    • Send images to external storage
    • Delete images on the disk
  5. Save whole file to S3
  6. Send HTTP response to client

I would split this like the following:

  1. Interface adapters

    • External file storage
    • HTTP router
  2. use case

    • convertFile
  3. Domain entities

    • File model (handle files as a domain entity? - with methods like create, copy, clean, zip ...)
    • outputDataStructure
    • Computational models

It seems that the converter module handle a lot of logic, if I represent it as a "use case" all the business logic will be handled here.

Maybe I didn't give enough informations.
Best regards.



via Simon Bruneaud

No comments:

Post a Comment