# gautamkr538/oauth2loginwithjwt architecture

> Architecture diagram of the GitHub repository gautamkr538/oauth2loginwithjwt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gautamkr538/oauth2loginwithjwt
- Repository: https://github.com/gautamkr538/oauth2loginwithjwt

## Overview

##### Project type and purpose
- This is a standalone Spring Boot microservice whose sole responsibility is to handle user authentication and authorization via Google OAuth 2.0, issue JWTs, and manage refresh tokens.
- There is no separate “frontend” folder, and all code lives under src/main/java, indicating a back-end service.

##### File structure
- Top-level artifacts
- pom.xml / mvnw: this is a Maven-based Java project.
- src/main/java/com/oath/login: contains all source code.
- src/main/resources/application.properties + schema.sql: configuration and DB schema.
- Layered folders under com.oath.login:
- config: security and bean setup (SecurityConfig, JwtService, filters, etc.)
- controller: REST entry points (AuthController, OAuth2CallbackController)
- service: business logic (AuthService, RefreshTokenService)
- repository: DB access (UserRepository, RefreshTokenRepository)
- model: domain objects and JPA entities (User, RefreshToken)
- dto: data‐transfer objects for request/response
- exception: custom exceptions and global handler
- Testing
- src/test/java contains a basic SpringBootTest suite.

##### README for additional insights
- The README is a placeholder, so we rely wholly on code structure for architectural inference.

