# ndlam0211/auth-service architecture

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

- Interactive diagram: https://gitdiagram.com/ndlam0211/auth-service
- Repository: https://github.com/ndlam0211/auth-service

## Overview

##### Project type and purpose
- This is a Java-based microservices system composed of:
- api-gateway – Spring Cloud Gateway
- auth-service – a JWT/RBAC authentication & authorization microservice
- eureka-server – Spring Cloud Netflix Eureka service registry
- Purpose: route client traffic, secure endpoints via JWT and roles, and perform service discovery.

##### File structure
- Three top-level modules, each with its own Maven wrapper and pom.xml:
- api-gateway: HTTP entrypoint, routing rules in GatewayConfig.java
- auth-service: full Spring Boot app with controllers, services, repositories, JWT filter, Flyway migrations
- eureka-server: simple Spring Boot Eureka registry
- The presence of application.yml/properties in each suggests per-service configuration.
- auth-service uses Flyway (db/migration) to initialize its database schema.

##### Key architecture patterns
- Microservices with centralized service registry (Eureka)
- API Gateway pattern for routing and cross-cutting concerns (security, CORS)
- Token-based authentication (JWT)
- Role-based access control via annotations and AOP (PermissionAspect)

##### Main components and how they interact
a. Clients (web/mobile)
b. API Gateway
c. Service Registry (Eureka)
d. Auth Service
e. Auth Service’s relational Database
f. (Future) downstream microservices

Interaction flow:
1. Client → API Gateway: all HTTP requests pass through the gateway.
2. API Gateway ↔ Eureka: on startup & periodically fetches the list of registered services.
3. API Gateway → Auth Service: routes authentication-related endpoints (e.g., /login, /refresh, /users).
4. Auth Service ↔ Database: persistent storage for users, tokens, permissions.
5. Auth Service returns JWT to Client via Gateway.
6. Subsequent Client calls include JWT → API Gateway, which validates or forwards to Auth Service’s JwtAuthFilter.

##### Final checklist
- [ ] All components labeled (Client, API Gateway, Eureka Server, Auth Service, Auth DB)
- [ ] Annotations for key frameworks/patterns (JWT, RBAC, Flyway migrations)

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Clients"
    Client["Clients\n(Web/Mobile)"]:::client
  end

  subgraph "Edge"
    subgraph "API Gateway"
      Gateway["API Gateway\n(Spring Cloud Gateway)"]:::gateway
      ApiApp["ApiGatewayApplication"]:::file
      GWConfig["GatewayConfig"]:::file
      GWYML["application.yml"]:::file
    end
  end

  subgraph "Service Registry"
    Eureka["Eureka Server\n(Spring Cloud Netflix Eureka)"]:::registry
    EurekaApp["EurekaApplication"]:::file
    EurekaProp["application.properties"]:::file
  end

  subgraph "Auth Service"
    AuthService["Auth Service\n(Spring Boot, JWT, Flyway)"]:::service
    AuthApp["EcommerceApplication"]:::file
    SecurityConfig["SecurityConfig"]:::file
    JwtConfig["JwtConfig"]:::file
    JwtUtil["JwtUtil"]:::file
    JwtFilter["JwtAuthFilter"]:::file
    PermissionAspect["PermissionAspect"]:::file
    PermissionEval["CustomPermissionEvaluator"]:::file
    AuthController["AuthController"]:::file
    UserController["UserController"]:::file
    Flyway["db/migration"]:::file
    GlobalEx["GlobalExceptionHandler"]:::file
    BaseRepo["BaseRepo"]:::file
    BaseService["BaseServiceInterface"]:::file
    AuthService --> PermissionAspect
  end

  AuthDB["Auth DB\n(PostgreSQL/MySQL)"]:::database

  subgraph "Future Services"
    Other["Other Microservices"]:::future
  end

  Client -->|HTTP requests| Gateway
  Gateway -->|"Service Discovery"| Eureka
  Eureka -->|"Registry Updates"| Gateway
  Gateway -->|"Auth Endpoints"| AuthService
  AuthService -->|"JDBC (Flyway)"| AuthDB
  AuthService -->|"JWT issuance/validation"| Gateway
  Gateway -.->|"Future routing"| Other

  click ApiApp "https://github.com/ndlam0211/auth-service/blob/main/api-gateway/src/main/java/com/example/gateway/ApiGatewayApplication.java"
  click GWConfig "https://github.com/ndlam0211/auth-service/blob/main/api-gateway/src/main/java/com/example/gateway/config/GatewayConfig.java"
  click GWYML "https://github.com/ndlam0211/auth-service/blob/main/api-gateway/src/main/resources/application.yml"
  click EurekaApp "https://github.com/ndlam0211/auth-service/blob/main/eureka-server/src/main/java/com/example/eureka/EurekaApplication.java"
  click EurekaProp "https://github.com/ndlam0211/auth-service/blob/main/eureka-server/src/main/resources/application.properties"
  click AuthApp "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/EcommerceApplication.java"
  click SecurityConfig "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/config/SecurityConfig.java"
  click JwtConfig "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/config/JwtConfig.java"
  click JwtUtil "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/security/JwtUtil.java"
  click JwtFilter "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/security/JwtAuthFilter.java"
  click PermissionAspect "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/aspects/PermissionAspect.java"
  click PermissionEval "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/config/CustomPermissionEvaluator.java"
  click AuthController "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/modules/user/controllers/AuthController.java"
  click UserController "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/modules/user/controllers/UserController.java"
  click Flyway "https://github.com/ndlam0211/auth-service/tree/main/auth-service/src/main/resources/db/migration"
  click GlobalEx "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/exceptions/GlobalExceptionHandler.java"
  click BaseRepo "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/repositories/BaseRepo.java"
  click BaseService "https://github.com/ndlam0211/auth-service/blob/main/auth-service/src/main/java/com/example/ecommerce/services/BaseServiceInterface.java"

  classDef client fill:#cccccc,stroke:#333,stroke-width:1px
  classDef gateway fill:#cce5ff,stroke:#004085,stroke-width:1px
  classDef registry fill:#cce5ff,stroke:#004085,stroke-width:1px
  classDef service fill:#cce5ff,stroke:#004085,stroke-width:1px
  classDef database fill:#d4edda,stroke:#155724,stroke-width:1px,stroke-dasharray: 5 5
  classDef future fill:#eeeeee,stroke:#666,stroke-width:1px,stroke-dasharray: 2 2
  classDef aspect fill:#f8d7da,stroke:#721c24,stroke-width:1px
  classDef file fill:#fff3cd,stroke:#856404,stroke-width:1px
```
