# arawns1/trabalho-react-hexbyte architecture

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

- Interactive diagram: https://gitdiagram.com/arawns1/trabalho-react-hexbyte
- Repository: https://github.com/arawns1/trabalho-react-hexbyte

## Overview

##### Project type and purpose
- This is a full-stack ecommerce application (frontend in React.js + Styled Components; backend in Spring Boot + PostgreSQL).
- The repository you have is the frontend “ecommerce” React project that serves as the client. It communicates with a separate Spring Boot API and persists data to Postgres.

##### File structure
- Top-level “ecommerce” directory is the React app:
- public/assets: static images & banners
- src: application source
– main.jsx & index.html: app bootstrap
– common/components: reusable UI modules (buttons, cards, modals, slider, header, etc.)
– common/hooks: useCart & useProducts (state & data fetching)
– common/services: api.js (HTTP client) & LocalStorage.js
– src/pages: route pages (Home, Cart, Login, SignUp, Payment, MyOrders, OrderComplete, Exceptions)
– routes/AllRoutes.jsx: React Router config
– Theme.jsx & global/GlobalStyle.jsx: styling setup
- No backend code here, but README says backend is Spring Boot + Postgres.

##### Key README insights
- Frontend stack: React.js + Styled Components
- Backend stack: Spring Boot + Postgres
- Live URL: https://loja-hexbyte.vercel.app/

##### Main components
a. Frontend (React)
– Browser / Client App
– Router layer (AllRoutes.jsx)
– UI Component Library (common/components)
– Page Components (src/pages/*)
– State & Data Layer (common/hooks & common/services)
– Styling Layer (Theme.jsx, GlobalStyle, styled-components)
b. Backend (Spring Boot)
– REST Controllers
– Service Layer
– Repository Layer (data access)
– Business Entities / DTOs
c. Database (PostgreSQL)
d. External Services (if any, e.g., payment gateway)

##### Interactions / Data flow
- User in Browser interacts with UI Pages → triggers actions/clicks
- Pages/components invoke hooks (useCart/useProducts)
- Hooks call api.js (configured axios) → HTTP request to Spring Boot API endpoints
- api.js handles responses → components update state
- LocalStorage.js persists cart data in client browser storage
- Spring Boot controllers accept requests → service layer applies business logic → repository persists/reads from Postgres
- Responses travel back to React → UI updates

##### Architectural patterns & principles
- Component-based UI (React + styled-components)
- Single Page Application (SPA) with client-side routing
- Separation of concerns:
- UI components vs. page containers
- Data fetching & caching hooks
- Service (api.js) as API abstraction
- Persistence (LocalStorage) isolated in a service
- Backend is layered (Controller → Service → Repository)

##### Details
- Related modules inside containers to show boundaries (e.g., “Frontend App”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User (Browser)"]:::user

    %% Frontend Application
    subgraph "Frontend Application"
        direction TB
        subgraph "Bootstrap"
            direction TB
            Entry["main.jsx"]:::frontend
            HTML["index.html"]:::frontend
        end

        Router["AllRoutes"]:::frontend

        subgraph "Page Components"
            direction TB
            Pages["src/pages"]:::frontend
        end

        subgraph "UI Component Library"
            direction TB
            Components["common/components"]:::frontend
        end

        subgraph "State & Data Layer"
            direction TB
            UseCart["useCart Hook"]:::data
            UseProducts["useProducts Hook"]:::data
            APIClient["api.js"]:::data
            LocalStorage["LocalStorage.js"]:::data
        end

        subgraph "Styling Layer"
            direction TB
            Theme["Theme.jsx"]:::frontend
            GlobalStyle["GlobalStyle.jsx"]:::frontend
        end

        StaticAssets["public/assets"]:::frontend
    end

    %% Backend Application
    subgraph "Backend (Spring Boot API)"
        direction TB
        Controllers["Controllers"]:::backend
        Services["Service Layer"]:::backend
        Repositories["Repository Layer"]:::backend
    end

    %% External & Database
    PaymentService["Payment Gateway"]:::external
    DB["PostgreSQL DB"]:::db

    %% Connections
    User -->|"opens SPA"| Entry
    Entry -->|"loads HTML"| HTML
    HTML -->|"bootstraps React"| Router
    Router -->|"routes to pages"| Pages
    Pages -->|"renders UI modules"| Components
    Pages -->|"invokes hooks"| UseCart
    Pages -->|"invokes hooks"| UseProducts
    UseCart -->|"sync cart"| LocalStorage
    UseCart -->|"GET /cart"| APIClient
    UseProducts -->|"GET /products"| APIClient
    APIClient -->|"HTTP request"| Controllers
    Controllers -->|"calls business logic"| Services
    Services -->|"queries DB"| Repositories
    Repositories -->|"SQL operations"| DB
    Services -->|"POST /payment"| PaymentService

    %% Click Events
    click Router "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/routes/AllRoutes.jsx"
    click Entry "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/src/main.jsx"
    click HTML "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/index.html"
    click Components "https://github.com/arawns1/trabalho-react-hexbyte/tree/main/ecommerce/src/common/components"
    click Pages "https://github.com/arawns1/trabalho-react-hexbyte/tree/main/ecommerce/src/pages"
    click UseCart "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/src/common/hooks/useCart.jsx"
    click UseProducts "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/src/common/hooks/useProducts.jsx"
    click APIClient "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/src/services/api.js"
    click LocalStorage "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/src/services/LocalStorage.js"
    click Theme "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/src/Theme.jsx"
    click GlobalStyle "https://github.com/arawns1/trabalho-react-hexbyte/blob/main/ecommerce/src/common/global/GlobalStyle.jsx"
    click StaticAssets "https://github.com/arawns1/trabalho-react-hexbyte/tree/main/ecommerce/public/assets"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef data fill:#D5F5E3,stroke:#186A3B,color:#145A32
    classDef backend fill:#FAD7A0,stroke:#B9770E,color:#6E2C00
    classDef db fill:#D5D8DC,stroke:#626567,color:#1B2631
    classDef external fill:#F5EEF8,stroke:#6C3483,color:#4A235A
    classDef user fill:#AED6F1,stroke:#1F618D,color:#1B2631
```