a. Main components
1. Client (mobile or web application)
2. API Gateway or client consumer that calls our AuthService endpoints
3. AuthController – exposes endpoints:
- /auth/login (email/password)
- /auth/refresh
- /oauth2/callback (Google OAuth2 redirect)
4. SecurityConfig + JwtAuthenticationFilter – intercepts requests, validates JWT
5. JwtService – creates/verifies tokens
6. AuthService & RefreshTokenService – core business logic
7. Repositories (UserRepository, RefreshTokenRepository) – JPA interface to relational DB
8. Database – stores user info and refresh tokens
9. External Google OAuth 2.0 Provider
b. Relationships & data flow
- Client → AuthController: sends credentials or OAuth redirect
- AuthController → AuthService/RefreshTokenService
- AuthService → JwtService (generate access token)
- AuthService/RefreshTokenService → Repositories (persist or load tokens)
- SecurityConfig + JwtFilter → intercept all protected calls, consult JwtService → allow/deny
- OAuth callback → OAuth2CallbackController → AuthService
- AuthService → Google OAuth provider (token exchange)
- Database ←→ Repositories
c. Architectural patterns/design principles
- Layered architecture (Controller → Service → Repository)
- Dependency injection via BeanConfig and Spring annotations
- JWT‐based stateless authentication with an optional stateful refresh token store
- Exception handling via GlobalExceptionHandler
d. Key technologies/frameworks
- Spring Boot, Spring Security, Spring Data JPA, Maven
- JWT library (built into JwtService)
- Google OAuth 2.0 API (HTTP calls or Spring OAuth clients)
- H2 or MySQL/PostgreSQL (depending on application.properties)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    Client["Client (Web/Mobile)"]:::external
    GoogleOAuth["Google OAuth 2.0 Provider"]:::external
    Database[(Relational DB)]:::external

    %% Main Application
    MainApp["GoogleLoginOath2Application"]:::main

    %% Security & Config Layer
    subgraph "Configuration Layer"
        direction TB
        BeanCfg["BeanConfig"]:::config
        SecCfg["SecurityConfig"]:::config
        JwtFilter["JwtAuthenticationFilter"]:::config
        JwtSvc["JwtService"]:::config
    end

    %% Controllers
    subgraph "Controller Layer"
        direction TB
        AuthCtrl["AuthController"]:::controller
        OAuth2CbCtrl["OAuth2CallbackController"]:::controller
    end

    %% Services
    subgraph "Service Layer"
        direction TB
        AuthSvc["AuthService"]:::service
        RefreshSvc["RefreshTokenService"]:::service
    end

    %% Repositories
    subgraph "Repository Layer"
        direction TB
        UserRepo["UserRepository"]:::repo
        RefreshRepo["RefreshTokenRepository"]:::repo
    end

    %% Models
    subgraph "Model Layer"
        direction TB
        UserModel["User"]:::model
        RefreshModel["RefreshToken"]:::model
    end

    %% DTOs
    subgraph "DTO Layer"
        direction TB
        AuthReq["AuthRequest"]:::dto
        AuthRes["AuthResponse"]:::dto
        RefreshReq["RefreshTokenRequest"]:::dto
    end

    %% Exceptions
    subgraph "Exception Layer"
        direction TB
        AuthEx["AuthException"]:::exception
        GlobalEx["GlobalExceptionHandler"]:::exception
    end

    %% Application Flow
    Client -->|"credentials / OAuth redirect"| JwtFilter
    JwtFilter -->|"passes if valid or bypass login"| AuthCtrl
    AuthCtrl -->|"login / refresh / OAuth callback"| AuthSvc
    OAuth2CbCtrl -->|"OAuth code"| AuthSvc
    AuthSvc -->|"validate / load user"| UserRepo
    AuthSvc -->|"persist token"| RefreshRepo
    AuthSvc -->|"generate JWT"| JwtSvc
    JwtSvc -->|"JWT"| AuthCtrl
    AuthSvc -->|"exchange code / tokens"| GoogleOAuth
    RefreshSvc -->|"load/persist token"| RefreshRepo
    AuthCtrl -->|"return AuthResponse / tokens"| Client

    UserRepo -->|reads/writes| Database
    RefreshRepo -->|reads/writes| Database

    %% Exception Handling
    AuthEx -->|thrown| GlobalEx
    GlobalEx -->|handles| AuthCtrl

    %% Initialization
    MainApp --> BeanCfg
    MainApp --> SecCfg

    %% Click Events
    click MainApp "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/GoogleLoginOath2Application.java"
    click BeanCfg "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/config/BeanConfig.java"
    click SecCfg "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/config/SecurityConfig.java"
    click JwtFilter "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/config/JwtAuthenticationFilter.java"
    click JwtSvc "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/config/JwtService.java"
    click AuthCtrl "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/controller/AuthController.java"
    click OAuth2CbCtrl "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/controller/OAuth2CallbackController.java"
    click AuthSvc "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/service/AuthService.java"
    click RefreshSvc "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/service/RefreshTokenService.java"
    click UserRepo "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/repository/UserRepository.java"
    click RefreshRepo "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/repository/RefreshTokenRepository.java"
    click UserModel "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/model/User.java"
    click RefreshModel "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/model/RefreshToken.java"
    click AuthReq "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/dto/AuthRequest.java"
    click AuthRes "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/dto/AuthResponse.java"
    click RefreshReq "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/dto/RefreshTokenRequest.java"
    click AuthEx "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/exception/AuthException.java"
    click GlobalEx "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/java/com/oath/login/exception/GlobalExceptionHandler.java"
    click Database "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/resources/schema.sql"
    click Database "https://github.com/gautamkr538/oauth2loginwithjwt/blob/main/src/main/resources/application.properties"

    %% Styles
    classDef external fill:#ffe4b2,stroke:#ff8c00,color:#000
    classDef main fill:#d0e0fc,stroke:#4578a4,color:#000
    classDef config fill:#e8f1f8,stroke:#6b8ba4,color:#000
    classDef controller fill:#fde2e2,stroke:#d67a7a,color:#000
    classDef service fill:#e2f4e9,stroke:#6aa77b,color:#000
    classDef repo fill:#f0eaf4,stroke:#a569b5,color:#000
    classDef model fill:#fff5cc,stroke:#d4b200,color:#000
    classDef dto fill:#f0f5ff,stroke:#5a7dff,color:#000
    classDef exception fill:#ffe6e6,stroke:#e05050,color:#000
```
