# imtaemin/myshop architecture

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

- Interactive diagram: https://gitdiagram.com/imtaemin/myshop
- Repository: https://github.com/imtaemin/myshop

## Overview

##### Project Type and Purpose
- MyShop is a full‐stack online shop platform with three Dockerized applications:
a. api (Spring Boot REST API)
b. customer (React customer portal)
c. provider (React seller portal)
- It implements features such as user authentication (JWT), carts, orders, coupons, favorites, file storage (GCP), and external payment (KakaoPay).
- CI/CD is orchestrated via Jenkins; Nginx handles load balancing and multi‐domain routing; MySQL with master‐replica (write–read) replication is used as the DB layer.

##### Key Components
a. Users
- Customer users (browsers)
- Provider users (browsers)
b. Nginx Layer
- Acts as edge router / load balancer
- Routes “/api” requests to api containers
- Serves or proxies static content for customer and provider frontends on separate domains
c. Dockerized Applications
- customer‐app containers (React)
- provider‐app containers (React)
- api containers (Spring Boot REST service)
d. CI/CD Pipeline (Jenkins)
- Monitors code repo
- Builds images for api, customer, provider
- Pushes images to a registry (optional) and deploys to hosting environment
e. Database Tier
- MySQL master for writes
- MySQL replicas for read queries
- JPA/QueryDSL in api service handles routing to master/replica via the RoutedDataSource
f. External Services
- GCP Cloud Storage for item images (via GCPStorageService)
- KakaoPay API for payment processing (via KakaoPayService)

##### Relationships and Data Flows
- Browser → Nginx
- customer.myshop.com → serves React static files from customer container
- provider.myshop.com → serves React static files from provider container
- api.myshop.com → proxies REST API requests to api containers
- customer‐app ↔ api
- Auth, item listings, cart, favorites, orders, coupons
- provider‐app ↔ api
- Provider’s item management, coupon issuance, order management
- api → MySQL master (writes via services/repositories)
- api → MySQL replica(s) (reads, analytics, paginated queries)
- api → GCP Cloud Storage (upload/download item images)
- api → KakaoPay (payment readiness, approval)
- Jenkins → Git → on‐commit triggers → build → docker push → deploy (update Nginx upstreams)

