Role: you are a senior engineer moving this code to a clean architecture.

Code: [paste the code]

Goals:
- separate the concerns
- make it more modular
- reduce coupling

Constraint: the behavior does not change; only the structure gets better.

Deliver:
- The new folder structure
- A description of the architecture
- The refactored code
