# mrin9/angular-springboot-rest-jwt architecture

> Architecture diagram of the GitHub repository mrin9/angular-springboot-rest-jwt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrin9/angular-springboot-rest-jwt
- Repository: https://github.com/mrin9/angular-springboot-rest-jwt

## Overview

##### Main Components
- Frontend (Angular):
– Represent the Angular application found under the “webui” folder (with its source files in webui/src and production files in webui/dist).
– Show core subcomponents such as Angular Components, Services (e.g., API request, customer/employee/order/product services), Directives, and Pages (like Login, Dashboard, Orders, Customers, etc.).
– Include Angular routing and guards (authentication routes and lazy data load).
- Backend (Spring Boot):
– Highlight the Service and Model layers (e.g., “UserService”, various model packages such as model/customer, model/order, etc.).
– Include the Repository layer (found in “com/app/repo”) that uses Spring Data/JPA to interact with an H2 in-memory database.
– Illustrate the Configuration components (e.g., SecurityConfig, CorsFilter, SwaggerConfig, VerifyTokenFilter) that set up API security (with JWT token generation/validation) and API documentation.
– Include Identity management classes (TokenUtil, TokenUser, UserAuthentication) for managing token-based authentication.
- Database:
- API Documentation:
– Show integration with Swagger and ReDoc (via the Swagger UI assets and endpoints) to document and test APIs.
- Build/Deployment Artifacts:
– Include build scripts (pom.xml, build.gradle) and describe how the frontend (webui/dist) is statically served by the backend via the “src/main/resources/public” path.
– Note that the backend, when built, packages the static Angular build, so both front and backend run on the same port (9119).

##### Relationships and Data Flow
- Authentication flow: The client sends a login request, receives a JWT, and then includes the token in headers to access secured endpoints.
- From the controller layer in the backend, show how requests flow to the service layer and then to the repository layer, culminating in the database interactions.
- Additional cross-cutting components like the GlobalExceptionHandler and CORS configuration that maintain system robustness and security.

##### Architectural Patterns and Design Principles
- Layered architecture – clearly separate Presentation (Angular client), Business Logic (Spring controllers/services), and Data Access (JPA repositories).
- Use of token-based security enforced via Spring Security and JWT.
- Integration pattern where the compiled Angular distribution is served as static content by the Spring Boot backend (through the “public” directory).
- Pattern for documentation and testing (Swagger/ReDoc integration).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Angular)"
        A1["Angular Application"]:::angularStyle
        A2["Angular Source Files (src)"]:::angularStyle
        A3["Angular Production Build (dist)"]:::angularStyle
        A4["Angular Components/Services/Pages (app)"]:::angularStyle
        A5["Angular Routing Module (app-routing.module.ts)"]:::angularStyle
    end

    subgraph "Backend (Spring Boot)"
        B1["Spring Boot Main Application"]:::springStyle
        B2["REST Controllers"]:::springStyle
        B3["Service Layer"]:::springStyle
        B4["Model Layer"]:::springStyle
        B5["Repository Layer"]:::springStyle
        B6["Configuration Components"]:::springStyle
        B7["Identity Management"]:::springStyle
        B8["Static Content (Angular Build served)"]:::springStyle
    end

    subgraph "Database, API Docs & Deployment"
        D1(("H2 Database")):::dbStyle
        D2["schema.sql"]:::dbStyle
        D3["data.sql"]:::dbStyle
        D4["Swagger UI"]:::apiDocStyle
        D5["ReDoc UI"]:::apiDocStyle
        D6["Maven Build Script (pom.xml)"]:::buildStyle
        D7["Gradle Build Script (build.gradle)"]:::buildStyle
    end

    %% Data flow between Frontend and Backend
    A4 -->|"login/APICall"| B2
    B2 -->|"calls_service"| B3
    B3 -->|"invokes_repository"| B5
    B5 -->|"queries"| D1
    D2 -->|"defines_schema"| D1
    D3 -->|"inits_data"| D1
    B2 -->|"sends_response"| A4

    %% Backend internal and static content flow
    B1 --> B2
    A3 -->|"static_build"| B8
    B6 -->|"configures_docs"| D4
    B6 -->|"configures_docs"| D5
    D6 -->|"packages_static"| B8
    D7 -->|"packages_static"| B8

    %% Click Events for Frontend Components
    click A1 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/webui"
    click A2 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/webui/src"
    click A3 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/webui/dist"
    click A4 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/webui/src/app"
    click A5 "https://github.com/mrin9/angular-springboot-rest-jwt/blob/master/webui/src/app/app-routing.module.ts"

    %% Click Events for Backend Components
    click B1 "https://github.com/mrin9/angular-springboot-rest-jwt/blob/master/src/main/java/com/app/MainApp.java"
    click B2 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/src/main/java/com/app/api"
    click B3 "https://github.com/mrin9/angular-springboot-rest-jwt/blob/master/src/main/java/com/app/api/user/UserService.java"
    click B4 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/src/main/java/com/app/model"
    click B5 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/src/main/java/com/app/repo"
    click B6 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/src/main/java/com/app/config"
    click B7 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/src/main/java/com/app/identity"

    %% Click Events for Database & API Docs & Build Artifacts
    click D2 "https://github.com/mrin9/angular-springboot-rest-jwt/blob/master/src/main/resources/schema.sql"
    click D3 "https://github.com/mrin9/angular-springboot-rest-jwt/blob/master/src/main/resources/data.sql"
    click D4 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/src/main/resources/public/swagger"
    click D5 "https://github.com/mrin9/angular-springboot-rest-jwt/tree/master/src/main/resources/public/redoc"
    click D6 "https://github.com/mrin9/angular-springboot-rest-jwt/blob/master/pom.xml"
    click D7 "https://github.com/mrin9/angular-springboot-rest-jwt/blob/master/build.gradle"

    %% Styles
    classDef angularStyle fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef springStyle fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef dbStyle fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef apiDocStyle fill:#e2e3e5,stroke:#383d41,stroke-width:2px;
    classDef buildStyle fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
