This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Notifier is Devtron's multi-channel notification service. It receives CI/CD pipeline events (via NATS JetStream or HTTP) and dispatches notifications to Slack, email (SES/SMTP), and webhooks. Built with TypeScript, Express, TypeORM (PostgreSQL), and NATS.
npm install # Install dependencies
npm run dev # Dev server with nodemon (auto-reload)
npm run dev:debug # Dev server with --inspect debugger
npm run build-ts # Compile TypeScript to dist/
npm run serve # Run compiled JS from dist/
npm test <file> # Run a single test file, e.g.: npm test src/tests/notificationService.test.tsRequires Node.js >= 20. TypeScript strict mode is enabled but noImplicitAny and strictNullChecks are off.
| Variable | Default | Description |
|---|---|---|
| DB_HOST | localhost | PostgreSQL host |
| DB_PORT | 5432 | PostgreSQL port |
| DB_USER | user | PostgreSQL username |
| DB_PWD | password | PostgreSQL password |
| DB | orchestrator | Database name |
| PORT | 3000 | HTTP server port |
| NATS_URL | (none) | NATS server URL; NATS disabled if unset |
| BASE_URL | (none) | Base URL for links embedded in notifications |
src/server.ts → connects to PostgreSQL (TypeORM), initializes all services via src/services/serviceInitializer.ts (manual DI), connects to NATS, starts Express on PORT.
Event Source (NATS JetStream or POST /notify/v2)
→ NotificationService.sendNotificationV2()
→ Loads notification_settings + templates from DB
→ json-rules-engine evaluates filter conditions
→ Dispatches to matching Handler implementations:
SlackService → Slack webhook API (via notifme-sdk)
SESService → AWS SES (via notifme-sdk)
SMTPService → SMTP server (via notifme-sdk)
WebhookService → HTTP POST to user-configured URLs (via axios)
→ Logs results to notifier_event_logs table
All destination handlers implement Handler (defined in src/notification/service/notificationService.ts) with:
handle(event, templates, setting, configsMap, destinationMap)— orchestrates a single notification sendsendNotification(event, sdk, template)— performs the actual send
Mustache templates live in src/templates/{slack,ses,smtp}/{CI,CD,BASE}/. Files are named by EVENT_TYPE enum value (e.g., 1.mustache for Trigger). TemplateLoader reads them at startup. MustacheHelper parses raw events into typed objects with boolean flags for conditional template rendering.
1=Trigger, 2=Success, 3=Fail, 4=Approval, 5=ConfigApproval, 6=Blocked, 7=ImagePromotion, 8=ImageScan, 9=ScoopNotification, 10=DeploymentApproved, 11=ConfigApproved, 12=PromotionApproved, 13=DeploymentCancelled, 14=ConfigCancelled, 15=PromotionCancelled
src/notification/service/— core NotificationService orchestrationsrc/destination/destinationHandlers/— channel-specific handlers (Slack, SES, SMTP, Webhook)src/entities/— TypeORM entity models (notification_settings, slack_config, smtp_config, ses_config, webhook_config, events, users, notifier_event_logs)src/repository/— data access layer wrapping TypeORMsrc/common/— shared types, MustacheHelper (event parsing), EventLogBuilder, Prometheus metricssrc/templates/— Mustache templates organized by channel and pipeline typesrc/config/— database, NATS, and logger configurationsrc/pubSub/— NATS JetStream client
Manual constructor injection in src/services/serviceInitializer.ts. No DI framework — all repositories, helpers, and handlers are instantiated explicitly and wired together.
Tests use Mocha + Chai (BDD style) in src/tests/. The custom test runner (test.ts) accepts a single file path:
npm test src/tests/notificationService.test.ts
npm test src/tests/approvalTemplateTest.tsTests are standalone files — no shared setup/teardown infrastructure.