# yapp-github/25th-web-team-2-fe architecture

> Architecture diagram of the GitHub repository yapp-github/25th-web-team-2-fe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yapp-github/25th-web-team-2-fe
- Repository: https://github.com/yapp-github/25th-web-team-2-fe

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js (v14) web application, written in TypeScript, which connects two user groups: researchers (who post experiments) and participants (who sign up).
- It uses Next.js App Router under `/src/app` for page rendering and server‐side API routes (e.g., `/app/api/auth/[...nextauth]/route.ts`).

##### File Structure
- Top-level directories:
- `/src/app` – Next.js pages and serverless API routes
- `/src/apis` – client‐side wrappers for calling your own API endpoints
- `/src/components`, `/src/hooks`, `/src/providers`, `/src/lib` – shared UI and utility modules
- `/src/middleware` – request middleware for auth, feature-flags, etc.
- `/mocks` – MSW setup for local development and testing
- Configuration files: `next.config.mjs`, `.eslintrc.json`, `tsconfig.json`, GitHub Actions workflows.

##### Main System Components
a. Frontend Client (Browser)
- Renders React UI via Next.js (Server-Side Rendering & Client-Side Navigation)
- Uses TanStack Query for data fetching, React Hook Form & Zod for forms/validation
- Interacts with `/app/api/*` routes and external auth providers
b. Next.js Server (Node.js)
- Serves pages and static assets (from `/public`)
- Implements API routes under `/app/api/auth` for NextAuth, plus any other custom endpoints
- Applies middleware (`/middleware.ts`) for authentication/session checks
c. Authentication Layer
- NextAuth integration for email, Google, Naver logins
- Session management (JWT or DB adapter)
d. Data Storage
- Although not shown in code, assume a persistent database (e.g., PostgreSQL) used by NextAuth and your API routes to store users, posts, experiments
e. External Services
- Email service to send recruitment emails
- OAuth providers (Google, Naver) for authentication
- Analytics (Mixpanel)
f. Mock Service Worker (MSW)
- Intercepts network calls in development/testing to simulate API responses (`/mocks/*`)

##### Component Interactions & Data Flow
- User’s Browser → Next.js Server: requests pages/routes via HTTP(S)
- Next.js Server → Database/External APIs:
- On page load or form submit, server‐side functions query DB or call 3rd-party services
- NextAuth handlers call OAuth endpoints or DB to validate sessions
- Browser → Client API Wrappers (`/src/apis/*`) → Next.js API routes for data mutations and queries
- TanStack Query caches these responses client-side for a fast, reactive UI

##### Architectural Patterns & Principles
- App Router: file-based routing for pages and API endpoints
- Separation of concerns:
- UI components under `/components` vs. page-specific components under `/src/app`
- Logic hooks under `/src/hooks` vs. data-access wrappers in `/src/apis`
- MSW for isolating front-end dev/testing from real backend
- Data fetching pattern: React Query → hooks → API wrappers → server routes