##### Architectural Patterns and Design Principles
- Layered Architecture in api:
- Controller → Service → Repository (with JPA + QueryDSL)
- Annotation‐driven security (JwtAuthenticationFilter, SecurityConfig)
- Read–Write Splitting via RoutingDataSource for DB replication
- Containerization: each service is an independent Docker image
- CI/CD for immutable infrastructure and zero‐downtime deploys
- Externalization of config: Spring profiles (dev, prod, GCP, JWT, pay)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Users"
        CustBrowser["Customer Browser"]:::user
        ProvBrowser["Provider Browser"]:::user
    end

    Nginx["Nginx (Edge Router / Load Balancer)"]:::edge

    subgraph "Application Tier"
        subgraph "Frontend Services"
            CustApp["customer-app containers"]:::frontend
            ProvApp["provider-app containers"]:::frontend
        end
        subgraph "Backend Services"
            API["api containers"]:::backend
        end
    end

    subgraph "API Codebase"
        Dockerfile["Dockerfile"]:::code
        Jenkinsfile["Jenkinsfile"]:::code
        Entry["ApiApplication.java"]:::code
        Controllers["Controller Package"]:::code
        Services["Service Package"]:::code
        Repos["Repository + RoutingDS"]:::code
        Security["Security Config"]:::code
        DataSource["DataSourceConfig.java & RoutingDataSource"]:::code
        Profiles["application-*.yml"]:::code
        GCPCreds["GCP Credentials File"]:::code
    end

    subgraph "Data Tier"
        Master["MySQL Master"]:::db
        Replica["MySQL Replica(s)"]:::db
    end

    subgraph "External Services"
        GCP["GCP Cloud Storage"]:::external
        Kakao["KakaoPay API"]:::external
    end

    subgraph "CI/CD" 
        Jenkins["Jenkins CI/CD"]:::cicd
        Git["Git Repository"]:::cicd
        Registry["Docker Registry"]:::cicd
    end

    CustBrowser -->|"HTTPS"| Nginx
    ProvBrowser -->|"HTTPS"| Nginx

    Nginx -->|"serves static on customer.myshop.com"| CustApp
    Nginx -->|"serves static on provider.myshop.com"| ProvApp
    Nginx -->|"proxies /api on api.myshop.com"| API

    CustApp <-->|"REST API calls"| API
    ProvApp <-->|"REST API calls"| API

    API -->|"built from code"| Dockerfile
    Dockerfile -->|build| API
    Jenkinsfile -->|pipeline for| API
    Entry -->|entry point| API
    Controllers -->|controllers| API
    Services -->|services| API
    Repos -->|repositories| API
    Security -->|security config| API
    DataSource -->|datasource config| API
    Profiles -->|profiles| API
    GCPCreds -->|credentials| API

    API -->|"writes"| Master
    API -->|"reads"| Replica
    API -->|"uploads/downloads images"| GCP
    API -->|"payment requests"| Kakao

    Git -->|on-commit triggers| Jenkins
    Jenkins -->|"build & push images"| Registry
    Jenkins -->|"deploy to"| Nginx
    Jenkins -->|"build API"| Dockerfile
    Jenkins -->|"build customer"| CustApp
    Jenkins -->|"build provider"| ProvApp

    classDef frontend fill:#B3E5FC,stroke:#0288D1,color:#000
    classDef backend fill:#C8E6C9,stroke:#388E3C,color:#000
    classDef db fill:#FFE0B2,stroke:#FB8C00,color:#000
    classDef external fill:#E0E0E0,stroke:#9E9E9E,color:#000
    classDef cicd fill:#E1BEE7,stroke:#8E24AA,color:#000
    classDef edge fill:#CFD8DC,stroke:#455A64,color:#000
    classDef user fill:#F0F4C3,stroke:#7CB342,color:#000
    classDef code fill:#F5F5F5,stroke:#BDBDBD,color:#000

    click API "https://github.com/imtaemin/myshop/tree/main/api/"
    click Dockerfile "https://github.com/imtaemin/myshop/tree/main/api/Dockerfile"
    click Jenkinsfile "https://github.com/imtaemin/myshop/tree/main/api/Jenkinsfile"
    click Entry "https://github.com/imtaemin/myshop/blob/main/api/src/main/java/com/myshop/api/ApiApplication.java"
    click Controllers "https://github.com/imtaemin/myshop/tree/main/api/src/main/java/com/myshop/api/controller/"
    click Services "https://github.com/imtaemin/myshop/tree/main/api/src/main/java/com/myshop/api/service/"
    click Repos "https://github.com/imtaemin/myshop/tree/main/api/src/main/java/com/myshop/api/repository/"
    click Security "https://github.com/imtaemin/myshop/tree/main/api/src/main/java/com/myshop/api/config/security/"
    click DataSource "https://github.com/imtaemin/myshop/blob/main/api/src/main/java/com/myshop/api/config/DataSourceConfig.java"
    click GCPCreds "https://github.com/imtaemin/myshop/blob/main/api/src/main/resources/myshop-373122-5a778e754845.json"
    click Profiles "https://github.com/imtaemin/myshop/blob/main/api/src/main/resources/application-*.yml"
    click CustApp "https://github.com/imtaemin/myshop/tree/main/customer/"
    click CustApp "https://github.com/imtaemin/myshop/tree/main/customer/Dockerfile"
    click CustApp "https://github.com/imtaemin/myshop/blob/main/customer/customer.conf"
    click CustApp "https://github.com/imtaemin/myshop/tree/main/customer/src/"
    click ProvApp "https://github.com/imtaemin/myshop/tree/main/provider/"
    click ProvApp "https://github.com/imtaemin/myshop/tree/main/provider/Dockerfile"
    click ProvApp "https://github.com/imtaemin/myshop/blob/main/provider/provider.conf"
    click ProvApp "https://github.com/imtaemin/myshop/tree/main/provider/src/"
```
