How atharva759/authify works
1. This repo is a two-tier auth system: a Spring Boot backend (Backend/) and a React/Vite frontend (Frontend/). The backend is the system of record for users, authentication state, OTP verification, and JWT issuance; the frontend is a thin UI client.
2. The backend is organized into clear layers:
- Controller exposes HTTP endpoints.
- Service holds business logic.
- UserRepository persists data through Spring Data JPA.
- Entity defines the database model.
- dto carries request/response payloads.
- Config and util implement security and token handling.
This structure is the main architectural boundary for backend diagrams.
3. AuthController is the API entry point for the auth workflow. Based on the README, the key endpoints are registration, login, OTP send/verify, and a protected “me” endpoint. These endpoints orchestrate service calls rather than doing direct persistence or token logic.
4. UserEntity is the central persisted domain object. The repository layer (UserRepository) likely stores user credentials and profile/verification state in PostgreSQL via JPA. The app is not using a separate identity provider; authentication is self-managed in the backend.
5. Authentication is JWT-based. JwtUtil creates and validates tokens, while JwtAuthenticationFilter reads the JWT from the request cookie, validates it, and populates Spring Security’s context. SecurityConfig defines the security policy, including CORS, CSRF/session behavior, and which routes are public versus protected.
6. The login flow is cookie-centric rather than header-centric. The backend sets an HttpOnly JWT cookie (jwt per README), and the frontend sends requests with credentials enabled. That makes the browser cookie the bridge between UI and backend-authenticated requests.
7. OTP verification is handled as a separate email-based step. EmailService sends the OTP through SMTP/JavaMail and manages its lifecycle/expiry. ProfileService and/or auth services likely coordinate OTP generation, persistence, and verification against the user record or transient state.
8. AppUserDetailsService adapts persisted users to Spring Security’s user model. This is the lookup boundary where the security layer resolves a login identity from the stored user data before JWT creation or authenticated requests.
9. Error handling is centralized. GlobalExceptionHandler and ApiError provide a consistent API error shape, which is important for frontend integration and for keeping the auth flows predictable when login, OTP, or validation fails.
10. The frontend is a small client application with Register.jsx, Login.jsx, and Profile.jsx as the main screens, wired together by App.jsx and bootstrapped in main.jsx. The API boundary is isolated in src/api/api.js, which is where the browser talks to the backend base URL.
11. The frontend’s architectural role is presentation plus session-aware API calls. It does not own auth state authority; it submits credentials/OTP, receives responses, and relies on the backend-set cookie for subsequent authenticated calls like /auth/me.
12. Infrastructure-wise, the backend depends on PostgreSQL, Java 21, Spring Security, JPA, BCrypt, and SMTP. Build/runtime is Maven (pom.xml, wrapper scripts). The frontend is Vite-based React with package-managed local development and a separate dev server, typically on port 5173, talking to the backend over HTTP.
13. The minimal test footprint (AuthSystemApplicationTests) suggests the repo is primarily organized around functional application code rather than a large automated test suite. For architecture diagrams, the important production path is frontend → backend controller → service → repository/email/JWT/security → PostgreSQL/SMTP → response/cookie back to frontend.
Main entry points: AuthController.java Auth API · api.js API client · App.jsx App · ProfileService.java Profile svc
Components 17
Backend
Spring Boot auth API, security, persistence, and email flows.
- Auth API · HTTP entry point for register, login, OTP, and me flows.
Backend/src/main/java/com/authsystem/authsystem/Controller/AuthController.java - Profile svc · Coordinates profile lookup and OTP-related user state.
Backend/src/main/java/com/authsystem/authsystem/Service/ProfileService.java - Email svc · Sends OTP messages and manages delivery lifecycle.
Backend/src/main/java/com/authsystem/authsystem/Service/EmailService.java - User details · Loads persisted users into Spring Security's user model.
Backend/src/main/java/com/authsystem/authsystem/Service/AppUserDetailsService.java - User repo · Persistence gateway for user records.
Backend/src/main/java/com/authsystem/authsystem/UserRepository/UserRepository.java - User entity · Persisted user state for credentials, profile, and verification.
Backend/src/main/java/com/authsystem/authsystem/Entity/UserEntity.java - JWT util · Creates and validates JWTs.
Backend/src/main/java/com/authsystem/authsystem/util/JwtUtil.java - JWT filter · Reads the auth cookie, validates JWT, and populates context.
Backend/src/main/java/com/authsystem/authsystem/Config/JwtAuthenticationFilter.java - Security config · Defines route protection, CORS, and session/CSRF behavior.
Backend/src/main/java/com/authsystem/authsystem/Config/SecurityConfig.java - Errors · Normalizes API failures into consistent responses.
Backend/src/main/java/com/authsystem/authsystem/Exception/GlobalExceptionHandler.java - API error · Shared error payload returned to clients.
Backend/src/main/java/com/authsystem/authsystem/Exception/ApiError.java - DTOs · Request and response contracts for auth endpoints.
Backend/src/main/java/com/authsystem/authsystem/dto/LoginRequest.java
Frontend
React/Vite client UI and API boundary.
- App · Top-level client composition and routing.
Frontend/src/App.jsx - Register · Registration UI and OTP initiation.
Frontend/src/Register.jsx - Login · Login UI that submits credentials.
Frontend/src/Login.jsx - Profile · Authenticated profile view backed by cookie auth.
Frontend/src/Profile.jsx - API client · Browser-to-backend request layer and base URL handling.
Frontend/src/api/api.js
Connections 19
- App → Register: shows · App composes the registration screen.
- App → Login: shows · App composes the login screen.
- App → Profile: shows · App composes the profile screen.
- Register → API client: registers · Registration submits to backend endpoints via the API client.
- Login → API client: logs in · Login submits credentials through the API client.
- Profile → API client: me request · Profile fetches authenticated user data through cookie-backed requests.
- API client → Auth API: HTTP · Client calls the auth API over HTTP with credentials enabled.
- Auth API → DTOs: maps payloads · Controller binds request and response DTOs.
- Auth API → Profile svc: orchestrates · Controller delegates profile and OTP-related workflows.
- Auth API → JWT util: issues tokens · Login flow creates JWTs for authenticated sessions.
- Auth API → Errors: fails via · Controller errors are normalized by global handling.
- Profile svc → User repo: reads/writes · Profile service persists and retrieves user state.
- Profile svc → Email svc: sends otp · Profile or auth flow triggers OTP delivery.
- User repo → User entity: stores · Repository persists the user domain entity.
- User details → User repo: loads user · Security adapter resolves identities from stored users.
- JWT filter → JWT util: validates · Filter validates JWTs extracted from the cookie.
- JWT filter → Security config: enforced by · Security config installs the authentication filter.
- Security config → Auth API: protects routes · Security policy splits public and protected endpoints.
- Errors → API error: emits · Global handling returns a shared error shape.