# serlesen/fullstack-jwt architecture

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

- Interactive diagram: https://gitdiagram.com/serlesen/fullstack-jwt
- Repository: https://github.com/serlesen/fullstack-jwt

## Overview

##### Project type and purpose
- This is a full-stack web application demonstrating JWT authentication.
- Frontend: Angular SPA that handles user login, stores a JWT, and accesses protected resources.
- Backend: Spring Boot REST API that issues and validates JWTs, manages users, and serves protected endpoints.

##### File structure
- Top-level directories:
- backend (Java/Spring Boot source, config, controllers, services, repos)
- frontend (Angular source, components, routing, service for HTTP calls)
- backend follows a layered MVC pattern:
- config (security filters, exception handlers, WebConfig)
- controllers (AuthController, MessagesController)
- services (UserService)
- repositories (UserRepository)
- dtos and mappers for data transfer
- frontend is component-based:
- login-form, header, content, welcome-content, auth-content, buttons
- axios.service.ts handles HTTP and attaches JWT header
- Key config files:
- backend/src/main/resources/application.yml (DB, JWT secret)
- frontend/angular.json, package.json, tsconfig.json

##### README for additional insights
- Purpose: Show end-to-end JWT flow
- Workflow: Angular sends credentials → Spring issues JWT → Angular saves token → Angular calls protected API
- No external services beyond DB and JWT logic

##### Elements
- Blue for frontend components
- Green for backend controllers/services
- Orange for security/filter components
- Gray for external systems (Database)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        User["User (Browser)"]:::frontend
        AngularApp["Angular App"]:::frontend
        LoginForm["LoginFormComponent"]:::frontend
        HeaderComp["HeaderComponent"]:::frontend
        WelcomeComp["WelcomeContentComponent"]:::frontend
        AuthComp["AuthContentComponent"]:::frontend
        ButtonsComp["ButtonsComponent"]:::frontend
        ContentComp["ContentComponent"]:::frontend
        Routing["AppRoutingModule"]:::frontend
        HTTPService["AxiosService"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        BackendApp["BackendApplication"]:::backend
        SecurityConfig["SecurityConfig"]:::security
        JwtFilter["JwtAuthFilter"]:::security
        AuthProvider["UserAuthenticationProvider"]:::security
        EntryPoint["UserAuthenticationEntryPoint"]:::security
        PasswordConf["PasswordConfig"]:::security
        RestExHandler["RestExceptionHandler"]:::security
        WebConfig["WebConfig"]:::security

        AuthController["AuthController"]:::backend
        MessagesCtrl["MessagesController"]:::backend

        UserService["UserService"]:::backend
        UserRepo["UserRepository"]:::backend
        UserEntity["UserEntity"]:::backend
        UserMapper["UserMapper"]:::backend
        DTOs["DTOs"]:::backend
    end

    %% Database
    Database[(Database)]:::db

    %% Frontend flows
    User -->|"interactswith"| AngularApp
    AngularApp -->|renders| LoginForm
    AngularApp -->|renders| HeaderComp
    AngularApp -->|renders| WelcomeComp
    AngularApp -->|rendersprotected| AuthComp
    AngularApp -->|uses| ButtonsComp
    AngularApp -->|wrapsprotected| ContentComp
    AngularApp -->|routesvia| Routing

    LoginForm -->|submitCredentials| HTTPService
    HTTPService -->|POST/api/auth/login| AuthController
    HTTPService -.->|attachToken| AuthComp

    %% Backend flows
    AuthController -->|calls| UserService
    UserService -->|queries| UserRepo
    UserRepo -->|reads| Database
    AuthController -->|returnsJWT| HTTPService

    HTTPService -->|GET/api/messages| JwtFilter
    JwtFilter -->|validates| SecurityConfig
    JwtFilter -->|onSuccess| AuthProvider
    JwtFilter -->|onFailure| EntryPoint
    JwtFilter -->|passes| MessagesCtrl
    MessagesCtrl -->|calls| UserService
    UserService -->|usesMapper| UserMapper
    UserMapper -->|transforms| DTOs
    MessagesCtrl -->|returnsData| HTTPService

    %% Additional backend config
    SecurityConfig --> JwtFilter
    SecurityConfig --> AuthProvider
    SecurityConfig --> EntryPoint
    SecurityConfig --> PasswordConf
    SecurityConfig --> RestExHandler
    SecurityConfig --> WebConfig

    %% Flows back to frontend
    HTTPService -->|response| AuthComp
    HTTPService -->|response| ContentComp

    %% Database as external
    Database -->|stores| UserEntity

    %% Click events for frontend
    click AngularApp "https://github.com/serlesen/fullstack-jwt/tree/main/frontend/src/app"
    click HTTPService "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/axios.service.ts"
    click Routing "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/app-routing.module.ts"
    click LoginForm "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/login-form/login-form.component.ts"
    click HeaderComp "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/header/header.component.ts"
    click WelcomeComp "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/welcome-content/welcome-content.component.ts"
    click AuthComp "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/auth-content/auth-content.component.ts"
    click ButtonsComp "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/buttons/buttons.component.ts"
    click ContentComp "https://github.com/serlesen/fullstack-jwt/blob/main/frontend/src/app/content/content.component.ts"

    %% Click events for backend
    click BackendApp "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/BackendApplication.java"
    click AuthController "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/controllers/AuthController.java"
    click MessagesCtrl "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/controllers/MessagesController.java"
    click SecurityConfig "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/config/SecurityConfig.java"
    click JwtFilter "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/config/JwtAuthFilter.java"
    click AuthProvider "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/config/UserAuthenticationProvider.java"
    click EntryPoint "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/config/UserAuthenticationEntryPoint.java"
    click PasswordConf "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/config/PasswordConfig.java"
    click RestExHandler "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/config/RestExceptionHandler.java"
    click WebConfig "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/config/WebConfig.java"
    click UserService "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/services/UserService.java"
    click UserRepo "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/repositories/UserRepository.java"
    click UserEntity "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/entites/User.java"
    click UserMapper "https://github.com/serlesen/fullstack-jwt/blob/main/backend/src/main/java/com/sergio/jwt/backend/mappers/UserMapper.java"
    click DTOs "https://github.com/serlesen/fullstack-jwt/tree/main/backend/src/main/java/com/sergio/jwt/backend/dtos"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef security fill:#FFA500,stroke:#333,stroke-width:1px
    classDef db fill:#D3D3D3,stroke:#333,stroke-width:1px
```
