# yoonjiji/casetibuy architecture

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

- Interactive diagram: https://gitdiagram.com/yoonjiji/casetibuy
- Repository: https://github.com/yoonjiji/casetibuy

## Overview

##### Main Components
- Frontend (Client)
- The client directory houses the React app. This includes various subcomponents such as pages (Home, DetailProduct, Login, SignUp, etc.), reusable components (Header, Footer, Cart, etc.), contexts (AuthContext, CartContext, etc.), and hooks that encapsulate custom business logic.
- The public folder contains static assets (images, fonts, JSON data), which the frontend renders.
- Backend (Server)
- The server directory follows an MVC-ish pattern with clear separation:
▸ Controllers – handling request logic such as cartController, memberController, orderController, etc.
▸ Routers – endpoints to map HTTP requests (e.g., cartRouter, memberRouter, etc.)
▸ Repository – database interaction via functions (db.js, productRepository, etc.)
- An upload controller/router takes care of file uploads.
- Database (MySQL)
- The SQL folder contains multiple export directories with scripts and dump files. This represents the relational database schema (tables for members, products, orders, reviews, carts, etc.).
- External APIs and Services (if applicable)
- The README mentions KakaoPay API for payment processing, so include an “External Payment Service” component.
- Other tools (such as Daum Postcode for address lookup) can be noted as external integration points.

##### Out the Interactions and Dataflow
- From the Client (React App):
- UI Components and pages issue HTTP requests (likely via Axios) to the relevant backend endpoints.
- State and context providers (like AuthContext, CartContext) manage user interactions, session tokens (JWT), and cart/order state.
- Backend (Express Server):
- Requests are routed via express routers to corresponding controllers.
- Controllers perform business logic (handling authentication, product details, reviews, etc.) and communicate with the repository layer.
- The repository layer interacts with the MySQL database, executing SQL queries and returning results.
- Database:
- Stores persistent data for products, users, orders, reviews, etc.
- External Service Connections:
- Payment processing (KakaoPay) and third-party address lookup (Daum Postcode) integrations.
- File Uploads and Static Assets:
- The server handles file uploads (using Multer) and serves static files as needed.

##### Architectural Patterns and Principles
- Separation of Concerns – clearly divided into frontend and backend layers with distinct responsibilities.
- MVC-like Pattern on the Server – controllers, routers, and repository separation.
- SPA Principles on the Client – single-page navigation with React components and context-based state management.
- RESTful API Design – backend provides endpoints for various operations (CRUD for products, orders, reviews, etc.).
- Security – use of JWT tokens for authentication.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE0["React SPA"]:::frontend
        FE1["Pages"]:::frontend
        FE2["Components"]:::frontend
        FE3["Contexts"]:::frontend
        FE4["Custom Hooks"]:::frontend
        FE5["Public Assets"]:::frontend
    end

    subgraph "Backend Layer"
        BE0["Backend Server"]:::backend
        BE1["Routers"]:::backend
        BE2["Controllers"]:::backend
        BE3["Repositories"]:::backend
    end

    D1(("MySQL Database")):::database
    E1["KakaoPay API"]:::external
    E2["Daum Postcode Service"]:::external

    %% Data flow from Frontend to Backend
    FE0 -->|"HTTP_Request"| BE1
    BE0 --> BE1
    BE0 --> BE2
    BE0 --> BE3
    BE1 -->|"Route_to_Controller"| BE2
    BE2 -->|"Query_DB"| BE3
    BE3 -->|"Return_Results"| D1

    %% External Service Integrations
    BE2 -->|"Payment"| E1
    BE2 -->|"AddressLookup"| E2

    %% Frontend Internal Composition
    FE0 --> FE1
    FE0 --> FE2
    FE0 --> FE3
    FE0 --> FE4
    FE0 --> FE5

    %% Click Events
    click FE0 "https://github.com/yoonjiji/casetibuy/tree/main/client"
    click FE1 "https://github.com/yoonjiji/casetibuy/tree/main/client/src/pages"
    click FE2 "https://github.com/yoonjiji/casetibuy/tree/main/client/src/component"
    click FE3 "https://github.com/yoonjiji/casetibuy/tree/main/client/src/context"
    click FE4 "https://github.com/yoonjiji/casetibuy/tree/main/client/src/hooks"
    click FE5 "https://github.com/yoonjiji/casetibuy/tree/main/client/public"
    click BE0 "https://github.com/yoonjiji/casetibuy/tree/main/server"
    click BE1 "https://github.com/yoonjiji/casetibuy/tree/main/server/router"
    click BE2 "https://github.com/yoonjiji/casetibuy/tree/main/server/controller"
    click BE3 "https://github.com/yoonjiji/casetibuy/tree/main/server/repository"
    click D1 "https://github.com/yoonjiji/casetibuy/tree/main/sql"

    %% Styles
    classDef frontend fill:#B3D9FF,stroke:#333,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef database fill:#FFE0B2,stroke:#333,stroke-width:2px;
    classDef external fill:#F8BBD0,stroke:#333,stroke-width:2px;
```
