How thnhan1/ibanking works
Project Type and Purpose
• This is a Spring Boot–based RESTful backend API for handling tuition payments at TDTU University.
• It exposes endpoints under /api/v1/ for authentication, tuition lookup, payment session creation, OTP handling, payment confirmation, and transaction history.
• It uses JWT for authentication/authorization, Mailtrap SMTP for OTP delivery, and PostgreSQL for persistence.
Main Architectural Layers & Components
a. Client Layer
• Web/Mobile frontend or API client (e.g., Postman, abc.http)
b. API & Security Layer
• Spring Security filters (JWT validation, CustomUserDetailsService)
• Controllers (AuthController, TuitionController, PaymentController, UserController)
c. Service Layer
• Business services (AuthService, PaymentService, TuitionService, OtpNotificationService, UserService, JwtService, CurrentUserService)
• Pessimistic locking and idempotency logic live here
d. Data Access Layer
• Spring Data JPA repositories (AccountRepository, PaymentTransactionRepository, StudentRepository, TuitionFeeRepository, UserRepository, OtpTokenRepository)
e. Persistence
• PostgreSQL database (entities: User, Account, Student, TuitionFee, PaymentTransaction, OtpToken, enums for statuses)
f. External Service
• Mailtrap SMTP (for sending OTP emails)
Relationships & Data Flow
• Client → HTTP Request → JWT Filter → Controllers → Services → Repositories → PostgreSQL
• Service → MailConfig → Mail Server (Mailtrap) → User email inbox
• Controllers validate via DTOs; Services map between DTOs and Entities; Repositories handle CRUD and locking.
• On login: AuthController → AuthService → JwtService → return JWT → client stores token.
• On payment session: PaymentController → PaymentService → generate OTP → OtpNotificationService → Mailtrap.
• On confirm: PaymentController → PaymentService (validate OTP, check balance, update entities) → Repository (pessimistic lock).
Key Patterns & Principles
• Layered (Controller → Service → Repository)
• DTOs separate API model from persistence model
• Dependency Injection (Spring-managed beans)
• JWT stateless auth
• Pessimistic locking for concurrency control
• Idempotency key support to prevent duplicate sessions
• Parameterized queries via Spring Data JPA to avoid SQL injection
Detailed Elements to Capture
• Security filter chain (JWT auth flow) preceding Controllers.
• Endpoint grouping by Controller.
• Service classes where OTP generation, idempotency, and locking occur.
• Database entities and how repositories map to them.
• Mail service integration for OTP delivery.
• Data flow for main user stories: login, tuition lookup, payment session creation, OTP confirmation, history retrieval.