# oks110/ssf architecture

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

- Interactive diagram: https://gitdiagram.com/oks110/ssf
- Repository: https://github.com/oks110/ssf

## Overview

This project is a monorepo for a React-based shopping mall service that includes both a customer-facing front end (client) and a Node.js/Express backend (server). The overall system is designed to support features such as product browsing, cart management, checkout (with KakaoPay integration), real‑time notifications through WebSocket, and a separate admin page for store management.

##### Key components
- Client (Frontend):
- Built with React, organized under the "/client" directory.
- Uses React Router for navigation, Context API and localStorage for state management.
- Contains UI components (found in client/src/components and client/src/commons), pages (e.g., Home, DetailProducts, Login, Signup, Carts, Order, Person), and hooks (client/src/hooks) that drive business logic.
- Integrates external services like KakaoPay API and handles real-time communications with WebSocket.
- Server (Backend):
- Found under the "/server" directory.
- Uses Node.js with Express to implement a RESTful API.
- Organized into controllers (business logic per feature), routers (defining endpoints), and repositories (database interactions).
- Implements JWT-based authentication, integrates with MySQL (see SQL files in the "db" folder), and manages real-time WebSocket connections.
- Database:
- MySQL is used for data persistence, with SQL scripts provided in the "db" directory for orders, products, customers, reviews, etc.
- External Services:
- KakaoPay API (for payment processing).
- WebSocket for real-time functionality (e.g., delivery updates, order notifications).
- Assets & Deployment:
- There are client assets (images, sample JSON data) and deployment artifacts for both customer and admin pages.
- The README includes deployment URLs for both customer and admin pages, indicating production environments hosted (e.g., on AWS S3).

##### Relationships and interactions
- The Client interacts with the Server through RESTful API calls (e.g., for login, fetching product details, cart and order management).
- The Client receives real-time updates via a WebSocket connection from the Server.
- The Server interacts with the MySQL database for CRUD operations, driven mainly by the repository layer.
- External interactions include the KakaoPay payment gateway (invoked by the Client via the Server) and WebSocket notifications from the admin side that inform the Client on state changes (e.g., delivery updates).

##### Architectural patterns and design principles
- Separation of concerns: Client and server sides are maintained separately within a monorepo.
- MVC-like structure on the backend: Controllers, routers, and repositories clearly separate request handling from business logic and data access.
- Component-based design on the frontend: React components, contexts, and hooks are organized to provide modular, reusable UI and state management.
- API-driven integration: The system uses RESTful endpoints to manage data flow between the client and server.
- Real-time data flow: WebSocket integration for live updates reflects an event-driven design principle.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Subgraph
    subgraph "Frontend (React Client)"
        FE_total("React Client"):::frontend
        FE_a("Components"):::frontend
        FE_b("Commons"):::frontend
        FE_c("Pages"):::frontend
        FE_d("App (Routing)"):::frontend
        FE_e("ContextAPI"):::frontend
        FE_f("Hooks"):::frontend
        FE_g("AuthContext"):::frontend
        FE_h("KaKaoPayment Hook"):::frontend
    end
    %% Group internal frontend components
    FE_a --> FE_total
    FE_b --> FE_total
    FE_c --> FE_total
    FE_d --> FE_total
    FE_e --> FE_total
    FE_f --> FE_total
    FE_g --> FE_total
    FE_h --> FE_total

    %% Backend Subgraph
    subgraph "Backend (Express Server API)"
        BE_total("Express Server API"):::backend
        BE1("Server Entry"):::backend
        BE2("CartController"):::backend
        BE3("OrderController"):::backend
        BE4("PaymentController"):::backend
        BE5("CartRouter"):::backend
        BE6("OrderRouter"):::backend
        BE7("PaymentRouter"):::backend
        BE8("CartRepository"):::backend
        BE9("OrderRepository"):::backend
        BE10("ProductRepository"):::backend
    end
    %% Internal backend relationships
    BE2 --> BE1
    BE3 --> BE1
    BE4 --> BE1
    BE5 --> BE1
    BE6 --> BE1
    BE7 --> BE1
    BE8 --> BE1
    BE9 --> BE1
    BE10 --> BE1
    BE1 --> BE_total

    %% Database Subgraph
    subgraph "Database"
        DB_main(("MySQL Database")):::database
        DB_a("AdminApproval SQL"):::database
        DB_b("Cart SQL"):::database
        DB_c("Customers SQL"):::database
    end
    DB_main --> DB_a
    DB_main --> DB_b
    DB_main --> DB_c

    %% External Services Subgraph
    subgraph "External Services"
        EX1("KakaoPay Gateway"):::external
        EX2("WebSocket Service"):::external
    end

    %% Interactions Between Subsystems
    FE_total -->|"REST_API_Calls"| BE_total
    BE_total -->|"CRUD_Operations"| DB_main
    BE_total -->|"Payment_Processing"| EX1
    BE_total <-->|"RealTime_Updates"| EX2
    EX2 -->|"RealTime_Update_to_Client"| FE_total

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#0275d8,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#2e7d32,stroke-width:2px;
    classDef database fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef external fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;

    %% Click Events - Frontend
    click FE_total "https://github.com/oks110/ssf/tree/main/client"
    click FE_a "https://github.com/oks110/ssf/tree/main/client/src/components"
    click FE_b "https://github.com/oks110/ssf/tree/main/client/src/commons"
    click FE_c "https://github.com/oks110/ssf/tree/main/client/src/pages"
    click FE_d "https://github.com/oks110/ssf/blob/main/client/src/App.js"
    click FE_e "https://github.com/oks110/ssf/tree/main/client/src/context"
    click FE_f "https://github.com/oks110/ssf/tree/main/client/src/hooks"
    click FE_g "https://github.com/oks110/ssf/blob/main/client/src/auth/AuthContext.js"
    click FE_h "https://github.com/oks110/ssf/blob/main/client/src/hooks/useKaKaoPayment.js"

    %% Click Events - Backend
    click BE_total "https://github.com/oks110/ssf/tree/main/server"
    click BE1 "https://github.com/oks110/ssf/blob/main/server/server.js"
    click BE2 "https://github.com/oks110/ssf/blob/main/server/controller/cartController.js"
    click BE3 "https://github.com/oks110/ssf/blob/main/server/controller/orderController.js"
    click BE4 "https://github.com/oks110/ssf/blob/main/server/controller/paymentController.js"
    click BE5 "https://github.com/oks110/ssf/blob/main/server/router/cartRouter.js"
    click BE6 "https://github.com/oks110/ssf/blob/main/server/router/orderRouter.js"
    click BE7 "https://github.com/oks110/ssf/blob/main/server/router/paymentRouter.js"
    click BE8 "https://github.com/oks110/ssf/blob/main/server/repository/cartRepository.js"
    click BE9 "https://github.com/oks110/ssf/blob/main/server/repository/orderRepository.js"
    click BE10 "https://github.com/oks110/ssf/blob/main/server/repository/productRepository.js"

    %% Click Events - Database
    click DB_main "https://github.com/oks110/ssf/tree/main/db"
    click DB_a "https://github.com/oks110/ssf/blob/main/db/shopping_mall_admin_approval.sql"
    click DB_b "https://github.com/oks110/ssf/blob/main/db/shopping_mall_cart.sql"
    click DB_c "https://github.com/oks110/ssf/blob/main/db/shopping_mall_customers.sql"
```
