# masa-massara/notifier architecture

> Architecture diagram of the GitHub repository masa-massara/notifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/masa-massara/notifier
- Repository: https://github.com/masa-massara/notifier

## Overview

Notifier App is a user-scoped service that turns Notion database page changes into conditional, formatted chat notifications. Users authenticate, register a Notion integration, discover databases, and manage templates and webhook destinations; incoming Notion webhooks then trigger matching templates and send messages to configured destinations. The graph follows documented capabilities and relationships visible in the supplied excerpts and SOURCE INDEX; links to unsampled handlers or modules are omitted where their wiring is not evidenced.

Main entry points: [`src/main.ts`](https://github.com/masa-massara/notifier/blob/main/src/main.ts) (HTTP application), [`src/application/usecases/processNotionWebhookUseCase.ts`](https://github.com/masa-massara/notifier/blob/main/src/application/usecases/processNotionWebhookUseCase.ts) (Webhook processing), [`src/infrastructure/web-clients/notionApiClient.ts`](https://github.com/masa-massara/notifier/blob/main/src/infrastructure/web-clients/notionApiClient.ts) (Notion API client), [`src/infrastructure/persistence/firestore`](https://github.com/masa-massara/notifier/tree/main/src/infrastructure/persistence/firestore) (Firestore repositories)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_api_app["HTTP application<br/>[main.ts]"]
  node_auth["Request authentication<br/>[authMiddleware.ts]"]
end

subgraph group_config["User configuration"]
  node_template_api["Template API<br/>[templateHandler.ts]"]
  node_template_manage["Template management"]
  node_destination_api["Destination API"]
  node_destination_manage["Destination management"]
  node_integration_api["Notion integration API"]
  node_integration_manage["Integration management"]
  node_database_api["Database schema API"]
  node_database_discovery["Database discovery"]
  node_database_properties["Property lookup"]
end

subgraph group_webhook["Notification workflow"]
  node_webhook_api["Notion webhook handler"]
  node_webhook_process["Webhook processing"]
  node_matcher["Condition matching"]
  node_formatter["Message formatting"]
end

subgraph group_integrations["External integrations"]
  node_notion_client["Notion API client<br/>[notionApiClient.ts]"]
  node_notification_client["Webhook sender"]
end

subgraph group_storage["Persistence and services"]
  node_firestore[("Firestore repositories")]
  node_cache["Schema cache"]
  node_encryption["Token encryption"]
end

node_user(("API user"))
node_notion(("Notion"))
node_chat(("Chat webhook"))

node_user -->|"calls API"| node_api_app
node_api_app -.->|"uses middleware"| node_auth
node_api_app -->|"routes requests"| node_template_api
node_api_app -->|"routes requests"| node_destination_api
node_api_app -->|"routes requests"| node_integration_api
node_api_app -->|"routes requests"| node_database_api
node_api_app -->|"routes webhook"| node_webhook_api
node_template_api -->|"calls use cases"| node_template_manage
node_destination_api -->|"calls use cases"| node_destination_manage
node_integration_api -->|"calls use cases"| node_integration_manage
node_integration_api -->|"calls use case"| node_database_discovery
node_database_api -.->|"calls use case"| node_database_properties
node_webhook_api -->|"dispatches to"| node_webhook_process
node_webhook_process -->|"matches templates"| node_matcher
node_webhook_process -->|"formats messages"| node_formatter
node_webhook_process -->|"fetches schema"| node_notion_client
node_webhook_process -->|"sends notifications"| node_notification_client
node_webhook_process -.->|"loads records"| node_firestore
node_webhook_process -->|"decrypts token"| node_encryption
node_template_manage -.->|"stores templates"| node_firestore
node_destination_manage -.->|"stores destinations"| node_firestore
node_integration_manage -.->|"stores integrations"| node_firestore
node_integration_manage -.->|"protects tokens"| node_encryption
node_database_discovery -.->|"queries databases"| node_notion_client
node_database_properties -.->|"queries properties"| node_notion_client
node_database_properties -.->|"uses cache"| node_cache
node_notion_client -.->|"calls API"| node_notion
node_notification_client -.->|"posts message"| node_chat
node_auth -.->|"verifies identity"| node_user

click node_api_app "https://github.com/masa-massara/notifier/blob/main/src/main.ts"
click node_auth "https://github.com/masa-massara/notifier/blob/main/src/presentation/middleware/authMiddleware.ts"
click node_template_api "https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/templateHandler.ts"
click node_template_manage "https://github.com/masa-massara/notifier/tree/main/src/application/usecases"
click node_destination_api "https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/destinationHandler.ts"
click node_destination_manage "https://github.com/masa-massara/notifier/tree/main/src/application/usecases"
click node_integration_api "https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/userNotionIntegrationHandler.ts"
click node_integration_manage "https://github.com/masa-massara/notifier/tree/main/src/application/usecases"
click node_database_api "https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/notionDatabaseHandler.ts"
click node_database_discovery "https://github.com/masa-massara/notifier/blob/main/src/application/usecases/listNotionDatabasesUseCase.ts"
click node_database_properties "https://github.com/masa-massara/notifier/blob/main/src/application/usecases/getNotionDatabasePropertiesUseCase.ts"
click node_webhook_api "https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/notionWebhookHandler.ts"
click node_webhook_process "https://github.com/masa-massara/notifier/blob/main/src/application/usecases/processNotionWebhookUseCase.ts"
click node_matcher "https://github.com/masa-massara/notifier/blob/main/src/domain/services/templateMatcherService.ts"
click node_formatter "https://github.com/masa-massara/notifier/blob/main/src/application/services/messageFormatterServiceImpl.ts"
click node_notion_client "https://github.com/masa-massara/notifier/blob/main/src/infrastructure/web-clients/notionApiClient.ts"
click node_notification_client "https://github.com/masa-massara/notifier/blob/main/src/infrastructure/web-clients/httpNotificationClient.ts"
click node_firestore "https://github.com/masa-massara/notifier/tree/main/src/infrastructure/persistence/firestore"
click node_cache "https://github.com/masa-massara/notifier/blob/main/src/infrastructure/persistence/inMemory/inMemoryCacheService.ts"
click node_encryption "https://github.com/masa-massara/notifier/blob/main/src/infrastructure/services/nodeCryptoEncryptionService.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_app,node_auth,node_user toneBlue
class node_template_api,node_template_manage,node_destination_api,node_destination_manage,node_integration_api,node_integration_manage,node_database_api,node_database_discovery,node_database_properties toneAmber
class node_webhook_api,node_webhook_process,node_matcher,node_formatter,node_chat toneMint
class node_notion_client,node_notification_client toneRose
class node_firestore,node_cache,node_encryption,node_notion toneIndigo
```

## Components

### API and access

- [HTTP application](https://github.com/masa-massara/notifier/blob/main/src/main.ts): `src/main.ts`
- [Request authentication](https://github.com/masa-massara/notifier/blob/main/src/presentation/middleware/authMiddleware.ts): `src/presentation/middleware/authMiddleware.ts`

### User configuration

- [Template API](https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/templateHandler.ts): `src/presentation/handlers/templateHandler.ts`
- [Template management](https://github.com/masa-massara/notifier/tree/main/src/application/usecases): `src/application/usecases`
- [Destination API](https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/destinationHandler.ts): `src/presentation/handlers/destinationHandler.ts`
- [Destination management](https://github.com/masa-massara/notifier/tree/main/src/application/usecases): `src/application/usecases`
- [Notion integration API](https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/userNotionIntegrationHandler.ts): `src/presentation/handlers/userNotionIntegrationHandler.ts`
- [Integration management](https://github.com/masa-massara/notifier/tree/main/src/application/usecases): `src/application/usecases`
- [Database schema API](https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/notionDatabaseHandler.ts): `src/presentation/handlers/notionDatabaseHandler.ts`
- [Database discovery](https://github.com/masa-massara/notifier/blob/main/src/application/usecases/listNotionDatabasesUseCase.ts): `src/application/usecases/listNotionDatabasesUseCase.ts`
- [Property lookup](https://github.com/masa-massara/notifier/blob/main/src/application/usecases/getNotionDatabasePropertiesUseCase.ts): `src/application/usecases/getNotionDatabasePropertiesUseCase.ts`

### Notification workflow

- [Notion webhook handler](https://github.com/masa-massara/notifier/blob/main/src/presentation/handlers/notionWebhookHandler.ts): `src/presentation/handlers/notionWebhookHandler.ts`
- [Webhook processing](https://github.com/masa-massara/notifier/blob/main/src/application/usecases/processNotionWebhookUseCase.ts): `src/application/usecases/processNotionWebhookUseCase.ts`
- [Condition matching](https://github.com/masa-massara/notifier/blob/main/src/domain/services/templateMatcherService.ts): `src/domain/services/templateMatcherService.ts`
- [Message formatting](https://github.com/masa-massara/notifier/blob/main/src/application/services/messageFormatterServiceImpl.ts): `src/application/services/messageFormatterServiceImpl.ts`

### External integrations

- [Notion API client](https://github.com/masa-massara/notifier/blob/main/src/infrastructure/web-clients/notionApiClient.ts): `src/infrastructure/web-clients/notionApiClient.ts`
- [Webhook sender](https://github.com/masa-massara/notifier/blob/main/src/infrastructure/web-clients/httpNotificationClient.ts): `src/infrastructure/web-clients/httpNotificationClient.ts`

### Persistence and services

- [Firestore repositories](https://github.com/masa-massara/notifier/tree/main/src/infrastructure/persistence/firestore): `src/infrastructure/persistence/firestore`
- [Schema cache](https://github.com/masa-massara/notifier/blob/main/src/infrastructure/persistence/inMemory/inMemoryCacheService.ts): `src/infrastructure/persistence/inMemory/inMemoryCacheService.ts`
- [Token encryption](https://github.com/masa-massara/notifier/blob/main/src/infrastructure/services/nodeCryptoEncryptionService.ts): `src/infrastructure/services/nodeCryptoEncryptionService.ts`

### Other components

- **API user**
- **Notion**
- **Chat webhook**

## Connections

- API user → HTTP application: calls API (evidence: `README.md`)
- HTTP application → Request authentication: uses middleware (evidence: `src/main.ts`)
- HTTP application → Template API: routes requests (evidence: `src/main.ts`)
- HTTP application → Destination API: routes requests (evidence: `src/main.ts`)
- HTTP application → Notion integration API: routes requests (evidence: `src/main.ts`)
- HTTP application → Database schema API: routes requests (evidence: `src/main.ts`)
- HTTP application → Notion webhook handler: routes webhook (evidence: `src/main.ts`)
- Template API → Template management: calls use cases (evidence: `src/presentation/handlers/templateHandler.ts`)
- Destination API → Destination management: calls use cases (evidence: `src/presentation/handlers/destinationHandler.ts`)
- Notion integration API → Integration management: calls use cases (evidence: `src/presentation/handlers/userNotionIntegrationHandler.ts`)
- Notion integration API → Database discovery: calls use case (evidence: `src/presentation/handlers/userNotionIntegrationHandler.ts`)
- Database schema API → Property lookup: calls use case
- Notion webhook handler → Webhook processing: dispatches to (evidence: `src/main.ts`)
- Webhook processing → Condition matching: matches templates (evidence: `src/application/usecases/processNotionWebhookUseCase.ts`)
- Webhook processing → Message formatting: formats messages (evidence: `src/application/usecases/processNotionWebhookUseCase.ts`)
- Webhook processing → Notion API client: fetches schema (evidence: `src/application/usecases/processNotionWebhookUseCase.ts`)
- Webhook processing → Webhook sender: sends notifications (evidence: `src/application/usecases/processNotionWebhookUseCase.ts`)
- Webhook processing → Firestore repositories: loads records
- Webhook processing → Token encryption: decrypts token (evidence: `src/application/usecases/processNotionWebhookUseCase.ts`)
- Template management → Firestore repositories: stores templates
- Destination management → Firestore repositories: stores destinations
- Integration management → Firestore repositories: stores integrations
- Integration management → Token encryption: protects tokens
- Database discovery → Notion API client: queries databases
- Property lookup → Notion API client: queries properties
- Property lookup → Schema cache: uses cache
- Notion API client → Notion: calls API
- Webhook sender → Chat webhook: posts message
- Request authentication → API user: verifies identity
