# yongsin0129/project-cheapskate-fe architecture

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

- Interactive diagram: https://gitdiagram.com/yongsin0129/project-cheapskate-fe
- Repository: https://github.com/yongsin0129/project-cheapskate-fe

## Overview

##### Project type and purpose
- This is a TypeScript‑based React single‑page application (SPA) built with Vite.
- Its purpose is to serve as the frontend for “小氣鬼的電影追蹤工具,” a movie‑tracking tool that lets users browse, follow, and save movies via a GraphQL backend API.

##### Top‑level components
a. User & Browser (Client)
b. Static Asset Host / CDN (Vercel)
c. Frontend SPA (React + Vite)
- Entry point: vite.dev server (dev mode) & built static files (prod mode)
- UI Components & Pages (src/pages, src/components)
- Context Providers (ApolloClientContext, ReactQueryContext, ColorModeContext, AppBarStateContext, HomePageStateContext, MeContext)
- Routing & Guards (ProtectedRoute)
- Custom Hooks & GraphQL (useFetchMovieDetails, useTriggerMovieDetails; generated/graphql.ts; gqlQuerys)
- Styling (SCSS modules under src/components/styles, src/pages/styles, src/style)
d. Backend GraphQL API (external repo)
e. Database (e.g., PostgreSQL/MySQL behind the backend)
f. Authentication Service (JWT / session managed by backend)

##### Relationships & data flows
- Browser → (HTTPS) → CDN/Vercel → serves static SPA
- SPA → (GraphQL queries & mutations) → Backend API
- Backend → (ORM) → Database
- Backend → issues JWT tokens → SPA stores tokens (e.g., in memory or cookies)

