# zhulinn/springboot-angular7-online-shopping-store architecture

> Architecture diagram of the GitHub repository zhulinn/springboot-angular7-online-shopping-store, 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/zhulinn/springboot-angular7-online-shopping-store
- Repository: https://github.com/zhulinn/springboot-angular7-online-shopping-store

## Overview

##### Main Components
- Backend Server:
- Contains a REST API built using Spring Boot.
- Implements business logic, handles security with JWT (see JWT provider, filter and entry point), and manages data operations via controllers, services, and repositories.
- Key directories: backend/src/main/java/me/zhulin/shopapi (controllers, services, entities, repositories, security, and configuration files) and backend/src/main/resources (configuration files like application.yml and import.sql which is used to seed the database).
- Frontend Client:
- An Angular 7 Single Page Application handling client-side routing and rendering.
- Communication with backend via API calls.
- Key directories: frontend/src/app (which contains pages, parts, services, models, enums, guards, interceptors) and configuration files in angular.json, package.json configuration files.
- Database:
- PostgreSQL is used for persistent storage.
- Security Components:
- JWT authentication implemented in backend.
- Spring Security configuration and related classes are part of the backend architecture.
- Docker & Docker Compose:
- Both backend and frontend have Dockerfiles.
- A top-level docker-compose.yml is present to define services and orchestrate running containers.

##### Relationships and Data Flow
- The Angular frontend interacts with the REST API endpoints provided by the Spring Boot backend.
- Data is served and received via JSON over HTTP; JWT tokens facilitate secure access.
- The backend, after processing business logic, interacts with a PostgreSQL database for CRUD operations.
- Docker Compose orchestrates both the frontend and backend containers, ensuring they communicate, while also possibly linking or connecting to the database container.

##### Architectural Patterns and Components
- MVC Pattern in the Backend:
- Controllers (e.g., CartController, CategoryController, OrderController, etc.) handle HTTP requests.
- Service layer (CartService, CategoryService, etc.) encapsulates business logic.
- Repository layer for data access.
- Entity classes represent database tables.
- Client-Side Rendering for the Frontend:
- Angular components serve as views.
- Services in Angular (cart.service.ts, product.service.ts, etc.) handle HTTP calls.
- Usage of Angular guards and interceptors to manage routing and HTTP request handling.
- Security with JWT:
- Integration of a dedicated JWT filter, provider, and security configurations.
- Containerization:
- Dockerfiles in both backend and frontend define the runtime environments.
- Docker Compose brings the multiple containers (backend, frontend, and likely the database) together to run as a cohesive unit.

- Clear labeling (with names like “Frontend (Angular 7)”, “Backend (Spring Boot 2.2)”, “Database (PostgreSQL)”, “JWT/Security”, “Docker Containers”).
- Frontend to Backend API requests.
- Backend to Database queries.
- Security checks (JWT token verification).
- Interactions stipulated by Docker Compose – show how containers are linked.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Docker & Deployment
    subgraph "Docker & Deployment"
        dd1("Backend Dockerfile"):::docker
        dd2("Frontend Dockerfile"):::docker
        dd3("Docker Compose"):::docker
    end

    %% Frontend (Angular 7)
    subgraph "Frontend (Angular 7)"
        f1("Angular Components"):::frontend
        f2("Frontend Config (angular.json)"):::frontend
        f3("Frontend Config (package.json)"):::frontend
    end

    %% Backend (Spring Boot 2)
    subgraph "Backend (Spring Boot 2)"
        b1("REST API (Controllers)"):::backend
        b2("Service Layer"):::backend
        b3("Repository Layer"):::backend
        sc("Security Components"):::security
        br1("Backend Code"):::backend
        br2("Backend Resources"):::backend
    end

    %% Security Detailed Components
    subgraph "Security Components Detail"
        s1("JWT Entry Point"):::security
        s2("JWT Filter"):::security
        s3("JWT Provider"):::security
        s4("SpringSecurityConfig"):::security
    end

    %% Database
    subgraph "Database (PostgreSQL)"
        db("Database"):::database
        dbi("DB Initialization (import.sql)"):::database
    end

    %% Connections between major components
    f1 -->|"APIcalls"| b1
    b1 -->|"JWTverify"| s2
    b3 -->|"Queries"| db
    dbi -->|"Seeds"| db

    %% Docker connections
    dd1 -->|"builds"| br1
    dd2 -->|"builds"| f1
    dd3 -->|"orchestrates"| b1
    dd3 -->|"orchestrates"| f1
    dd3 -->|"orchestrates"| db

    %% Security internal connections
    sc --- s1
    sc --- s2
    sc --- s3
    sc --- s4

    %% Class Definitions for color coding
    classDef frontend fill:#FFECB3,stroke:#FF9800,stroke-width:2px;
    classDef backend fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef database fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef docker fill:#E0E0E0,stroke:#616161,stroke-width:2px;
    classDef security fill:#FFCDD2,stroke:#C62828,stroke-width:2px;

    %% Click Events
    click br1 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/tree/master/backend/src/main/java/me/zhulin/shopapi"
    click br2 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/tree/master/backend/src/main/resources"
    click f1 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/tree/master/frontend/src/app"
    click f2 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/angular.json"
    click f3 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/package.json"
    click dbi "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/backend/src/main/resources/import.sql"
    click s1 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/backend/src/main/java/me/zhulin/shopapi/security/JWT/JwtEntryPoint.java"
    click s2 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/backend/src/main/java/me/zhulin/shopapi/security/JWT/JwtFilter.java"
    click s3 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/backend/src/main/java/me/zhulin/shopapi/security/JWT/JwtProvider.java"
    click s4 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/backend/src/main/java/me/zhulin/shopapi/security/SpringSecurityConfig.java"
    click dd1 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/tree/master/backend/Dockerfile"
    click dd2 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/tree/master/frontend/Dockerfile"
    click dd3 "https://github.com/zhulinn/springboot-angular7-online-shopping-store/blob/master/docker-compose.yml"
```
