I'm currently implementing a trading bot using Python and I have the following design:
- Should I place the bot and the simulator in the same layer?
- Should I call this layer UI layer, or should I call it Application?
- What are the flaws of my design and things that could be named better?
** the bot and the simulator could even be separate projects, however, they still use the same business logic
and share a lot of commonalities so I'm wondering what is the best way to design a system that allows
multiple projects to use it.
For the sake of simplicity, the design above does not contain every component.
The full design is:
the purpose of the simulator is to run a simulation based on date range, stocks symbols pool, and a trading strategy a simplified version:
class Simulator:
def run(
self,
initial_money_amount: float,
symbols: List[str],
trading_strategy: TradingStrategy,
date_range: Tuple[float, float]=(NOW-YEAR, NOW)
) -> SimulationResult:
pass
Since both are entrypoints, they should be separated in two projects. Since they share code from the domain and persistence layers, these should be implemented as libraries and referenced by both projects. However, since you only have a limited amount of code, it is probably more maintenance burden than beneficial. Separation would be useful if you had different people maintaining different layers for instance.
Basically code in this layer do manage both the presentation and the hosting responsibilities, so you can use any name. Merging presentation and hosting is a classic approach to layered architecture. Separating both layers is usually more maintenance burden than beneficial, once again.
This is quite an opinionated question. I prefer using plain names rather than acronyms, such as persistence
, presentation
or hosting
, rather than DAL
or UI
, unless I don't have access to autocompletion tools and length matters. Also I would suggest to replace the _1
and _2
suffixes with more explicit names.