# devpalsplus/frontend architecture

> Architecture diagram of the GitHub repository devpalsplus/frontend, 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/devpalsplus/frontend
- Repository: https://github.com/devpalsplus/frontend

## Overview

##### Project Type and Purpose
- This is the **frontend** of a full-stack web application called *DevPals*.
- Built with **React**, **TypeScript**, **Vite**, **Styled-Components**, **React Query**, and **Zustand**, it serves as a Single-Page Application (SPA) that consumes a RESTful NestJS backend.
- Its purpose is to help junior developers discover, apply to, and manage side-project postings, while interacting with senior mentors and other community members.

##### File-Structure Analysis
- Top-level config & tooling: `vite.config.ts`, `tsconfig.json`, `.github/workflows` (CI/CD), Storybook config.
- `public/`: static assets and the mock Service Worker.
- `src/`:
- **pages/**: top-level routes (Home, Login, Apply, CreateProject, MyPage, etc.)
- **components/**: reusable UI blocks organized by feature (common, home, comment, m ypage, projectForm, etc.)
- **api/**: wrappers around HTTP calls (e.g., `auth.api.ts`, `projectLists.api.ts`)
- **hooks/**: custom hooks, divided into domain hooks (ProjectHooks, CommentHooks) and generic hooks (useAuth, useModal)
- **store/**: Zustand stores (e.g., `authStore.ts`)
- **context/**: React Context providers (ModalContext, ErrorBoundaryContext, SearchFilteringContext)
- **routes/**: routing config (`AppRoutes.tsx`)
- **models/**: TypeScript type definitions for API payloads and domain models
- **constants/**, **util/**, **assets/**, **style/**
- Mocks & tests: `src/mock/` for MSW, `setupTests.ts`, `vitest.d.ts`, `__tests__` under util.

##### Key Architecture & Interactions
a. **UI Layer**
- **Pages**: mounted by the router.
- **Components**: presentational and container components under `components/`.
b. **Routing**
- `AppRoutes.tsx` configures public and protected routes using React Router and `ProtectRoute`.
c. **State Management**
- **Zustand** (`authStore`) for global auth state.
- **React Query** for server state (queries and mutations via custom hooks).
d. **Data-Fetching Layer**
- **api/** modules build HTTP requests to `VITE_APP_API_BASE_URL`.
- **React Query Hooks** wrap these APIs (`useGetProjectData`, `usePostComment`, etc.) and manage caching.
e. **Context Providers**
- **ModalContext** for global modal dialogs.
- **ErrorBoundaryContext** for error handling.
- **SearchFilteringContext** for filter state on the home page.
f. **Styling**
- **Styled-Components** used per component and per page.
g. **Utilities & Models**
- Helpers in `util/` (date formatting, crypto utils).
- Domain types in `models/`.
h. **External Services**
- **Backend API** on AWS (NestJS + Prisma + MySQL).
- **Image CDN** (S3).
- **CI/CD**: GitHub Actions, deploying static to S3 via AWS CLI.

##### Architectural Patterns & Principles
- **Component-Based UI**: modularization by feature and reusability (common/ vs feature/).
- **Separation of Concerns**: distinct layers for UI, routing, state, data fetching, contexts.
- **Single Source of Truth**: central stores for auth & server data (Zustand + React Query).
- **Provider Pattern**: contexts wrapping the app for cross-cutting concerns (modal, error, filtering).
- **API Abstraction**: each domain API in its own module under `api/`.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "User Layer" 
        direction TB
        User["Browser / User"]:::external
    end

    subgraph "React SPA" 
        direction TB

        subgraph "Routing Layer"
            direction TB
            AppRoutes["AppRoutes (src/routes)"]:::ui
            ProtectRoute["ProtectRoute (src/components/common)"]:::ui
        end

        subgraph "UI Components"
            direction TB
            Pages["Pages (src/pages)"]:::ui
            FeatureComponents["Feature Components (src/components/)"]:::ui
            CommonComponents["Common Components (src/components/common/)"]:::ui
        end

        subgraph "State Layer"
            direction TB
            ZustandStore["Zustand Store\nauthStore.ts"]:::state
            ReactQueryCache["React Query Cache\n(useQuery/useMutation)"]:::state
        end

        subgraph "Data Layer"
            direction TB
            APIClient["HTTP Client\nhttp.api.ts"]:::data
            DomainAPIs["Domain APIs (src/api/)"]:::data
            ReactQueryHooks["React Query Hooks (src/hooks/)"]:::data
            QueryKeys["Query Keys\n(src/hooks/queries/keys.ts)"]:::data
        end

        subgraph "Context Providers"
            direction TB
            ModalContext["ModalContext\n(src/context/ModalContext.tsx)"]:::state
            ErrorBoundaryContext["ErrorBoundaryContext\n(src/context/ErrorBoundaryContext.tsx)"]:::state
            SearchFilterContext["SearchFilteringContext\n(src/context/SearchFilteringContext.tsx)"]:::state
        end

        subgraph "Utilities & Models"
            direction TB
            UtilFunctions["Utility Functions (src/util/)"]:::data
            UtilTests["Util Tests (src/util/__tests__/)"]:::data
            Models["Domain Models (src/models/)"]:::data
        end

        subgraph "Mock Layer"
            direction TB
            MSWWorker["mockServiceWorker.js\n(public/mockServiceWorker.js)"]:::data
            MockHandlers["Mock Handlers (src/mock/)"]:::data
        end

    end

    subgraph "External Services"
        direction TB
        BackendAPI["Backend API (NestJS on AWS)"]:::external
        ImageCDN["Image CDN (AWS S3)"]:::external
        CICD["CI/CD (GitHub Actions → S3)"]:::external
    end

    %% Connections
    User -->|"navigates"| AppRoutes
    AppRoutes -->|"protects"| ProtectRoute
    AppRoutes -->|"renders"| Pages
    Pages -->|"uses"| FeatureComponents
    Pages -->|"uses"| CommonComponents

    FeatureComponents -->|"calls hooks"| ReactQueryHooks
    CommonComponents -->|"calls hooks"| ReactQueryHooks

    ReactQueryHooks -->|"fetches via"| DomainAPIs
    DomainAPIs -->|"HTTP via"| APIClient
    APIClient -->|"requests"| BackendAPI
    BackendAPI -->|"responds"| APIClient
    APIClient -->|"returns"| ReactQueryHooks
    ReactQueryHooks -->|"updates"| ReactQueryCache
    ReactQueryCache -->|"feeds"| Pages

    ZustandStore -.->|"provides auth"| APIClient
    ZustandStore -->|"state available"| Pages

    ModalContext -.->|"provides"| Pages
    ErrorBoundaryContext -.->|"wraps"| Pages
    SearchFilterContext -.->|"wraps"| Pages

    Pages -->|"imports"| UtilFunctions
    UtilFunctions --> UtilTests
    Pages -->|"uses models"| Models

    Pages -->|"development mocks"| MockHandlers
    MSWWorker -->|"intercepts"| DomainAPIs

    CICD -->|"deploys"| ImageCDN
    CICD -->|"deploys"| BackendAPI

    %% Click Events
    click AppRoutes "https://github.com/devpalsplus/frontend/blob/develop/src/routes/AppRoutes.tsx"
    click ProtectRoute "https://github.com/devpalsplus/frontend/blob/develop/src/components/common/ProtectRoute.tsx"
    click Pages "https://github.com/devpalsplus/frontend/tree/develop/src/pages/"
    click FeatureComponents "https://github.com/devpalsplus/frontend/tree/develop/src/components/"
    click CommonComponents "https://github.com/devpalsplus/frontend/tree/develop/src/components/common/"
    click APIClient "https://github.com/devpalsplus/frontend/blob/develop/src/api/http.api.ts"
    click DomainAPIs "https://github.com/devpalsplus/frontend/tree/develop/src/api/"
    click ReactQueryHooks "https://github.com/devpalsplus/frontend/tree/develop/src/hooks/"
    click QueryKeys "https://github.com/devpalsplus/frontend/blob/develop/src/hooks/queries/keys.ts"
    click ZustandStore "https://github.com/devpalsplus/frontend/blob/develop/src/store/authStore.ts"
    click ModalContext "https://github.com/devpalsplus/frontend/blob/develop/src/context/ModalContext.tsx"
    click ErrorBoundaryContext "https://github.com/devpalsplus/frontend/blob/develop/src/context/ErrorBoundaryContext.tsx"
    click SearchFilterContext "https://github.com/devpalsplus/frontend/blob/develop/src/context/SearchFilteringContext.tsx"
    click UtilFunctions "https://github.com/devpalsplus/frontend/tree/develop/src/util/"
    click UtilTests "https://github.com/devpalsplus/frontend/tree/develop/src/util/__tests__/"
    click Models "https://github.com/devpalsplus/frontend/tree/develop/src/models/"
    click MSWWorker "https://github.com/devpalsplus/frontend/blob/develop/public/mockServiceWorker.js"
    click MockHandlers "https://github.com/devpalsplus/frontend/tree/develop/src/mock/"
    click CICD "https://github.com/devpalsplus/frontend/tree/develop/.github/workflows/"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef state fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D8BFD8,stroke:#000,stroke-width:1px
```
