API & Class Design for Sign-in / Register Page
Problem Statement
Design the Low-Level Design (LLD) and API structure for a User Authentication module that powers a Sign-in and Register Page for a web or mobile application (like any modern app — e.g., Instagram, Swiggy, or LinkedIn).
The system should allow new users to register and existing users to sign in securely, while maintaining extensibility for future authentication features like OTP login, social login (Google/Facebook), and password reset.
🎯 Goal
Design the classes, APIs, and data flow for:
✅ Functional Requirements
1. User Registration (Sign-Up)
2. User Login (Sign-In)
3. Session / Token Management
4. Error Handling
⚙️ Non-Functional Requirements
🧱 Key Classes to Design
ClassResponsibility
User
Represents an application user (stores name, email, hashed password, status).
Credentials
Handles password hashing, verification, and comparison.
AuthService
Core service for registration, login, and token management.
TokenManager
Generates, validates, and expires access tokens.
UserRepository
Manages CRUD operations on user data (simulate DB).
ValidationService
Validates input formats and password strength.
AuthController (API Layer)
Handles REST endpoints for sign-in/sign-up.
ErrorResponse / ApiResponse
Standardized response wrapper for APIs.
🧩 Example Class Relationships
1
2User
3 ├── id
4 ├── name
5 ├── email
6 ├── hashedPassword
7 ├── status (ACTIVE / PENDING_VERIFICATION / DISABLED)
8 ├── createdAt
9 ├── updatedAt
10
11AuthService
12 ├── registerUser(name, email, password)
13 ├── login(email, password)
14 ├── logout(token)
15
16TokenManager
17 ├── generateToken(userId)
18 ├── validateToken(token)
19 ├── invalidateToken(token)🌐 Example API Endpoints
EndpointMethodDescription
/api/v1/auth/register
POST
Register a new user
/api/v1/auth/login
POST
Sign in with credentials
/api/v1/auth/logout
POST
Invalidate session token
/api/v1/auth/verify
GET
Verify email/OTP (optional)
🧪 Sample API Flow
🔸 Register Request:
1
2POST /api/v1/auth/register
3{
4 "name": "Sahil Batra",
5 "email": "sahil@example.com",
6 "password": "Strong@123"
7}✅ Response:
1
2{
3 "status": "success",
4 "message": "User registered successfully",
5 "userId": "U10239"
6}🔸 Login Request:
1
2POST /api/v1/auth/login
3{
4 "email": "sahil@example.com",
5 "password": "Strong@123"
6}✅ Response:
1
2{
3 "status": "success",
4 "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
5}🔸 Invalid Login:
1
2{
3 "status": "error",
4 "error": "Invalid credentials"
5}🔐 Security & Concurrency
🧠 Possible Extensions
✅ Final Summary:
Design an API and class structure for Sign-in / Register functionality that supports:
Focus on OOP modeling, authentication flow, and API contract design, not UI or database scaling.