Sensoworks Edge/Fog architecture
Overview
The Sensoworks Fog architecture is designed to manage configurations, control flows, and monitor the status of various processes in a distributed environment. This document provides an overview of the architecture, including the main components and their interactions.

Components
1. Configuration Server
The ConfigurationServer is a Flask-based server that exposes RESTful APIs for managing configurations and controlling flows. It interacts with the ConfigManager and FlowManager to handle configuration data and flow commands.
2. ConfigManager
The ConfigManager handles the storage, retrieval, and manipulation of configuration data. It is responsible for reading configuration files, updating configurations, and providing configuration details to other components.
3. FlowManager
The FlowManager is responsible for managing the lifecycle of flows. It can start, stop, pause, and resume flows based on the commands received from the ConfigurationServer. The FlowManager maintains the status of each flow and interacts with the SensoworksFog instances to control their execution.
4.Workflow Engine (SensoworksFog class)
The SensoworksFog class represents a single flow instance and acts as the workflow engine. It is initialized with a configuration and is responsible for managing the execution of tasks within the flow. The SensoworksFog class handles triggering tasks based on defined conditions, managing state transitions, and ensuring tasks are executed in the correct order. Each SensoworksFog instance runs in a separate thread to allow concurrent execution of multiple flows.
5.Flows
The Flows component provides a user interface for managing configurations that the workflow engine will execute. This interface enabling users to efficiently set up and control their workflows within the IoT infrastructure. In addition to its configuration management capabilities, the Flows component communicates with the Edge-Broker component to exchange and synchronize information with the platform. This communication ensures that all configurations and workflow instructions are up-to-date and accurately reflect the current state of the system. Furthermore, the Flows component provides detailed information about the node on which it resides. This information is critical for maintaining an accurate and comprehensive view of the network's operational status, enhancing the platform's ability to manage and optimize its resources. By integrating with the Edge-Broker and providing a robust interface for workflow management, the Flows component plays a crucial role in the seamless operation of the IoT system, ensuring that configurations are effectively managed and executed across the network.

Interactions
Initialization
- MainSensoworksFogGateway: This is the main entry point for the application. It initializes the ConfigManager,FlowManager, andConfigurationServer, and starts the server andWorkflowEngineinstances as background processing threads.
- ConfigurationServer: The server starts and listens for incoming API requests.
Configuration Management
- Get All Configurations: The ConfigurationServerreceives a request to retrieve all configurations. It calls theget_all_configsmethod on theConfigManager, which reads and returns all configuration files.
- Get Configuration by ID: The ConfigurationServerreceives a request to retrieve a specific configuration. It calls theget_configmethod on theConfigManagerwith theflow_id, and theConfigManagerreturns the corresponding configuration.
- Add/Update/Delete Configuration: The ConfigurationServerhandles requests to add, update, or delete configurations by calling the respective methods on theConfigManager.
Flow Control
- Start Flow: The ConfigurationServerreceives a request to start flows. It calls thestart_flowsmethod on theFlowManagerwith the list offlow_ids. TheFlowManagerinitializes and starts aSensoworksFoginstance for each flow.
- Stop/Pause/Resume Flow: Similar to starting flows, the ConfigurationServerhandles requests to stop, pause, or resume flows by calling the respective methods on theFlowManager.
Status Monitoring
- Get Flow Status: The ConfigurationServerreceives a request to retrieve the status of all flows or a specific flow. It calls theget_flow_statusmethod on theFlowManager, which returns the current status information.
- Current Task: The FlowManagercan also provide details about the current task being executed in a flow.
Data Flow
- Configuration Files: Stored in a specified directory and managed by the ConfigManager.
- Flow Status: Maintained in a shared dictionary with thread-safe access managed by the flow_status_lock.
- Commands and Responses: Handled by the ConfigurationServerand passed to theFlowManagerfor execution.
Example Workflow
- Starting the Server: The MainSensoworksFogGatewaystarts theConfigurationServerand the background engine flow.
- Adding a Configuration: A client sends a POST request to /flowswith a new configuration. TheConfigurationServerprocesses the request and updates the configuration files via theConfigManager.
- Starting a Flow: A client sends a PATCH request to /flows/commandswith a start command and flow IDs. TheConfigurationServerforwards the command to theFlowManager, which initializes and starts theSensoworksFoginstances.
- Monitoring Status: A client sends a GET request to /flows/statusto retrieve the status of all flows. TheConfigurationServerfetches the status from theFlowManagerand returns it to the client.