- App Router (`/src/app`)
- API Routes (`/app/api`)
- Middleware (`/middleware.ts`)
- Database (e.g., User, Post tables)
- OAuth Providers (Google, Naver)
- Email Service
- Analytics (Mixpanel)
5) MSW under the client as a dev/testing stub.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Browser Layer
    subgraph "Client Browser" 
        direction TB
        UI["React UI\n(Next.js Pages)"]:::frontend
        Components["Shared UI Components"]:::frontend
        Hooks["Shared Hooks"]:::frontend
        Schema["Schemas & Validation\n(Zod)"]:::frontend
        subgraph "Providers"
            direction TB
            QueryProv["CustomQueryClientProvider"]:::frontend
            GlobalProv["Global Providers"]:::frontend
        end
        subgraph "API Wrappers"
            direction TB
            LoginAPI["login.ts"]:::frontend
            PostAPI["post.ts"]:::frontend
            UserAPI["user.ts"]:::frontend
        end
        subgraph "Mock Service Worker (MSW)"
            direction TB
            MSWBrowser["browser.ts"]:::dev
            MSWServer["server.ts"]:::dev
            subgraph "Handlers"
                direction TB
                HandlerIndex["index.ts"]:::dev
                HandlerPost["postHandler.ts"]:::dev
            end
        end
    end

    %% Next.js Server Layer
    subgraph "Next.js Server" 
        direction TB
        Router["App Router\n(src/app)"]:::backend
        API["Serverless API Routes\n(src/app/api)"]:::backend
        AuthRoute["NextAuth Route\n([...nextauth]/route.ts)"]:::backend
        MiddlewareMain["Middleware\n(middleware.ts)"]:::backend
        MiddlewareUtils["Middleware Utils\n(utils.ts)"]:::backend
    end

    %% Data Stores & External Services
    DB["Database"]:::database
    OAuth["OAuth Providers\n(Google, Naver)"]:::external
    Email["Email Service"]:::external
    Analytics["Mixpanel"]:::external

    %% Connections
    UI -->|SSR/CSR requests| Router
    UI --> Components
    UI --> Hooks
    UI --> Schema
    UI --> QueryProv
    UI --> GlobalProv

    LoginAPI -->|calls API routes| API
    PostAPI -->|calls API routes| API
    UserAPI -->|calls API routes| API

    UI -->|uses forms| LoginAPI
    UI -->|uses forms| PostAPI
    UI -->|uses forms| UserAPI

    MSWBrowser -.-> LoginAPI
    MSWBrowser -.-> PostAPI
    MSWBrowser -.-> UserAPI
    MSWServer -.-> API
    HandlerIndex -.-> MSWServer
    HandlerPost -.-> MSWServer

    Router -->|routes pages| API
    API -->|DB queries| DB
    AuthRoute -->|validate session| DB
    AuthRoute -->|OAuth flow| OAuth

    API -->|send emails| Email
    API -->|track events| Analytics
    Router -->|track events| Analytics

    MiddlewareMain -->|guards routes| Router
    MiddlewareUtils -->|provides helpers| MiddlewareMain

    %% Click Events
    click UI "https://github.com/yapp-github/25th-web-team-2-fe/tree/develop/src/app"
    click Router "https://github.com/yapp-github/25th-web-team-2-fe/tree/develop/src/app"
    click API "https://github.com/yapp-github/25th-web-team-2-fe/tree/develop/src/app/api"
    click AuthRoute "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/app/api/auth/[...nextauth]/route.ts"
    click MiddlewareMain "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/middleware.ts"
    click MiddlewareUtils "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/middleware/utils.ts"
    click Components "https://github.com/yapp-github/25th-web-team-2-fe/tree/develop/src/components"
    click Hooks "https://github.com/yapp-github/25th-web-team-2-fe/tree/develop/src/hooks"
    click Schema "https://github.com/yapp-github/25th-web-team-2-fe/tree/develop/src/schema"
    click QueryProv "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/providers/CustomQueryClientProvider.tsx"
    click GlobalProv "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/providers/Providers.tsx"
    click LoginAPI "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/apis/login.ts"
    click PostAPI "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/apis/post.ts"
    click UserAPI "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/apis/user.ts"
    click MSWBrowser "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/mocks/browser.ts"
    click MSWServer "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/mocks/server.ts"
    click HandlerIndex "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/mocks/handlers/index.ts"
    click HandlerPost "https://github.com/yapp-github/25th-web-team-2-fe/blob/develop/src/mocks/handlers/postHandler.ts"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#DFFFE0,stroke:#228B22,color:#228B22
    classDef external fill:#FFEFD5,stroke:#FF8C00,color:#FF8C00
    classDef database fill:#F0E68C,stroke:#B8860B,color:#B8860B
    classDef dev fill:#F3E6FF,stroke:#8A2BE2,color:#8A2BE2
```
