# UML Class Diagram: Integration and Observability

Packages: `backend`, `api.utils`, `api.models`, `kafka_consumer`, `node`.

## Class and Module Responsibilities

| Component | Responsibility |
| --- | --- |
| `backend.kafka.send_request` | Generates a UUID request id, adds it to the payload, publishes Kafka JSON with a `method` header, writes `KafkaLog`, and flushes the producer. |
| `KafkaLog` | Persists Kafka request/response payloads and correlates responses by `request_id`. |
| `kafka_consumer.tt_response` | Polls the unified response topic, dispatches by method, updates activities/resources/Redis, forwards microservice data, and pushes websocket notifications. |
| `backend.redis_client.redis_client` | Lazily constructed Redis client configured from settings. |
| `api.utils.bulk_sync_to_redis` | Applies insert/update/delete payloads to Redis JSON keys. |
| `api.utils.push_websocket_notification` | Posts `{socket_id, data}` to the Node broadcaster HTTP endpoint. |
| `node/broadcast.js` | Express HTTP endpoints that emit Socket.IO events to a specific socket room. |
| `IncomingApiAdmin`, `AuditTrail`, `ErrorLog` | Admin request logging, audit records, and exception storage. |

```mermaid
classDiagram
direction LR
class KafkaProducerModule {
  +send_request(topic, data, socket_id, method)
}
class KafkaLog {
  +request_id
  +request_topic
  +request_data
  +response_topic
  +response_data
  +socket_id
  +insert_request()
  +update_response()
}
class KafkaConsumerWorker {
  +schedule(response_data, kafka_log)
  +preschedule(response_data, kafka_log)
  +swap(response_data, kafka_log)
  +pollLoop()
}
class RedisClient
class RedisSyncUtility {
  +bulk_sync_to_redis(redis_client, data, chunk_size)
}
class WebsocketUtility {
  +push_websocket_notification(url, data, socket_id)
}
class NodeBroadcaster {
  +postScheduleResponse()
  +postPrescheduleResponse()
  +postPrescheduleDetailsResponse()
  +postSwapGetResources()
  +postSwap()
}
class IncomingApiAdmin
class AuditTrail
class AuditTrailDetails
class ErrorLog
class TtActivity
class TtStaff
class TtLocation
class TtStudentSet

KafkaProducerModule --> KafkaLog : insert request
KafkaProducerModule --> KafkaConsumerWorker : Kafka topics
KafkaConsumerWorker --> KafkaLog : update response
KafkaConsumerWorker --> TtActivity : schedule updates
KafkaConsumerWorker --> TtStaff : resource map updates
KafkaConsumerWorker --> TtLocation : resource map updates
KafkaConsumerWorker --> TtStudentSet : resource map updates
KafkaConsumerWorker --> RedisSyncUtility : cache sync
RedisSyncUtility --> RedisClient : pipeline JSON commands
KafkaConsumerWorker --> WebsocketUtility : notify frontend
WebsocketUtility --> NodeBroadcaster : HTTP POST
IncomingApiAdmin --> ErrorLog : exceptions can be logged separately
AuditTrail "1" --> "*" AuditTrailDetails
```
