Skip to content

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Sep 30, 2025

Summary by CodeRabbit

  • New Features
    • Added configurable event broadcasting for tenants, organizations, and users via Kafka topics and listener endpoints.
    • Event payloads now include structured change details (old/new values) for updates.
  • Chores
    • Introduced new environment variables to enable/disable event streams and configure topics/endpoints.
  • Refactor
    • Unified the event broadcasting API name across services.
    • Centralized routing of events by group (tenant, organization, user) for Kafka delivery.

@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Walkthrough

Adds tenant and organization eventing across env config, DTOs, utils, Kafka helpers, broadcaster, and services. Introduces broadcastEvent API replacing broadcastUserEvent, per-entity Kafka topics/endpoints, change-diff utilities, and emits structured create/update events for users, tenants, and organizations.

Changes

Cohort / File(s) Summary of changes
Environment configuration
src/.env.sample, src/envVariables.js
Adds enablement flags and topics/endpoints for user/tenant/org Kafka and listener APIs; adjusts requiredIf for user Kafka topic to new flag.
DTOs for event payloads
src/dtos/organizationDTO.js, src/dtos/tenantDTO.js
Adds static eventBodyDTO(...) to build validated event bodies including computed changes and filtered args.
Kafka helpers
src/generics/kafka-communication.js
Adds pushTenantEventsToKafka and pushOrganizationEventsToKafka; exports updated.
Utilities
src/generics/utils.js
Adds extractUpdatedValues(oldData, newData, updateData) to compute field-level diffs; exports updated.
Event broadcaster API
src/helpers/eventBroadcasterMain.js
Renames export to broadcastEvent; adds tenantEvents support; routes to user/org/tenant Kafka helpers by group; extends endpoint/enablement lookups.
Services and callers using broadcaster
src/helpers/userInvite.js, src/services/account.js, src/services/user.js
Replaces broadcastUserEvent with broadcastEvent at call sites; imports updated.
Admin service org events
src/services/admin.js
Integrates organizationDTO.eventBodyDTO and broadcastEvent; updates deactivateOrg to use returning updates and emit org deactivation events.
Organization service events
src/services/organization.js
Adds structured create/update org events, related_orgs enrichment, centralized orgEventEmitter using diff + DTO, and broadcasts via broadcastEvent.
Tenant service events
src/services/tenant.js
Adds tenant create/update/domain add/remove events using TenantDTO.eventBodyDTO, returning updates, and tenantEventEmitter for diffs and broadcasting.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller as Service/Helper
  participant EB as eventBroadcasterMain.broadcastEvent
  participant ENV as Env flags
  participant HTTP as Listener API (per group)
  participant K as Kafka helpers

  Caller->>EB: broadcastEvent(eventGroup, {requestBody, headers, isInternal})
  EB->>ENV: isEventEnabled(eventGroup)?
  alt events disabled
    EB-->>Caller: no-op / log
  else events enabled
    EB->>ENV: getEndpoints(eventGroup)
    alt endpoints exist
      EB->>HTTP: POST requestBody (per endpoint)
      HTTP-->>EB: 2xx/4xx
    else no endpoints
      EB->>K: route by group<br/>org→pushOrganizationEventsToKafka<br/>user→pushUserEventsToKafka<br/>tenant→pushTenantEventsToKafka
      K-->>EB: ack/error
    end
    EB-->>Caller: result/log
  end
Loading
sequenceDiagram
  autonumber
  participant Svc as Org/Tenant Service
  participant Utils as extractUpdatedValues
  participant DTO as *.eventBodyDTO
  participant EB as broadcastEvent

  Svc->>Utils: compute changedValues(old, new, updateData)
  Utils-->>Svc: [{fieldName, oldValue, newValue}, ...]
  Svc->>DTO: eventBodyDTO({entity, eventType, entityId, changedValues, args})
  DTO-->>Svc: eventBody payload
  Svc->>EB: broadcastEvent(group, {requestBody: payload, isInternal: true})
  EB-->>Svc: completion/log
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

A rabbit taps the topic drum, thump-thump on Kafka lanes,
Tenants hop, orgs bop, users ride the message trains.
Flags are raised, endpoints sing,
Diffy carrots, changes ring.
With one grand “broadcastEvent,” we spring—
Logs like clover, queues like spring. 🐇✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f99088 and dd08237.

📒 Files selected for processing (13)
  • src/.env.sample (1 hunks)
  • src/dtos/organizationDTO.js (1 hunks)
  • src/dtos/tenantDTO.js (1 hunks)
  • src/envVariables.js (2 hunks)
  • src/generics/kafka-communication.js (2 hunks)
  • src/generics/utils.js (2 hunks)
  • src/helpers/eventBroadcasterMain.js (4 hunks)
  • src/helpers/userInvite.js (3 hunks)
  • src/services/account.js (3 hunks)
  • src/services/admin.js (6 hunks)
  • src/services/organization.js (9 hunks)
  • src/services/tenant.js (7 hunks)
  • src/services/user.js (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@nevil-mathew
Copy link
Collaborator Author

@coderabbitai summary

@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

✅ Actions performed

Summary regeneration triggered.

@coderabbitai coderabbitai bot changed the title @coderabbitai Add tenant/org eventing, per-entity Kafka topics, broadcastEvent API Sep 30, 2025
@nevil-mathew nevil-mathew merged commit 47357a0 into staging Sep 30, 2025
1 of 2 checks passed
This was referenced Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants