# hsu022210/snippets-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/hsu022210/snippets-frontend
- Repository: https://github.com/hsu022210/snippets-frontend

## Overview

##### Project Type and Purpose
- This is a single-page frontend web application (“Code Snippets Frontend”) built with React, TypeScript, and Vite.
- It provides a UI for users to log in, create, view, search, filter, edit, and delete code snippets, with syntax highlighting (CodeMirror), theming, and responsive design.
- The app communicates with a separate backend API (not included here) via Axios-based services.

##### File Structure
Top-level files & folders
- public/index.html – host HTML
- src/main.tsx & src/App.tsx – React entrypoint and root component
- src/components/ – reusable UI components, subdivided into:
– auth (login/register forms, password rules, submit buttons)
– snippet (snippet-related UI: cards, filter, search, modals)
– shared (buttons, cards, code editor wrapper, containers)
– common components (Footer, Navigation, ErrorBoundary, Loading spinners)
- src/pages/ – page-level containers for routes (Home, Login, Register, SnippetList, SnippetDetail, Profile, Settings, etc.)
- src/contexts/ – React Contexts managing global state (AuthContext, ThemeContext, ToastContext)
- src/hooks/ – custom hooks for API calls, snippet management, theming, sharing, preview sizing, filter state
- src/services/ – API layer abstractions (api.ts config, authService.ts, snippetService.ts)
- src/utils/ – pure utility functions (language utilities, pagination, DOM helpers, theming)
- src/styles/ – SCSS files (variables, mixins, component-specific styles)
- src/types/ – TypeScript interfaces/types for API payloads, auth, snippets, routes, UI, errors
- src/test/ & __tests__ – Vitest/React Testing Library setup, handler mocks, tests for components, hooks, contexts, utils
Configuration & Build
- vite.config.ts, tsconfig.json, eslint.config.ts

##### README for Additional Insights
- Describes tech stack and testing strategy (Vitest, RTL).
- Explains project structure in brief.

##### Detail Recommendations
- Don’t treat the UI as a single block—break it into pages, component groups, shared vs. feature components.
- How state flows from Context Providers into UI, and how events bubble up to hooks.
- SCSS styling pipeline if needed to illustrate theming/customization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Runtime
    subgraph "Browser Runtime"
        direction TB
        Browser["User Browser"]:::external
        HTML["public/index.html"]:::frontend
        Main["src/main.tsx"]:::frontend
        App["src/App.tsx"]:::frontend

        Browser -->|loads| HTML
        HTML -->|bootstraps| Main
        Main -->|renders| App
    end

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Pages["Page Components<br/>(src/pages/)"]:::frontend
        AuthComps["Auth Components<br/>(src/components/auth/)"]:::frontend
        SnippetComps["Snippet Components<br/>(src/components/snippet/)"]:::frontend
        SharedComps["Shared UI Components<br/>(src/components/shared/)"]:::frontend
        CommonComps["Common Components<br/>(src/components/)"]:::frontend

        App -->|routes to| Pages
        Pages -->|uses| AuthComps
        Pages -->|uses| SnippetComps
        Pages -->|uses| SharedComps
        Pages -->|uses| CommonComps
    end

    %% State & Logic Layer
    subgraph "State & Logic Layer"
        direction TB
        subgraph "Context Providers"
            direction TB
            AuthCtx["AuthContext<br/>(src/contexts/AuthContext.tsx)"]:::logic
            ThemeCtx["ThemeContext<br/>(src/contexts/ThemeContext.tsx)"]:::logic
            ToastCtx["ToastContext<br/>(src/contexts/ToastContext.tsx)"]:::logic
        end
        subgraph "Custom Hooks"
            direction TB
            HookAPI["useApiRequest<br/>(src/hooks/useApiRequest.ts)"]:::logic
            HookSnippet["useSnippet<br/>(src/hooks/useSnippet.ts)"]:::logic
            HookList["useSnippetList<br/>(src/hooks/useSnippetList.ts)"]:::logic
            HookTheme["useCodeMirrorTheme<br/>(src/hooks/useCodeMirrorTheme.ts)"]:::logic
            HookFilter["useFilterState<br/>(src/hooks/useFilterState.ts)"]:::logic
            HookPreview["usePreviewHeight<br/>(src/hooks/usePreviewHeight.ts)"]:::logic
            HookShare["useShareSnippet<br/>(src/hooks/useShareSnippet.ts)"]:::logic
        end

        App -->|wrapped by| AuthCtx
        App -->|wrapped by| ThemeCtx
        App -->|wrapped by| ToastCtx

        AuthComps -->|calls| HookAPI
        SnippetComps -->|calls| HookSnippet
        SnippetComps -->|calls| HookList
        SharedComps -->|calls| HookTheme
        SnippetComps -->|calls| HookFilter
        SnippetComps -->|calls| HookPreview
        SnippetComps -->|calls| HookShare
    end

    %% Service/API Layer
    subgraph "Services/API Layer"
        direction TB
        APIConfig["api.ts<br/>(src/services/api.ts)"]:::service
        AuthService["authService.ts<br/>(src/services/authService.ts)"]:::service
        SnipService["snippetService.ts<br/>(src/services/snippetService.ts)"]:::service
        ServiceIndex["index.ts<br/>(src/services/index.ts)"]:::service

        HookAPI -->|uses| APIConfig
        HookAPI -->|calls| AuthService
        HookSnippet -->|calls| SnipService
        HookList -->|calls| SnipService
        ServiceIndex -->|aggregates| APIConfig
        ServiceIndex -->|aggregates| AuthService
        ServiceIndex -->|aggregates| SnipService
    end

    %% Utilities & Styles
    subgraph "Utilities & Styles"
        direction TB
        Utils["Utilities<br/>(src/utils/)"]:::service
        Styles["SCSS Styles<br/>(src/styles/)"]:::service

        SharedComps -->|imports| Styles
        AuthComps -->|imports| Styles
        SnippetComps -->|imports| Styles
        Utils -->|used by| HookFilter
        Utils -->|used by| HookShare
        Utils -->|used by| HookTheme
    end

    %% External Libraries & Services
    subgraph "External Services"
        direction TB
        Backend["Backend API"]:::external
        CodeMirror["CodeMirror 6"]:::library
        Bootstrap["Bootstrap 5<br/>& React-Bootstrap"]:::library
        CDN["CDN / Asset Host"]:::external

        APIConfig -->|HTTP requests| Backend
        SnipService -->|HTTP requests| Backend
        AuthService -->|HTTP requests| Backend
        SharedComps -->|renders code editor| CodeMirror
        SharedComps -->|uses components| Bootstrap
        HTML -->|serves assets| CDN
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        direction TB
        Vite["vite.config.ts"]:::build
        TSConfig["tsconfig.json<br/>tsconfig.node.json"]:::build
        ESLint["eslint.config.ts"]:::build
        Dist["dist/ (build output)"]:::build

        Main -->|bundled by| Vite
        App -->|type-checked by| TSConfig
        App -->|linted by| ESLint
        Vite -->|outputs| Dist
    end

    %% Legend and Styling
    classDef frontend fill:#cfe2ff,stroke:#084298,color:#084298;
    classDef logic fill:#d1e7dd,stroke:#0f5132,color:#0f5132;
    classDef service fill:#fff3cd,stroke:#664d03,color:#664d03;
    classDef external fill:#e2e3e5,stroke:#41464b,color:#41464b;
    classDef library fill:#f8d7da,stroke:#842029,color:#842029;
    classDef build fill:#e7cbf3,stroke:#5a189a,color:#5a189a;

    %% Click Events
    click Main "https://github.com/hsu022210/snippets-frontend/blob/main/src/main.tsx"
    click App "https://github.com/hsu022210/snippets-frontend/blob/main/src/App.tsx"
    click HTML "https://github.com/hsu022210/snippets-frontend/blob/main/public/index.html"
    click Pages "https://github.com/hsu022210/snippets-frontend/tree/main/src/pages/"
    click AuthComps "https://github.com/hsu022210/snippets-frontend/tree/main/src/components/auth/"
    click SnippetComps "https://github.com/hsu022210/snippets-frontend/tree/main/src/components/snippet/"
    click SharedComps "https://github.com/hsu022210/snippets-frontend/tree/main/src/components/shared/"
    click CommonComps "https://github.com/hsu022210/snippets-frontend/tree/main/src/components/"
    click AuthCtx "https://github.com/hsu022210/snippets-frontend/blob/main/src/contexts/AuthContext.tsx"
    click ThemeCtx "https://github.com/hsu022210/snippets-frontend/blob/main/src/contexts/ThemeContext.tsx"
    click ToastCtx "https://github.com/hsu022210/snippets-frontend/blob/main/src/contexts/ToastContext.tsx"
    click HookAPI "https://github.com/hsu022210/snippets-frontend/blob/main/src/hooks/useApiRequest.ts"
    click HookSnippet "https://github.com/hsu022210/snippets-frontend/blob/main/src/hooks/useSnippet.ts"
    click HookList "https://github.com/hsu022210/snippets-frontend/blob/main/src/hooks/useSnippetList.ts"
    click HookTheme "https://github.com/hsu022210/snippets-frontend/blob/main/src/hooks/useCodeMirrorTheme.ts"
    click HookFilter "https://github.com/hsu022210/snippets-frontend/blob/main/src/hooks/useFilterState.ts"
    click HookPreview "https://github.com/hsu022210/snippets-frontend/blob/main/src/hooks/usePreviewHeight.ts"
    click HookShare "https://github.com/hsu022210/snippets-frontend/blob/main/src/hooks/useShareSnippet.ts"
    click APIConfig "https://github.com/hsu022210/snippets-frontend/blob/main/src/services/api.ts"
    click AuthService "https://github.com/hsu022210/snippets-frontend/blob/main/src/services/authService.ts"
    click SnipService "https://github.com/hsu022210/snippets-frontend/blob/main/src/services/snippetService.ts"
    click ServiceIndex "https://github.com/hsu022210/snippets-frontend/blob/main/src/services/index.ts"
```
