# saishkulkarni/stock-market-springboot-thymeleaf architecture

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

- Interactive diagram: https://gitdiagram.com/saishkulkarni/stock-market-springboot-thymeleaf
- Repository: https://github.com/saishkulkarni/stock-market-springboot-thymeleaf

## Overview

##### Project Type and Purpose
- Full-stack web application
- Backend: Spring Boot (MVC pattern), Spring Data JPA
- Frontend: Thymeleaf templates (server-side rendered)
- Database: MySQL
- External integrations: Alpha Vantage API, Razorpay API, Java Mail Sender
- Role-based features: Admin (manage stocks) and User (register, recharge wallet, trade)

##### File Structure
- src/main/java/org/jsp/stocks
– controller: HTTP endpoints (StockController)
– service: business logic interfaces and implementations (StockService, StockServiceImpl, AES util)
– repository: Spring Data JPA repositories for User, Stock, AdminData, UserStocksTransaction
– dto: domain objects (User, Stock, AdminData, UserStocksTransaction)
– StockMarketApplication.java: Spring Boot entry point
- src/main/resources/templates: Thymeleaf views (login, register, portfolio, admin pages, etc.)
- application.properties: DB credentials, API keys, session settings
- build & deployment: Maven wrapper (mvnw), pom.xml

##### Core Architectural Components
A. Presentation Layer
- Browser → Thymeleaf views ← HTTP controllers
- Session management via HTTP Session attributes for admin and user roles
B. Web/API Layer
- Spring MVC controllers (StockController)
- Request → Controller → Service → Repository → DB
C. Service Layer
- Business logic (StockServiceImpl)
- AES utility for encryption
- RestTemplate calls to external APIs
D. Data Layer
- Spring Data JPA repositories interacting with MySQL
- Entities mapped to tables: users, stocks, transactions, admin_details
E. External Services
- Alpha Vantage REST API (fetch stock data on admin “Add Stock”)
- Razorpay REST API (wallet recharge / payment)
- Java Mail Sender (OTP email verification)

##### Relationships and Data Flows
- Admin “Add Stock” flow:
Browser → Controller → Service (RestTemplate → Alpha Vantage) → Repository → MySQL
- User Registration flow:
Browser → Controller → Service (Java Mail Sender sends OTP) → Repository → MySQL
- Wallet Recharge flow:
Browser → Controller → Service (Razorpay SDK/API) → Repository → MySQL
- Stock Purchase/Sale flow:
Browser → Controller → Service (validate wallet & transaction) → Repository (transactions table) → MySQL
- Session handling: session cookies stored in user’s browser, tracked in application memory

##### Architectural Patterns & Principles
- Layered (MVC) architecture
- Single-page templates, server-side rendering via Thymeleaf
- Dependency injection (Spring Boot)
- RESTful calls to external services
- Direct session management in lieu of Spring Security
- DAO pattern via Spring Data JPA repositories

- UI Layer: Browser & Thymeleaf templates
- Web Layer: HTTP Controllers
- Service Layer: Business services & AES utility
- Data Layer: JPA repositories & MySQL database
- External Clouds: Alpha Vantage, Razorpay, Mail Sender
- Session Store: HTTP session for user/admin
- Build/Run: Maven wrapper & Spring Boot entry point

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "UI Layer"
        Browser[(Browser)]:::frontend
        Templates["Thymeleaf Templates"]:::frontend
    end

    subgraph "Web/API Layer"
        Controller["StockController"]:::backend
    end

    subgraph "Service Layer"
        StockService["StockService"]:::backend
        StockServiceImpl["StockServiceImpl"]:::backend
        AES["AES Utility"]:::util
    end

    subgraph "Data Layer"
        subgraph "Entities"
            User["User (Entity)"]:::database
            StockEnt["Stock (Entity)"]:::database
            AdminData["AdminData (Entity)"]:::database
            TransactionEnt["UserStocksTransaction (Entity)"]:::database
        end
        subgraph "Repositories"
            UserRepo["UserRepository"]:::database
            StockRepo["StockRepository"]:::database
            AdminDataRepo["AdminDataRepository"]:::database
            TransactionRepo["UserStocksTransactionRepository"]:::database
        end
        DB[(MySQL DB)]:::database
    end

    subgraph "External Services"
        AlphaVantage["Alpha Vantage API"]:::external
        Razorpay["Razorpay API"]:::external
        Mail["Java Mail Sender"]:::external
    end

    Session[/"HTTP Session Store"/]:::backend
    Entry["StockMarketApplication"]:::entry
    Build["Maven & Wrapper"]:::build
    Test["StockMarketApplicationTests"]:::test

    %% Flows
    Browser --> Templates
    Browser --> Controller
    Controller --> StockService
    Controller --> Session
    StockService --> StockServiceImpl
    StockServiceImpl --> AES
    StockServiceImpl --> AlphaVantage
    StockServiceImpl --> Razorpay
    StockServiceImpl --> Mail
    StockServiceImpl --> UserRepo
    StockServiceImpl --> StockRepo
    StockServiceImpl --> AdminDataRepo
    StockServiceImpl --> TransactionRepo

    UserRepo --> User
    StockRepo --> StockEnt
    AdminDataRepo --> AdminData
    TransactionRepo --> TransactionEnt

    UserRepo --> DB
    StockRepo --> DB
    AdminDataRepo --> DB
    TransactionRepo --> DB

    Entry --> Controller
    Entry --> StockService
    Entry --> UserRepo
    Build --> Entry
    Test --> Entry

    %% Click Events
    click Templates "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/tree/master/src/main/resources/templates"
    click Controller "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/controller/StockController.java"
    click Entry "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/StockMarketApplication.java"
    click StockService "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/service/StockService.java"
    click StockServiceImpl "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/service/implementation/StockServiceImpl.java"
    click AES "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/service/implementation/AES.java"
    click User "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/dto/User.java"
    click StockEnt "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/dto/Stock.java"
    click AdminData "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/dto/AdminData.java"
    click TransactionEnt "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/dto/UserStocksTransaction.java"
    click UserRepo "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/repository/UserRepository.java"
    click StockRepo "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/repository/StockRepository.java"
    click AdminDataRepo "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/repository/AdminDataRepository.java"
    click TransactionRepo "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/main/java/org/jsp/stocks/service/UserStocksTransactionRepository.java"
    click Build "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/tree/master/mvnw"
    click Build "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/.mvn/wrapper/maven-wrapper.properties"
    click Build "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/pom.xml"
    click Test "https://github.com/saishkulkarni/stock-market-springboot-thymeleaf/blob/master/src/test/java/org/jsp/stocks/StockMarketApplicationTests.java"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#00838F,color:#006064;
    classDef backend fill:#C8E6C9,stroke:#388E3C,color:#1B5E20;
    classDef database fill:#FFE0B2,stroke:#F57C00,color:#E65100;
    classDef external fill:#CFD8DC,stroke:#90A4AE,color:#37474F;
    classDef util fill:#D1C4E9,stroke:#7B1FA2,color:#4A148C;
    classDef entry fill:#B2DFDB,stroke:#00796B,color:#004D40;
    classDef build fill:#F0F4C3,stroke:#AFB42B,color:#827717;
    classDef test fill:#FFCDD2,stroke:#E53935,color:#B71C1C;
```
