How zhulinn/springboot-angular7-online-shopping-store works
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.