# mosip/id-authentication architecture

> Architecture diagram of the GitHub repository mosip/id-authentication, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mosip/id-authentication
- Repository: https://github.com/mosip/id-authentication

## Overview

##### Main Components
- API Exposure & Gateway: The system exposes various APIs to external clients (see the “APIs” section in the README and several modules with “controller” directories). These endpoints are grouped by functionality – some are part of the core authentication service, others provide OTP, KYC, or even esignet integration.
- Core Authentication Engine: The “authentication-core” and “authentication-common” directories hold the core logic and common libraries (managers, builders, filters, exception handlers, helper utilities, etc.) that are used by other parts of the system.
- Service & Filter Modules: Multiple modules target specialized functionality:
– authentication-filter-api: Contains interfaces and SPI for authentication filters.
– authentication-authtypelockfilter-impl, authentication-hotlistfilter-impl: Provide implementations for specific security or hotlist checking.
– authentication-internal-service: Provides internal-facing endpoints (and batch scripts for scheduled tasks like cleanup) and special configurations for internal authentication flows.
– authentication-otp-service: Dedicated to handling OTP requests and validations.
– authentication-service: Contains business logic controlling external authentication and KYC services, with controllers and facade implementations.
– esignet-integration-impl: Provides integration with esignet services (including DTOs and helper modules).
- Database: SQL scripts and upgrade scripts (under db_scripts and db_upgrade_scripts) indicate that the system relies on a relational database, with multiple tables (for API keys, transactions, hotlist caches, etc.). Represent the database as an external component that these modules interact with.
- Infrastructure/Docker: The Dockerfiles and deployment scripts indicate containerized deployments, as well as configuration files for Kubernetes deployment. Include a containerization element that wraps the microservices if needed.
- Messaging/Integration: Several modules reference Kafka configurations (e.g., within authentication-common) and websub components for event-driven interactions. Represent an integration/communication layer (e.g., message queues or event topics) connecting components that publish authentication events.

##### Relationships and Data Flow
- That the core libraries (authentication-core and authentication-common) are shared utilities used by multiple services.
- If applicable, indicate external integrations (such as esignet integration) that interface with third-party services.

##### Deployment & Build Elements
- Although not every Jenkins/CI/CD detail must be shown, you might note that build automation (Travis, GitHub workflows) is in place.

– External Clients/API Consumers (label with “REST API”)
– An API Gateway (or the exposed controllers)
– A centralized Database (or multiple DB components if needed, as suggested by the db_scripts)
– Event/Message Brokers for event-driven integration (Kafka/websub)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Client("REST API Client"):::external

    %% API Exposure Layer
    subgraph "API Exposure"
        ASController("Auth Service Controller"):::api
        ISController("Internal Service Controller"):::api
        OTController("OTP Service Controller"):::api
    end

    %% Service Modules Layer
    subgraph "Service Modules"
        AuthService("Authentication & KYC Service Module"):::service
        OTPService("OTP Service Module"):::service
        InternalService("Internal Authentication Service"):::service
        EsignetModule("Esignet Integration Module"):::service
    end

    %% Core Libraries and Filters Layer
    subgraph "Core Libraries"
        AuthCore("Authentication Core Library"):::core
        AuthCommon("Authentication Common Library"):::core
        FilterAPI("Authentication Filter API"):::filter
        AuthTypeLock("AuthTypeLock Filter Implementation"):::filter
        HotlistFilter("Hotlist Filter Implementation"):::filter
    end

    %% Infrastructure & Integration Layer
    subgraph "Infrastructure & Integration"
        Database("Relational Database"):::db
        Messaging("Messaging System (Kafka&WebSub)"):::messaging
        Docker("Docker/Deployment Config"):::docker
    end

    %% Connections from External Client to API Controllers
    Client -->|"HTTP/REST"| ASController
    Client -->|"HTTP/REST"| ISController
    Client -->|"HTTP/REST"| OTController

    %% API Controllers to Service Modules
    ASController -->|"handles externalAuth"| AuthService
    ISController -->|"handles internalAuth"| InternalService
    OTController -->|"handles OTP"| OTPService

    %% Service Modules Interaction
    AuthService -->|"invokes"| EsignetModule

    %% Service Modules using Core Libraries
    AuthService -->|"uses"| AuthCore
    AuthService -->|"uses"| AuthCommon
    OTPService -->|"uses"| AuthCore
    OTPService -->|"uses"| AuthCommon
    InternalService -->|"uses"| AuthCore
    InternalService -->|"uses"| AuthCommon
    EsignetModule -->|"uses"| AuthCommon

    %% Authentication Service applies Filters
    AuthService -->|"applies"| FilterAPI
    AuthService -->|"applies"| AuthTypeLock
    AuthService -->|"applies"| HotlistFilter

    %% Core Library publishing events
    AuthCommon -->|"publishes"| Messaging

    %% Service Modules database interactions
    AuthService -->|"reads/writes"| Database
    OTPService -->|"reads/writes"| Database
    InternalService -->|"reads/writes"| Database
    EsignetModule -->|"reads/writes"| Database

    %% Deployment connections to Docker
    ASController --> Docker
    ISController --> Docker
    OTController --> Docker
    AuthService --> Docker
    OTPService --> Docker
    InternalService --> Docker
    EsignetModule --> Docker
    AuthCore --> Docker
    AuthCommon --> Docker
    FilterAPI --> Docker
    AuthTypeLock --> Docker
    HotlistFilter --> Docker

    %% Click Events for API Exposure & Gateway
    click ASController "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-service/src/main/java/io/mosip/authentication/service/controller"
    click ISController "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/controller"
    click OTController "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-otp-service/src/main/java/io/mosip/authentication/otp/service/controller"

    %% Click Events for Core Authentication Engine
    click AuthCore "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-core"
    click AuthCommon "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-common"

    %% Click Events for Service & Filter Modules
    click FilterAPI "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-filter-api"
    click AuthTypeLock "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-authtypelockfilter-impl"
    click HotlistFilter "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-hotlistfilter-impl"
    click InternalService "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-internal-service"
    click OTPService "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-otp-service"
    click AuthService "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-service"
    click EsignetModule "https://github.com/mosip/id-authentication/tree/master/authentication/esignet-integration-impl"

    %% Click Event for Database
    click Database "https://github.com/mosip/id-authentication/tree/master/db_scripts"

    %% Click Event for Docker/Deployment
    click Docker "https://github.com/mosip/id-authentication/tree/master/docker"

    %% Click Event for Messaging/Integration
    click Messaging "https://github.com/mosip/id-authentication/tree/master/authentication/authentication-common/src/main/java/io/mosip/authentication/common/service/config"

    %% Class Definitions for styling
    classDef external fill:#fcc,stroke:#333,stroke-width:2px
    classDef api fill:#fce,stroke:#333,stroke-width:2px
    classDef service fill:#cfe,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef filter fill:#fc9,stroke:#333,stroke-width:2px
    classDef db fill:#cff,stroke:#333,stroke-width:2px
    classDef messaging fill:#ffc,stroke:#333,stroke-width:2px
    classDef docker fill:#d9f,stroke:#333,stroke-width:2px
```
