How ssaisriharsha/otp-authentication works
Project Type and Purpose
• Type: Standalone backend microservice (Spring Boot monolith).
• Purpose: Expose REST endpoints to (a) generate OTPs for a given mobile number, (b) verify submitted OTPs.
• API Consumers: mobile apps, web front-ends, other backend services.
Main Components
1. Clients (External)
– Mobile App
– Web App
– Other Services
2. API Layer (Presentation)
– VerificationController
– Exception Handler (VerificationControllerAdvice)
3. Business Logic Layer
– VerificationService (core OTP generation & validation)
4. Data Layer
– In-memory store (e.g., ConcurrentHashMap) or external cache/DB (Redis, SQL) for persisting OTPs
5. Integration Layer (External Services)
– SMS Gateway (e.g., Twilio) for sending OTPs
6. Cross-Cutting Configuration
– CORS Config (CorsConfig)
– Spring Security (if extended)
– application.properties (configuration)
Relationships and Data Flows
1. Client → API Layer
• “POST /otp” to request OTP
• “POST /otp/verify” to validate OTP
2. API Layer → Business Logic
• Controller calls VerificationService
3. Business Logic → Data Layer
• Store generated OTP with timestamp
• Retrieve and compare OTP on verify
4. Business Logic → External SMS Gateway
• Send SMS with generated OTP
5. Data Layer → Business Logic
• Return stored OTP for comparison
6. API Layer → Client
• Return success/failure responses (GetOtpResponse, Validated DTO)
Architectural Patterns and Principles
• Layered Architecture: clear separation of Controller (API), Service (business logic), Data Store
• DTOs: used for request/response payloads (PhNo, GetOtpResponse, Validated)
• Exception-Handling Advice: centralized error handling via VerificationControllerAdvice
• Configuration as Code: CORS, security, externalized properties
Technologies and Frameworks
• Java 17 (or your target Java version)
• Spring Boot (autoconfiguration, embedded Tomcat)
• Maven for build and dependency management
• (Optional) SMS provider SDK (e.g., Twilio Java)
• (Optional) Redis or relational DB