@kenniy/godeye-event-contracts
v1.0.17
Published
Shared event schemas and stream definitions for 8Medical microservices architecture
Downloads
33
Maintainers
Readme
GOD-EYE Event Contracts
Standardized event schemas and stream definitions for 8Medical microservices architecture.
🎉 Latest Update: v1.0.11 - COMPLETE STANDARDIZATION ACHIEVED
✅ ZERO legacy code or hardcoded strings remaining ✅ ALL services use standardized constants ✅ Event flow mismatches completely resolved ✅ Clean, maintainable folder structure ✅ 100% type safety with TypeScript
🏗️ Architecture
This package provides a unified event-driven communication contract for all microservices in the GOD-EYE Healthcare Platform.
📁 Project Structure
@kenniy/godeye-event-contracts/
src/
├── consumers/ # Consumer group definitions
│ └── index.ts # ConsumerGroups, ConsumerGroupName type
├── events/ # Service-specific event schemas
│ ├── user-service/
│ │ ├── index.ts # UserServiceEvents
│ │ └── registration.ts
│ ├── hrm-service/
│ │ └── index.ts # HrmServiceEvents
│ ├── file-notification-service/
│ │ └── index.ts # NotificationServiceEventTypes
│ └── system/
│ └── index.ts # SystemEventTypes
├── schemas/ # Base event interfaces
│ └── base-event.ts # BaseEvent, EventEnvelope, etc.
├── services/ # Service name constants
│ └── index.ts # ServiceNames, ServiceName type
├── streams/ # Stream definitions
│ └── index.ts # EventStreams, EventStreamName type
├── config/ # Configuration mappings
│ ├── index.ts # Barrel file
│ ├── consumer-group-streams.ts
│ └── service-consumer-recommendations.ts
└── index.ts # Main barrel file🚀 Installation
npm install @kenniy/godeye-event-contracts📖 Usage
Basic Event Publishing
import {
EventStreams,
UserServiceEvents,
ServiceNames
} from '@kenniy/godeye-event-contracts';
// Publish a business registration event
await eventPublisher.publish(
EventStreams.USER_SERVICE_EVENTS,
UserServiceEvents.BUSINESS_REGISTERED,
{
businessId: '123',
businessName: 'Medical Center',
email: '[email protected]'
}
);Event Consumption
import {
EventStreams,
UserServiceEvents,
ConsumerGroups
} from '@kenniy/godeye-event-contracts';
// Listen for business registration events
consumer.subscribe(
EventStreams.USER_SERVICE_EVENTS,
ConsumerGroups.EMAIL_PROCESSORS,
(event) => {
if (event.eventType === UserServiceEvents.BUSINESS_REGISTERED) {
// Send welcome email
console.log(`Welcome ${event.data.businessName}!`);
}
}
);Consumer Group Configuration
import {
ConsumerGroups,
getConsumerGroupStreams,
getServiceConsumerGroups
} from '@kenniy/godeye-event-contracts';
// Get recommended consumer groups for a service
const groups = getServiceConsumerGroups(ServiceNames.FILE_NOTIFICATION_SERVICE);
// Returns: [ConsumerGroups.EMAIL_PROCESSORS, ConsumerGroups.SMS_PROCESSORS, ...]
// Get streams for a consumer group
const streams = getConsumerGroupStreams(ConsumerGroups.EMAIL_PROCESSORS);
// Returns: [EventStreams.USER_SERVICE_EVENTS, EventStreams.HRM_SERVICE_EVENTS, ...]🎯 Event Types by Service
User Service Events
CUSTOMER_REGISTERED- New customer registrationBUSINESS_REGISTERED- New business registrationADMIN_CREATED- Admin user creationCUSTOMER_LOGGED_IN/OUT- Authentication eventsEMAIL_VERIFIED- Email verification completionPASSWORD_RESET_REQUESTED- Password reset requests
HRM Service Events
HOSPITAL_REGISTERED- Hospital registrationBED_ALLOCATED/RELEASED- Bed managementSTAFF_ASSIGNED- Staff assignmentsEMERGENCY_ALERT- Emergency notifications
File+Notification Service Events
EMAIL_SENT/FAILED/DELIVERED- Email delivery trackingSMS_SENT/FAILED/DELIVERED- SMS delivery trackingFILE_UPLOADED/PROCESSED- File processing events
System Events
SERVICE_WELCOME- Service startup announcementsSERVICE_HEARTBEAT- Health check events
🔄 Event Streams
USER_SERVICE_EVENTS- User registration, authenticationHRM_SERVICE_EVENTS- Hospital resource managementNOTIFICATION_SERVICE_EVENTS- Email/SMS deliveryBUSINESS_VERIFICATION_EVENTS- Business verification workflowSERVICE_HEALTH_EVENTS- System monitoring
👥 Consumer Groups
EMAIL_PROCESSORS- Email notification handlingSMS_PROCESSORS- SMS notification handlingHRM_PROCESSORS- Hospital business logicANALYTICS_PROCESSORS- Data analytics and reportingAUDIT_PROCESSORS- Compliance and security logging
🏥 Service Names
USER_SERVICE- User management and authenticationHRM_SERVICE- Hospital resource managementFILE_NOTIFICATION_SERVICE- File processing and notificationsPAYMENT_SERVICE- Payment processingTRANSPORT_SERVICE- Ambulance and logisticsAGGREGATOR_SERVICE- Data aggregationGATEWAY_SERVICE- API gateway
📝 Type Safety
All events are fully typed with TypeScript interfaces:
import { BusinessRegisteredEvent, CustomerRegisteredEvent } from '@kenniy/godeye-event-contracts';
function handleBusinessRegistration(event: BusinessRegisteredEvent) {
// event.data is fully typed
console.log(`New business: ${event.data.businessName}`);
console.log(`Contact: ${event.data.email}`);
}🔧 Configuration
The package provides configuration helpers for setting up consumer groups and stream mappings:
import {
ServiceConsumerRecommendations,
ConsumerGroupStreams
} from '@kenniy/godeye-event-contracts';
// Get all recommended setups
const recommendations = ServiceConsumerRecommendations;
const streamMappings = ConsumerGroupStreams;📊 Event Flow Examples
Business Registration Flow
- User Service publishes
UserServiceEvents.BUSINESS_REGISTERED - File+Notification Service consumes via
ConsumerGroups.EMAIL_PROCESSORS - HRM Service consumes via
ConsumerGroups.HRM_PROCESSORS - Welcome email sent + hospital profile created
Hospital Bed Management
- HRM Service publishes
HrmServiceEvents.BED_ALLOCATED - Analytics Service tracks via
ConsumerGroups.ANALYTICS_PROCESSORS - Notification Service sends alerts via
ConsumerGroups.SMS_PROCESSORS
🔄 Migration from Legacy
Before (Event Mismatches)
// File+Notification Service was importing:
import { UserServiceEventTypes } from '@kenniy/godeye-event-contracts'; // ❌ DIDN'T EXIST!
// Causing events to be lost between servicesAfter (Fixed)
// Now correctly imports:
import { UserServiceEvents } from '@kenniy/godeye-event-contracts'; // ✅ WORKS!
// Events flow correctly: User Service → File+Notification Service🚦 Version History
- v1.0.11 - Complete standardization with clean folder structure
- v1.0.10 - Added missing event types and fixed import mismatches
- v1.0.9 - Event flow mapping and mismatch resolution
- v1.0.8 - Consumer group reorganization
- v1.0.7 - Stream standardization
- v1.0.6 - Initial standardized contracts
🛠️ Development
# Clone and setup
git clone https://github.com/keniiy/event-contracts.git
cd event-contracts
npm install
# Build
npm run build
# Watch mode
npm run dev
# Publish (maintainers only)
npm run prepublishOnly
npm publish🔗 Related Packages
This package is part of the GOD-EYE Healthcare Platform:
@kenniy/godeye-user-service@kenniy/godeye-hrm-service@kenniy/godeye-file-notification-service
📄 License
Private package for 8Medical GOD-EYE Healthcare Platform.
🆘 Support
- Issues: GitHub Issues
- Email: [email protected]
🎯 Complete Event Standardization Achieved
- ✅ Zero legacy code or naming inconsistencies
- ✅ All services use standardized event constants
- ✅ Event flows properly mapped end-to-end
- ✅ Type safety with full TypeScript support
- ✅ Clean, maintainable folder structure
- ✅ All import mismatches resolved
- ✅ Event communication working perfectly
