Refactoring Journey: From GistStateManager to Domain-Driven Components
The Problem: A Growing "God Class"
In our Mercury trading bot project, we started with a seemingly simple class called GistStateManager. Its initial purpose was to manage state persistence using GitHub gists as a storage mechanism. However, as the project evolved, this class accumulated more and more responsibilities:
- Managing application state in Redis
- Reconstructing state from event streams
- Creating and updating GitHub gists
- Handling Telegram message updates
- Managing UI buttons and formatting
- Coordinating state transitions
This is a classic case of what we call a "god class" - a class that knows too much and does too much. Let's explore how we can refactor this into more focused, domain-driven components.
