How fdewasmes/brewblox-brewfather-service works
Main components of the system
• Core Service: The Python service is in the “brewblox_brewfather_service” folder. Within it, the main entry point (__main__.py) kicks off the service, which coordinates brewing automation.
• API Layer: The “api” directory (with brewfather_api_client.py) abstracts and handles interactions with Brewfather’s API, e.g., fetching recipes and batch information.
• Automation Logic: The brewfather_automation.py module contains the core logic to drive the mash automation—moving between steps, handling timers, and checking the Brewtracker state.
• Data Management: The datastore.py module likely persists state or configuration, while schemas.py defines the data contracts.
• External Integrations:
• Brewfather: The external service providing recipes and Brewtracker state. Communication here occurs via HTTP using the Brewfather API client.
• Brewblox: Although not directly part of this codebase, the service is designed to integrate with Brewblox (via Docker configuration and API endpoints) and communicates with it by publishing state events.
• MQTT Broker: The service publishes automation state events on the “brewcast/state/brewfather” topic. This is key for notifying connected clients about progress.
• Deployment Environment: The Docker folder (Dockerfile, before_build.sh) and configuration files (poetry.toml, pyproject.toml, azure-pipelines.yml) indicate containerized deployment and automated CI/CD pipelines.
Relationships and interactions
• The Core Service receives API requests (e.g., via the swagger UI endpoint at /brewfather/api/doc) and subsequently invokes the Brewfather API client to load recipes or batch details.
• Once a batch is transitioned to the brewing state, the automation logic takes over: it processes the Brewtracker object, handles “pauseBefore” directives, and advances the mash automation either automatically or in response to manual triggers (via the /proceed endpoint).
• As each step is processed, the service publishes MQTT state events. These events notify Brewblox and any other subscribers of the new automation state (mash, rest, heat, etc.).
• The datastore and schemas ensure that the state, configuration, and temporal data (like timers) are managed consistently.
Architectural patterns and design principles
• Layered Architecture: Separate modules handling API interfacing, automation control, and data persistence.
• External Service Integration: Clear boundaries exist between handling Brewfather API calls and internal automation logic.
• Event-Driven Communication: Use of MQTT for broadcasting state changes indicates a reactive design.
• Configuration & Containerization: Environment variables (.env), Docker configuration, and CI/CD pipeline definitions show the project is designed for flexible deployment and integration.
• Labeled Components:
• “Mash Automation Engine” for brewfather_automation.py as the core logic controller.
• “Datastore & Schemas” for managing persistent and structured data.
• “MQTT Broker” that receives state events, labeled with the topic “brewcast/state/brewfather”.
• “External Brewfather Service” (depicted as an external system) which the client communicates with.
• “Brewblox Integration” as the endpoint via which automation progress is consumed.
• From Brewblox UI (or Swagger API client) to the Core Service.
• From the Core Service to Brewfather (using the API Client).
• From the Core Service to the MQTT Broker, indicating event publications.
• Internal modules with standard rectangles.
Overall, be as detailed as possible
• Relationships (e.g., API requests from the Swagger UI trigger Brewfather API client calls, results feed into the automation engine that then publishes MQTT events).
• To note the integration between the Dockerized service environment and the external systems (Brewfather, Brewblox, MQTT).