# markuskeiththomas/solartp architecture

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

- Interactive diagram: https://gitdiagram.com/markuskeiththomas/solartp
- Repository: https://github.com/markuskeiththomas/solartp

## Overview

##### Overall Project Purpose & Type
- The project is a full-stack eCommerce application (likely with a solar energy theme based on the project name “solartp” and page names such as “den-nang-luong-mat-troi” and “he-thong-dien-mat-troi”).
- It is divided into two main parts: a Java-based backend (using Maven, Spring Boot architecture patterns) and a React-based frontend (with TypeScript and React components).

##### Main Components
- Frontend (React):
- Displays the user interface with pages for products, cart checkout, user account management, etc.
- Contains components like ProductCard, CartItem, and various pages (Home, Product Detail, Login, SignUp, etc.).
- Defines API interactions with the backend (see the api folder with authApi.tsx, productApi.ts).

- Backend (Java – Spring Boot):
- The main application entry point is in EcommerceApplication.java.
- Organized into clearly defined layers:
○ Controllers (API endpoints managing Articles, Auth, Categories, Products, Files, etc.)
○ Services (handling the business logic: ArticleService, AuthService, CartService, CloudflareR2Service, etc.)
○ Repositories (data access layer interacting with the database through entities such as UserEntity, ProductEntity, etc.)
○ Entities / DTOs (models for carrying data back and forth)
○ Exception handling, configuration (e.g., CorsConfig, RedisConfig, SecurityConfig), and filters (e.g., JwtAuthenticationFilter).

- Database & Persistence:
- Migration scripts in src/main/resources/db/migration (e.g., V1__init_schema.sql) indicate a relational database is in use.
- The repository layer connects entities to the persistence store.

- Supporting Services:
- Redis configuration implies caching mechanisms.
- CloudflareR2 integration for file uploads or image storage.
- External email service integration for user notifications.
- A set of utility classes indicate shared logic (e.g., JWT handling, date formatting).

##### Relationships and Interactions
- The React frontend communicates with the Java backend via RESTful API calls.
- The backend controllers receive incoming requests, then delegate business logic to service layers.
- The services interact with repositories to perform CRUD operations on the database.
- Additional configurations (security, CORS) and filters (JWT authentication) secure and moderate the request flow.
- External integrations (CloudflareR2, possibly email services) are invoked from appropriate service components.
- Caching and session/state management use Redis as configured.

##### Architectural Patterns and Design Principles
- The backend follows a layered (MVC-like) architecture:
○ Controllers → Services → Repositories → Database.
- Use of configuration and filtering patterns for security and cross-origin resource handling.
- Separation of concerns is evident: the frontend focuses on presentation and API consumption while the backend handles business logic, persistence, and external integrations.
- Clear use of DTOs for data transfer and mapping utilities (ProductMapperUtils) to separate business models from transport objects.

## Diagram (Mermaid)

```mermaid
flowchart TB
    User("User/Browser"):::external

    subgraph "Frontend (React)"
        FR_Main("Main Application Entry (React)"):::frontend
        FR_Pages("Pages (React)"):::frontend
        FR_Components("Components (React)"):::frontend
        FR_API("API Interactions (React)"):::frontend
    end

    subgraph "Backend (Spring Boot)"
        BE_Main("Main Application Entry (Java)"):::backend
        BE_Controllers("Controllers"):::backend
        BE_Services("Services"):::backend
        BE_Repositories("Repositories"):::backend
        BE_DB("Database Migration"):::db
        BE_Config("Configuration"):::config
        BE_Exception("Exception Handling"):::config
        BE_JWT("JWT Authentication Filter"):::config
        BE_Cloudflare("Cloudflare R2 Integration"):::external
    end

    User -->|"HTTP_Request"| FR_Main
    FR_Main -->|"renders"| FR_Pages
    FR_Main -->|"renders"| FR_Components
    FR_Main -->|"calls_API"| FR_API
    FR_API -->|"HTTP_API"| BE_Controllers
    BE_Main -->|"initializes"| BE_Controllers
    BE_Controllers -->|"delegates_to"| BE_Services
    BE_Services -->|"calls"| BE_Repositories
    BE_Repositories -->|"DB_access"| BE_DB
    BE_Services -->|"integrates_with"| BE_Cloudflare
    BE_Controllers -->|"configured_by"| BE_Config
    BE_Controllers -->|"monitored_by"| BE_Exception
    BE_Controllers -->|"filtered_by"| BE_JWT

    click FR_Main "https://github.com/markuskeiththomas/solartp/blob/main/frontend-react/src/main.tsx"
    click FR_Pages "https://github.com/markuskeiththomas/solartp/tree/main/frontend-react/src/pages"
    click FR_Components "https://github.com/markuskeiththomas/solartp/tree/main/frontend-react/src/components"
    click FR_API "https://github.com/markuskeiththomas/solartp/tree/main/frontend-react/src/api"
    click BE_Main "https://github.com/markuskeiththomas/solartp/blob/main/backend-java/src/main/java/ecommerce/project/EcommerceApplication.java"
    click BE_Controllers "https://github.com/markuskeiththomas/solartp/tree/main/backend-java/src/main/java/ecommerce/project/controller"
    click BE_Services "https://github.com/markuskeiththomas/solartp/tree/main/backend-java/src/main/java/ecommerce/project/service"
    click BE_Repositories "https://github.com/markuskeiththomas/solartp/tree/main/backend-java/src/main/java/ecommerce/project/repository"
    click BE_Config "https://github.com/markuskeiththomas/solartp/tree/main/backend-java/src/main/java/ecommerce/project/config"
    click BE_Exception "https://github.com/markuskeiththomas/solartp/tree/main/backend-java/src/main/java/ecommerce/project/exception"
    click BE_JWT "https://github.com/markuskeiththomas/solartp/blob/main/backend-java/src/main/java/ecommerce/project/filter/JwtAuthenticationFilter.java"
    click BE_DB "https://github.com/markuskeiththomas/solartp/tree/main/backend-java/src/main/resources/db/migration"
    click BE_Cloudflare "https://github.com/markuskeiththomas/solartp/blob/main/backend-java/src/main/java/ecommerce/project/service/CloudflareR2Service.java"

    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#F7D6AE,stroke:#333,stroke-width:2px;
    classDef db fill:#C7F7C3,stroke:#333,stroke-width:2px;
    classDef config fill:#FFD6A5,stroke:#333,stroke-width:2px;
    classDef external fill:#FFBFA5,stroke:#333,stroke-width:2px;
```
