# siddharthp02/lpay architecture

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

- Interactive diagram: https://gitdiagram.com/siddharthp02/lpay
- Repository: https://github.com/siddharthp02/lpay

## Overview

##### Project Type and Purpose
- This is a full-stack, microservices-style simulation of a UPI payment ecosystem (“Lpay – a UPI Clone”)
- Key components:
- UPI Client (Thymeleaf front-end + Spring Boot REST client)
- UPI Server (handles user registration, login, UPI ID generation)
- NPCI Server (central switch that orchestrates transactions)
- Bank Server(s) (one or more bank APIs managing accounts and balances)
- Databases (MySQL instances per server)

##### File Structure
- Top-level directories: “Client copy” (UPI Client), “UPI Server”, “NPCI Server”, “Bank Server”
- Each service follows the standard Spring Boot layout:
- src/main/java/com/.../controller (REST controllers)
- …/service + …/service/impl (business logic)
- …/repository (JPA interfaces)
- …/entity/domain (data models)
- src/main/resources/application.properties (DB config)
- templates/ (Thymeleaf HTML) for front‐ends
- Maven build files (pom.xml, mvnw) and test directories present per microservice

##### README Insights
- Architecture described as 3 servers + 1 client, all Spring-Boot REST APIs, front-end via Thymeleaf
- Uses MySQL for persistence

##### Components & Interactions
- UPI Client (Browser + Thymeleaf UI + REST client module)
- UPI Server (Spring Boot service)
- NPCI Server (Spring Boot orchestration service)
- Bank Server(s) (one or more identical Spring Boot services)
- Optional: Log store (file or centralized logging service)
1. User → UPI Client UI (HTTP)
2. UPI Client → UPI Server (REST call: registration, login, fetch balance)
3. UPI Server ↔ MySQL (JPA)
4. UPI Server → NPCI Server (REST: transaction request)
5. NPCI Server ↔ MySQL (JPA for NPCI accounts, logs)
6. NPCI Server → Bank Server A & B (REST: debit/credit calls)
7. Bank Servers ↔ their MySQL (account/transaction tables)
8. Each server → centralized log (or local log files)
9. Responses flow back in reverse order
c. Architectural Patterns & Principles:
- Microservices per domain (client, UPI, NPCI, bank)
- Layered (Controller → Service → Repository → DB)
- RESTful APIs for inter-service communication
- Domain-driven entities for accounts, transactions, users
- Separation of concerns (UI vs business vs persistence)
d. Key Technologies:
- Java 17+ / Spring Boot (Web, Data JPA, Security)
- Thymeleaf for client templates
- MySQL for persistence
- Maven for build
- Spring Security (custom user details, WebSecurityConfig)

