# mart6delavi/emergency-notification-system architecture

> Architecture diagram of the GitHub repository mart6delavi/emergency-notification-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mart6delavi/emergency-notification-system
- Repository: https://github.com/mart6delavi/emergency-notification-system

## Overview

##### Main Components
- API Gateway – Represented by the “sensa-api-gateway” module. It acts as the centralized entry point for incoming REST API requests and handles tasks like request filtering, routing, and logging.
- Service Discovery – Shown by the “sensa-discovery-server”. This component enables dynamic service registration and discovery, allowing the other microservices to locate each other.
- Authentication Service – The “sensa-authentication-service” handles user authentication, security (including JWT token handling via Redis), and authorization.
- Notification Service – The “sensa-notification-service” manages the sending and tracking of emergency alerts, particularly via Telegram. It also integrates with Kafka for asynchronous communication.
- Message Delivery Service – The “sensa-message-delivery-service” is responsible for orchestrating the delivery of messages, managing interactions with external clients (like NotificationClient and UserManagementClient), and likely handling retries or scheduling.
- Template Service – The “sensa-template-service” allows creation, storage, and management of message templates.
- User Management Service – The “sensa-user-management-service” handles recipient data, user profiles, and bulk data import/update functionalities.
- External Database and Caching – Use PostgreSQL for persistent storage of recipient data, message logs, and templates. Redis is used to store and quickly access authorization tokens and possibly session data.
- Asynchronous Messaging – Kafka acts as the backbone for inter-service communication (used in several modules including authentication, messaging, and notification).

##### Relationships and Data Flow
- External users (admin or trigger systems) send REST API requests that hit the API Gateway.
- The API Gateway forwards validated requests to the appropriate service (for example, authentication requests go to the authentication service; sending alerts trigger the message delivery and notification services).
- Connectivity with external systems like Telegram (for sending alerts) should be shown via outbound data flow from the notification service.
- Database interactions (with PostgreSQL) and caching operations (with Redis) should be depicted from the individual services where these operations occur.

##### Architectural Patterns and Technologies
- Microservices Paradigm – Emphasize that each module is a separate deployable Spring Boot service with its own source tree and Docker configuration.
- API Gateway and Service Discovery Patterns – These provide a scalable entry point and dynamic routing between services.
- Asynchronous Event Processing – Use of Kafka, as well as asynchronous processing techniques for low latency in bulk notifications, should be clearly illustrated.
- Containerization – Since Docker and docker-compose files are present in each service, a container layer can be shown around the microservices to indicate the deployment environment.
- Security – Show the authentication service’s interactions with Redis for token management and the implementation of rate limiting/security filtering (as seen with the RequestFilter and SecurityConfig).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        E("External User (Client)"):::client
        AG("API Gateway"):::api
    end

    %% Core Services
    subgraph "Core Services"
        SD("Service Discovery"):::discovery
        AS("Authentication Service"):::microservice
        NS("Notification Service"):::microservice
        MDS("Message Delivery Service"):::microservice
        TS("Template Service"):::microservice
        UMS("User Management Service"):::microservice
    end

    %% Infrastructure
    subgraph "Infrastructure"
        K("Kafka"):::infrastructure
        PSQL("PostgreSQL"):::infrastructure
        R("Redis"):::infrastructure
        TAPI("Telegram API"):::external
    end

    %% Connections from External User to API Gateway
    E -->|"REST_API"| AG

    %% API Gateway routes to other services
    AG -->|"Auth_Request"| AS
    AG -->|"Alert_Trigger"| NS
    AG -->|"Delivery_Request"| MDS
    AG -->|"Template_Manage"| TS
    AG -->|"User_Manage"| UMS

    %% Service Registration with Service Discovery
    AG -->|"register"| SD
    AS -->|"register"| SD
    NS -->|"register"| SD
    MDS -->|"register"| SD
    TS -->|"register"| SD
    UMS -->|"register"| SD

    %% Asynchronous Messaging via Kafka
    AS -->|"publish_auth_events"| K
    K -->|"subscribe_events"| NS
    K -->|"subscribe_events"| MDS
    K -->|"subscribe_events"| UMS

    %% Database / Cache Interactions
    AS -->|"JWT_Tokens"| R
    NS -->|"store_message_logs"| PSQL
    TS -->|"store_templates"| PSQL
    UMS -->|"store_user_data"| PSQL

    %% External Integration
    NS -->|"send_alert"| TAPI

    %% Click Events for Component Mapping
    click AG "https://github.com/mart6delavi/emergency-notification-system/tree/master/sensa-api-gateway/"
    click SD "https://github.com/mart6delavi/emergency-notification-system/tree/master/sensa-discovery-server/"
    click AS "https://github.com/mart6delavi/emergency-notification-system/tree/master/sensa-authentication-service/"
    click NS "https://github.com/mart6delavi/emergency-notification-system/tree/master/sensa-notification-service/"
    click MDS "https://github.com/mart6delavi/emergency-notification-system/tree/master/sensa-message-delivery-service/"
    click TS "https://github.com/mart6delavi/emergency-notification-system/tree/master/sensa-template-service/"
    click UMS "https://github.com/mart6delavi/emergency-notification-system/tree/master/sensa-user-management-service/"

    %% Styles
    classDef client fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef api fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef microservice fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef discovery fill:#ffe082,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#ffab91,stroke:#333,stroke-width:2px;
    classDef external fill:#80deea,stroke:#333,stroke-width:2px;
```
