# daphdev/electro architecture

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

- Interactive diagram: https://gitdiagram.com/daphdev/electro
- Repository: https://github.com/daphdev/electro

## Overview

##### Main Components
- Frontend – electro-client: A React-based single-page application (SPA) that contains separate pages and components (client views and admin views) and interacts with the server using HTTP (RESTful APIs) and WebSocket connections.
- Backend – electro-server: A Spring Boot application following the MVC pattern. It includes controllers, services, repositories, and entity classes. The server handles authentication, order processing, chat, payments, and inventory management.
- Database – MySQL: The data persistence layer that stores all entities. The Spring Boot application uses JDBC via Spring Data JPA to connect to the MySQL server.
- External Services: Integration points for PayPal (payment gateway) and Giao Hàng Nhanh (shipping service).
- Docker Environment: Documentation shows a docker-compose.yml along with Dockerfiles. These orchestrate deploying the database, server, and client each in their own containers with an internal network.

##### Relationships and Interactions
- In the backend, optionally expand the MVC structure – for instance, show a breakdown of controllers calling services which in turn use repositories to access persistent entities.

##### Architectural Patterns and Design Principles
- 3-tier architecture (presentation, application, and data layers).
- That the backend follows an MVC design pattern with clearly defined roles for controllers, services, and repositories.
- Use of Docker for containerization and the separation of concerns (i.e., separation of client and server).

##### Relevant Technologies
- Frontend: React, JavaScript/TypeScript.
- Backend: Java, Spring Boot, Spring Data JPA, JDBC.
- Database: MySQL.
- Containerization: Docker, docker-compose.
- External: PayPal API and Giao Hàng Nhanh API.
- Additional artifacts: You might note the inclusion of various configuration files (nginx.conf in the client, security configurations and JWT handling in the server) to emphasize their role in the overall design.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Docker Environment Container
    subgraph "Docker Environment"
        FC["React Client (SPA)"]:::frontend
        SB["Spring Boot API Server"]:::backend
        DB["MySQL Database"]:::database
    end

    %% Container Configurations Subgraph
    subgraph "Container Configurations"
        DC["Docker Compose"]:::docker
        CDF["Client Dockerfile"]:::docker
        SDF["Server Dockerfile"]:::docker
    end

    %% Developer Artifacts
    DA["Developer Artifacts"]:::doc

    %% MVC Breakdown inside the Backend (detailed interaction)
    CT["Controllers"]:::backend
    SV["Services"]:::backend
    RP["Repositories/Entities"]:::backend

    %% External Services
    PS["PayPal Service"]:::external
    GH["Giao Hàng Nhanh Service"]:::external

    %% Connections - Docker Environment orchestration
    DC -->|"orchestrates"| FC
    DC -->|"orchestrates"| SB
    DC -->|"orchestrates"| DB
    DC -->|"defines"| CDF
    DC -->|"defines"| SDF

    %% Interactions between client and server
    FC -->|"HTTP/WS"| SB

    %% Backend MVC Flow
    SB -->|"entry point"| CT
    CT -->|"calls"| SV
    SV -->|"accesses"| RP
    SV -->|"JDBC/ORM"| DB

    %% Backend to External Service Integrations 
    SV -->|"REST"| PS
    SV -->|"REST"| GH

    %% Developer Artifacts reference
    DA ---|"Docs"| SB

    %% Styles
    classDef frontend fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef database fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef docker fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef doc fill:#e6ccff,stroke:#333,stroke-width:2px;

    %% Click Events
    click FC "https://github.com/daphdev/electro/tree/main/electro-client/"
    click SB "https://github.com/daphdev/electro/tree/main/electro-server/"
    click DB "https://github.com/daphdev/electro/blob/main/electro-server/src/main/resources/schema.sql"
    click PS "https://github.com/daphdev/electro/tree/main/electro-server/src/main/java/com/electro/config/payment/paypal/"
    click GH "https://github.com/daphdev/electro/tree/main/electro-server/src/main/java/com/electro/dto/waybill/"
    click GH "https://github.com/daphdev/electro/blob/main/electro-server/src/main/java/com/electro/service/waybill/WaybillService.java"
    click DC "https://github.com/daphdev/electro/blob/main/docker-compose.yml"
    click CDF "https://github.com/daphdev/electro/tree/main/electro-client/Dockerfile"
    click SDF "https://github.com/daphdev/electro/tree/main/electro-server/Dockerfile"
    click DA "https://github.com/daphdev/electro/tree/main/diagram/"
```