##### Detailed Guidance
[Controller] → [Service] → [Repository]
This highlights your MVC pattern inside each service.
- Don’t overcrowd—capture only essential data flows and components

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interaction
    User["User"]:::external
    User -->|"1. Interacts via HTTP"| UPIClientClient

    %% UPI Client
    subgraph "UPI Client"  
        direction TB
        UPIClientClient["Thymeleaf UI & REST Client"]:::frontend
        UPIClientClient -->|"Calls REST API"| UPIClientController
        UPIClientController["Client Controller"]:::backend
        UPIClientController -->|"Invokes"| UPIClientService
        UPIClientService["Client Service"]:::backend
        UPIClientService -->|"Uses JPA"| UPIClientRepo
        UPIClientRepo["Client Repository"]:::backend
        UPIClientClient -->|"Loads Templates"| Templates
        UPIClientClient -->|"Reads Config"| ClientConfig
        UPIClient -->|"Directory"| UPIClientDir
    end

    %% UPI Server
    subgraph "UPI Server"
        direction TB
        UPIController["UserController"]:::backend
        UPIService["UserService"]:::backend
        UPIServiceImpl["UserServiceImpl"]:::backend
        UPIRepo["UserRepository & MyTransactionRepository"]:::backend
        UPIController -->|"Calls"| UPIService
        UPIService -->|"Implements"| UPIServiceImpl
        UPIServiceImpl -->|"Uses JPA"| UPIRepo
        UPIDB["MySQL (UPI Server)"]:::db
        UPIRepo --> UPIDB
        UPIMain["UpiSystemApplication"]:::backend
        UPITemplates["Thymeleaf Templates"]:::frontend
        UPIConfig["application.properties"]:::backend
    end

    %% NPCI Server
    subgraph "NPCI Server"
        direction TB
        NPCIController["NPCIController"]:::backend
        NPCIService["NPCIService"]:::backend
        NPCIServiceImpl["NPCIServiceImpl"]:::backend
        NPCIRepos["Repositories"]:::backend
        NPCIDomain["Domain Entities"]:::backend
        NPCIController -->|"Invokes"| NPCIService
        NPCIService -->|"Implements"| NPCIServiceImpl
        NPCIServiceImpl -->|"Uses"| NPCIRepos & NPCIDomain
        NPCIDB["MySQL (NPCI)"]:::db
        NPCIRepos --> NPCIDB
        NPCIConfig["application.properties"]:::backend
    end

    %% Bank Servers
    subgraph "Bank Servers"
        direction TB
        subgraph "Bank Server A"
            direction TB
            BankAController["apiController"]:::backend
            BankAEntity["Entities"]:::backend
            BankARepo["Repositories"]:::backend
            BankAResponse["ResponseHandler"]:::backend
            BankADB["MySQL (Bank A)"]:::db
            BankAController -->|"Uses"| BankARepo
            BankARepo --> BankADB
        end
        subgraph "Bank Server B"
            direction TB
            BankBController["apiController"]:::backend
            BankBEntity["Entities"]:::backend
            BankBRepo["Repositories"]:::backend
            BankBResponse["ResponseHandler"]:::backend
            BankBDB["MySQL (Bank B)"]:::db
            BankBController -->|"Uses"| BankBRepo
            BankBRepo --> BankBDB
        end
    end

    %% Logging
    Log["Log Store"]:::log

    %% Inter-Service Flows
    UPIClientController -->|"2. POST /register, /login"| UPIController
    UPIController -->|"3. JPA operations"| UPIDB
    UPIController -->|"4. POST /transactionRequest"| NPCIController
    NPCIController -->|"5. JPA operations"| NPCIDB
    NPCIController -->|"6. REST debit/credit"| BankAController
    NPCIController -->|"6. REST debit/credit"| BankBController
    BankAController -->|"7. JPA operations"| BankADB
    BankBController -->|"7. JPA operations"| BankBDB
    UPIController -->|"8. Logs"| Log
    NPCIController -->|"8. Logs"| Log
    BankAController -->|"8. Logs"| Log
    BankBController -->|"8. Logs"| Log
    BankAController -->|"9. Response"| NPCIController
    BankBController -->|"9. Response"| NPCIController
    NPCIController -->|"9. Response"| UPIController
    UPIController -->|"9. Response"| UPIClientController
    UPIClientController -->|"9. Render UI"| UPIClientClient

    %% Click Events
    click UPIClientDir "https://github.com/siddharthp02/lpay/tree/master/Client copy/"
    click UPIClientController "https://github.com/siddharthp02/lpay/tree/master/Client copy/src/main/java/net/javaguides/sms/controller/"
    click UPIClientService "https://github.com/siddharthp02/lpay/tree/master/Client copy/src/main/java/net/javaguides/sms/service/"
    click UPIClientRepo "https://github.com/siddharthp02/lpay/tree/master/Client copy/src/main/java/net/javaguides/sms/repository/"
    click WebSecurityConfig "https://github.com/siddharthp02/lpay/blob/master/Client copy/src/main/java/net/javaguides/sms/security/WebSecurityConfig.java"
    click Templates "https://github.com/siddharthp02/lpay/tree/master/Client copy/src/main/resources/templates/"
    click ClientConfig "https://github.com/siddharthp02/lpay/blob/master/Client copy/src/main/resources/application.properties"
    click UPIMain "https://github.com/siddharthp02/lpay/blob/master/UPI Server/src/main/java/net/javaguides/sms/UpiSystemApplication.java"
    click UPIController "https://github.com/siddharthp02/lpay/blob/master/UPI Server/src/main/java/net/javaguides/sms/controller/UserController.java"
    click UPIService "https://github.com/siddharthp02/lpay/blob/master/UPI Server/src/main/java/net/javaguides/sms/service/UserService.java"
    click UPIServiceImpl "https://github.com/siddharthp02/lpay/blob/master/UPI Server/src/main/java/net/javaguides/sms/service/impl/UserServiceImpl.java"
    click UPIRepo "https://github.com/siddharthp02/lpay/blob/master/UPI Server/src/main/java/net/javaguides/sms/repository/UserRepository.java"
    click UPITemplates "https://github.com/siddharthp02/lpay/tree/master/UPI Server/src/main/resources/templates/"
    click UPIConfig "https://github.com/siddharthp02/lpay/blob/master/UPI Server/src/main/resources/application.properties"
    click NPCIMain "https://github.com/siddharthp02/lpay/blob/master/NPCI Server/src/main/java/com/OOAD/NPCI/NpciApplication.java"
    click NPCIController "https://github.com/siddharthp02/lpay/blob/master/NPCI Server/src/main/java/com/OOAD/NPCI/Controller/NPCIController.java"
    click NPCIService "https://github.com/siddharthp02/lpay/blob/master/NPCI Server/src/main/java/com/OOAD/NPCI/services/NPCIService.java"
    click NPCIServiceImpl "https://github.com/siddharthp02/lpay/blob/master/NPCI Server/src/main/java/com/OOAD/NPCI/services/impl/NPCIServiceImpl.java"
    click NPCIRepos "https://github.com/siddharthp02/lpay/tree/master/NPCI Server/src/main/java/com/OOAD/NPCI/Repositories/"
    click NPCIDomain "https://github.com/siddharthp02/lpay/tree/master/NPCI Server/src/main/java/com/OOAD/NPCI/domain/"
    click NPCIConfig "https://github.com/siddharthp02/lpay/blob/master/NPCI Server/src/main/resources/application.properties"
    click BankServerDir "https://github.com/siddharthp02/lpay/tree/master/Bank Server/"
    click BankAController "https://github.com/siddharthp02/lpay/blob/master/Bank Server/src/main/java/com/bank/bankServer/Controller/apiController.java"
    click BankAEntity "https://github.com/siddharthp02/lpay/tree/master/Bank Server/src/main/java/com/bank/bankServer/Entity/"
    click BankARepo "https://github.com/siddharthp02/lpay/tree/master/Bank Server/src/main/java/com/bank/bankServer/Repository/"
    click BankAResponse "https://github.com/siddharthp02/lpay/blob/master/Bank Server/src/main/java/com/bank/bankServer/Response/ResponseHandler.java"
    click BankADB "https://github.com/siddharthp02/lpay/blob/master/Bank Server/src/main/resources/application.properties"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#000;
    classDef backend fill:#ffafcc,stroke:#000;
    classDef db fill:#bde0fe,stroke:#000;
    classDef log fill:#ffe066,stroke:#000;
    classDef external fill:#cdb4db,stroke:#000;
```