##### Architectural patterns & design principles
- Component‑based UI (atomic components under src/components, page‑level under src/pages)
- Context API for cross‑cutting concerns (authentication, theming, global state)
- GraphQL client via Apollo + React Query for data fetching & caching
- Hook abstraction for API interactions
- SCSS modules for local‑scoped styling
- SPA routing with protected routes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External and Ops
    subgraph "External Services" 
        direction TB
        User["User & Browser"]:::external
        GitHub["GitHub"]:::external
        VercelCI["Vercel CI/CD"]:::external
        CDN["CDN / Vercel"]:::external
    end

    GitHub -->|push code| VercelCI
    VercelCI -->|deploy static files| CDN
    User -->|access via HTTPS| CDN

    %% Frontend Layer
    subgraph "Frontend SPA (React + Vite)" 
        direction TB
        subgraph "Entry & Bootstrapping" 
            direction TB
            ViteConfig["vite.config.ts"]:::frontend
            IndexHTML["index.html"]:::frontend
            MainTSX["src/main.tsx"]:::frontend
            AppTSX["src/App.tsx"]:::frontend
        end

        subgraph "Routing & Guards" 
            direction TB
            ProtectedRoute["src/components/ProtectedRoute.tsx"]:::frontend
        end

        subgraph "UI Components" 
            direction TB
            ErrMsg["src/components/ErrorMessage.tsx"]:::frontend
            Footer["src/components/Footer.tsx"]:::frontend
            Loading["src/components/Loading.tsx"]:::frontend
            ToggleBtn["src/components/ToggleModeButton.tsx"]:::frontend
            UserVal["src/components/UserValidator.tsx"]:::frontend
            subgraph "AppBar Components"
                Tab["src/components/appBar/Tab.tsx"]:::frontend
                AppBarIndex["src/components/appBar/index.tsx"]:::frontend
            end
            subgraph "Table Components"
                DetailModal["src/components/table/DetailModal.tsx"]:::frontend
                HeartIcon["src/components/table/HeartIcon.tsx"]:::frontend
                StatusCell["src/components/table/StatusCell.tsx"]:::frontend
                TableIndex["src/components/table/index.tsx"]:::frontend
            end
        end

        subgraph "Pages" 
            direction TB
            HomePage["src/pages/HomePage.tsx"]:::frontend
            AllMovies["src/pages/AllMovies.tsx"]:::frontend
            FirstRound["src/pages/FirstRoundMovie.tsx"]:::frontend
            SecondRound["src/pages/SecondRoundMovie.tsx"]:::frontend
            Followed["src/pages/FollowedMovies.tsx"]:::frontend
            SignIn["src/pages/SignIn.tsx"]:::frontend
            SignUp["src/pages/SignUp.tsx"]:::frontend
            PagesIndex["src/pages/index.tsx"]:::frontend
        end

        subgraph "Context Providers" 
            direction TB
            ApolloCtx["src/context/ApolloClientContext.tsx"]:::frontend
            ReactQueryCtx["src/context/ReactQueryContext.tsx"]:::frontend
            ColorModeCtx["src/context/ColorModeContext.tsx"]:::frontend
            AppBarState["src/context/AppBarStateContext.tsx"]:::frontend
            HomePageState["src/context/HomePageStateContext.tsx"]:::frontend
            MeCtx["src/context/MeContext.tsx"]:::frontend
            CtxIndex["src/context/index.tsx"]:::frontend
        end

        subgraph "Data Layer (GraphQL & Hooks)" 
            direction TB
            GeneratedGQL["src/generated/graphql.ts"]:::data
            GQLQueries["src/gqlQuerys/index.ts"]:::data
            FetchHook["src/components/table/hooks/useFetchMovieDetails.tsx"]:::data
            TriggerHook["src/components/table/hooks/useTriggerMovieDetails.tsx"]:::data
        end

        subgraph "Styling" 
            direction TB
            CompStyles["src/components/styles"]:::frontend
            TableStyles["src/components/table/styles"]:::frontend
            PageStyles["src/pages/styles/homePage.module.scss"]:::frontend
            GlobalStyles["src/style"]:::frontend
        end
    end

    CDN -->|"serves SPA"| MainTSX
    MainTSX -->|renders| AppTSX
    AppTSX -->|uses| ProtectedRoute
    ProtectedRoute -->|guards| PagesIndex

    AppTSX --> UIComponents
    UIComponents --> Pages
    AppTSX --> ContextProviders
    ContextProviders --> DataLayer
    DataLayer -->|GraphQL queries/mutations| API

    %% Backend Layer
    subgraph "Backend GraphQL API" 
        direction TB
        API["GraphQL API"]:::backend
        AuthService["Authentication (JWT)"]:::backend
    end
    API -->|ORM| DB

    subgraph "Database" 
        direction TB
        DB["PostgreSQL / MySQL"]:::database
    end

    AppTSX -->|login mutation| AuthService
    AuthService -->|issues JWT| ContextProviders
    UIComponents -->|fetch hooks| DataLayer

    %% Legends
    subgraph "Legend"
        direction TB
        A["UI Layer"]:::frontend
        B["Data Layer"]:::data
        C["External/Hosting"]:::external
        D["Database"]:::database
    end

    %% Click Events
    click ViteConfig "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/vite.config.ts"
    click IndexHTML "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/index.html"
    click MainTSX "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/main.tsx"
    click AppTSX "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/App.tsx"
    click ProtectedRoute "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/ProtectedRoute.tsx"
    click ErrMsg "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/ErrorMessage.tsx"
    click Footer "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/Footer.tsx"
    click Loading "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/Loading.tsx"
    click ToggleBtn "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/ToggleModeButton.tsx"
    click UserVal "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/UserValidator.tsx"
    click Tab "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/appBar/Tab.tsx"
    click AppBarIndex "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/appBar/index.tsx"
    click DetailModal "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/table/DetailModal.tsx"
    click HeartIcon "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/table/HeartIcon.tsx"
    click StatusCell "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/table/StatusCell.tsx"
    click TableIndex "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/table/index.tsx"
    click HomePage "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/HomePage.tsx"
    click AllMovies "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/AllMovies.tsx"
    click FirstRound "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/FirstRoundMovie.tsx"
    click SecondRound "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/SecondRoundMovie.tsx"
    click Followed "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/FollowedMovies.tsx"
    click SignIn "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/SignIn.tsx"
    click SignUp "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/SignUp.tsx"
    click PagesIndex "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/index.tsx"
    click ApolloCtx "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/context/ApolloClientContext.tsx"
    click ReactQueryCtx "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/context/ReactQueryContext.tsx"
    click ColorModeCtx "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/context/ColorModeContext.tsx"
    click AppBarState "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/context/AppBarStateContext.tsx"
    click HomePageState "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/context/HomePageStateContext.tsx"
    click MeCtx "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/context/MeContext.tsx"
    click CtxIndex "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/context/index.tsx"
    click GeneratedGQL "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/generated/graphql.ts"
    click GQLQueries "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/gqlQuerys/index.ts"
    click FetchHook "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/table/hooks/useFetchMovieDetails.tsx"
    click TriggerHook "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/components/table/hooks/useTriggerMovieDetails.tsx"
    click CompStyles "https://github.com/yongsin0129/project-cheapskate-fe/tree/master/src/components/styles"
    click TableStyles "https://github.com/yongsin0129/project-cheapskate-fe/tree/master/src/components/table/styles"
    click PageStyles "https://github.com/yongsin0129/project-cheapskate-fe/blob/master/src/pages/styles/homePage.module.scss"
    click GlobalStyles "https://github.com/yongsin0129/project-cheapskate-fe/tree/master/src/style"

    %% Styles
    classDef frontend fill:#e0f7e9,stroke:#2e7d32,color:#1b5e20
    classDef data fill:#e3f2fd,stroke:#1565c0,color:#0d47a1
    classDef external fill:#f5f5f5,stroke:#616161,color:#212121
    classDef backend fill:#ffebee,stroke:#c62828,color:#b71c1c
    classDef database fill:#fff3e0,stroke:#ef6c00,color:#e65100
```
