One possible solution is hexagonal architecture or ports and adapters architecture. The central terms port and adapter are explained in the figure below.
In our example, the architecture consists of four layers: presentation, infrastructure, application, and domain, with the presentation layer omitted for a pure back-end system. However, these are not considered top-down, but from the outside in, with the domain being the core. Outer layers may access code from inner layers, but not vice versa. This principle corresponds to the basic idea of the onion architecture, which can be extended with interfaces and their implementations (ports and adapters) to enable access to other layers. The presentation layer (UI) is usually a separate project and will not be explained further in this paper. An overview of the other three layers follows: