Messaging

{
  "overview": "## Messaging Service Overview\n\nThe messaging service is an integral component of the Vivified platform that facilitates inter-plugin communication with strict adherence to HIPAA compliance. It ensures secure and efficient data exchange across various platform modules.\n\n!!! note\n    This service uses a canonical message format and supports multiple message types, including events, requests, responses, and notifications.\n\n### Architecture\n\n```mermaid\ngraph TD;\n    A[Messaging Service] -->|Sends Message| B[Event Bus];\n    B --> C{Broker}\n    C -->|Dispatch| D[Subscriber Plugins];\n    C -->|Audit| E[Audit Service];\n    C -->|Policy Check| F[Policy Engine];\n```\n\n### Key Components\n- **MessagingService**: The main service managing message dispatch and receipt.\n- **EventBus**: Abstracts the broker for message publishing and subscribing, supporting various backends like NATS, Redis, or in-memory.\n- **AuditService**: Ensures all message interactions are logged for compliance and security auditing.\n- **PolicyEngine**: Evaluates policies to enforce data privacy and security measures.\n\n### Security Considerations\n- All messages are audited to ensure compliance with HIPAA regulations.\n- Data classifications such as PHI and PII are enforced to protect sensitive information.\n- The policy engine ensures that all data exchanges comply with predefined security policies.\n\n!!! warning\n    Ensure that the messaging service is deployed in a secure and isolated environment to prevent unauthorized access to sensitive data.\n\n## Troubleshooting\n\n1. **Message Delivery Failures**\n   - Check network connectivity and broker availability.\n   - Ensure correct broker configuration in the environment settings.\n\n2. **Policy Decision Denials**\n   - Review policy rules in the PolicyEngine for accuracy and relevancy.\n   - Validate user permissions and roles against policy requirements.",
  "api": "## Messaging Service API Reference\n\n### MessagingService\n\n- `__init__(self, audit_service: AuditService, policy_engine: PolicyEngine)`: Initializes the messaging service with audit and policy components.\n- `start(self)`: Starts the messaging service for handling inter-plugin communication.\n\n### Message Model\n\n| Attribute        | Type               | Description                         |\n|------------------|--------------------|-------------------------------------|\n| `id`             | `str`              | Unique identifier for the message.  |\n| `message_type`   | `MessageType`      | Type of the message (e.g., event).  |\n| `priority`       | `MessagePriority`  | Priority level of the message.      |\n\n### MessageType Enum\n- `EVENT`: Represents an event message.\n- `REQUEST`: Represents a request message.\n- `RESPONSE`: Represents a response message.\n- `NOTIFICATION`: Represents a notification message.\n\n### MessagePriority Enum\n- `LOW`, `NORMAL`, `HIGH`, `CRITICAL`: Priority levels.\n\n### DataClassification Enum\n- `PUBLIC`, `INTERNAL`, `CONFIDENTIAL`, `PHI`, `PII`: Data classification levels.",
  "config": "## Configuration Guide\n\nThe messaging service can be configured using environment variables or configuration files. Below are the key configuration options:\n\n| Option                  | Description                                        | Default        |\n|-------------------------|----------------------------------------------------|----------------|\n| `EVENT_BUS_BACKEND`     | Backend for the event bus (`nats`, `redis`, `memory`). | `memory`       |\n| `LOG_LEVEL`             | Logging level for the service (`DEBUG`, `INFO`).   | `INFO`         |\n\nTo configure the event bus backend to use Redis, set the environment variable:\n\n```bash\nexport EVENT_BUS_BACKEND=redis\n```\n\n!!! tip\n    Test your configuration changes in a development environment before applying them to production.",
  "examples": "## Usage Examples\n\n=== \"Python\"\n\n    ```python\n    from vivified.messaging.service import MessagingService\n    from vivified.audit.service import AuditService\n    from vivified.policy.engine import PolicyEngine\n\n    audit_service = AuditService()\n    policy_engine = PolicyEngine()\n    messaging_service = MessagingService(audit_service, policy_engine)\n\n    async def start_service():\n        await messaging_service.start()\n    ```\n\n=== \"curl\"\n\n    ```bash\n    # Example command to check service status\n    curl -X GET http://localhost:8000/status\n    ```\n\nThese examples demonstrate how to initialize and start the messaging service using Python and how to interact with it via command-line tools like curl."
}