# p3arl/notification-service architecture

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

- Interactive diagram: https://gitdiagram.com/p3arl/notification-service
- Repository: https://github.com/p3arl/notification-service

## Overview

##### Project type and purpose
- This is a single Spring Boot microservice (“notification-service”) whose sole responsibility is to send notifications (SMS, Email, Push) to users based on their subscription plan.
- It exposes REST endpoints for managing subscriptions and triggering notifications. It uses an in-memory HSQL database for persistence and will integrate with external push‐notification providers.

##### File structure
- src/main/java/com/project/config
- Application.java – entry point, SpringBootApplication
- DatabaseConfig.java – HSQL in-memory DataSource setup
- src/main/java/com/project/controller
- NotificationController – REST endpoints to send notifications
- SubscriptionController – endpoints to manage user subscriptions
- src/main/java/com/project/service (and interfaces)
- INotificationService / NotificationService – orchestrates sending notifications
- ISubscriptionService / SubscriptionService – subscription logic
- IUserService / UserService – user lookup, plan resolution
- IPushService – interface for push‐providers
- src/main/java/com/project/utility/service
- SmsService, EmailService – concrete implementations for SMS/Email
- AndroidPushService, ApplePushService – placeholder push integrations
- src/main/java/com/project/repository
- IUserRepository, INotificationRepository – Spring Data repositories
- src/main/resources
- application.properties – configuration (DB URL, credentials)
- testdb/schema.sql & data.sql – in-memory DB initialization
- tests exercise the service layer (NotificationServiceTest).

##### Key architectural insights from README
- Stateless Spring Boot REST microservice
- In-memory DB for easy testing
- Pluggable notification channels (SMS, Email, future Push)

– Top: Controllers
– Middle: Services (NotificationService, SubscriptionService, UserService)
– Bottom: Repositories
– Client → Controller (HTTP POST/GET)
– Controller → Service (Java method call)
– Service → Repository (JPA calls)
– Service → Utility Service (Strategy invocation)
– Utility Service → External API (REST/SMTP)

Clarity over artistic detail: capture every layer, every integration, and show how data and execution flow through the system from incoming HTTP request to external notification provider.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Clients["Clients (Mobile/Web)"]:::external

    %% Main Application
    subgraph "notification-service"
        direction TB

        %% Configuration Layer
        subgraph "Configuration"
            Application["Application"]:::config
            DatabaseConfig["DatabaseConfig"]:::config
        end

        %% Controller Layer
        subgraph "Controllers"
            NotificationController["NotificationController"]:::controller
            SubscriptionController["SubscriptionController"]:::controller
        end

        %% Service Layer
        subgraph "Services"
            NotificationService["NotificationService"]:::service
            SubscriptionService["SubscriptionService"]:::service
            UserService["UserService"]:::service
        end

        %% Utility Service Layer
        subgraph "Utility Services"
            SmsService["SmsService"]:::utility
            EmailService["EmailService"]:::utility
            AndroidPushService["AndroidPushService"]:::utility
            ApplePushService["ApplePushService"]:::utility
        end

        %% Repository Layer
        subgraph "Repositories"
            IUserRepository["IUserRepository"]:::repository
            INotificationRepository["INotificationRepository"]:::repository
        end
    end

    %% Persistence
    HSQLDB["HSQL In-Memory DB"]:::database

    %% External Systems
    SMTP["SMTP Server"]:::external
    SMSGateway["SMS Gateway"]:::external
    PushAPI["Push Provider API"]:::external

    %% Connections
    Clients -->|"HTTP Request"| NotificationController
    Clients -->|"HTTP Request"| SubscriptionController

    NotificationController -->|"calls"| NotificationService
    SubscriptionController -->|"calls"| SubscriptionService

    NotificationService -->|"uses"| UserService
    NotificationService -->|"persists"| INotificationRepository
    SubscriptionService -->|"persists"| IUserRepository
    UserService -->|"reads"| IUserRepository

    NotificationService -->|"strategy"| SmsService
    NotificationService -->|"strategy"| EmailService
    NotificationService -->|"strategy"| AndroidPushService
    NotificationService -->|"strategy"| ApplePushService

    IUserRepository -->|JPA| HSQLDB
    INotificationRepository -->|JPA| HSQLDB

    SmsService -->|"REST API"| SMSGateway
    EmailService -->|"SMTP"| SMTP
    AndroidPushService -->|"HTTP"| PushAPI
    ApplePushService -->|"HTTP"| PushAPI

    %% Click Events
    click Application "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/config/Application.java"
    click DatabaseConfig "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/db/DatabaseConfig.java"
    click NotificationController "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/controller/NotificationController.java"
    click SubscriptionController "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/controller/SubscriptionController.java"
    click NotificationService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/service/NotificationService.java"
    click INotificationService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/service/INotificationService.java"
    click SubscriptionService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/service/SubscriptionService.java"
    click ISubscriptionService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/service/ISubscriptionService.java"
    click UserService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/service/UserService.java"
    click IUserService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/service/IUserService.java"
    click IPushService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/service/IPushService.java"
    click IUserRepository "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/repository/IUserRepository.java"
    click INotificationRepository "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/repository/INofiticationRepository.java"
    click SmsService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/utility/service/SmsService.java"
    click EmailService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/utility/service/EmailService.java"
    click AndroidPushService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/utility/service/AndroidPushService.java"
    click ApplePushService "https://github.com/p3arl/notification-service/blob/master/src/main/java/com/project/utility/service/ApplePushService.java"

    %% Styles
    classDef controller fill:#cce5ff,stroke:#007bff,color:#004085
    classDef service fill:#d4edda,stroke:#28a745,color:#155724
    classDef repository fill:#fff3cd,stroke:#ffc107,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#383d41
    classDef config fill:#f5c6cb,stroke:#dc3545,color:#721c24
    classDef utility fill:#d1ecf1,stroke:#17a2b8,color:#0c5460
    classDef database fill:#f8d7da,stroke:#dc3545,color:#721c24,stroke-dasharray: 5 5
```
