How saishkulkarni/stock-market-springboot-thymeleaf works
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