# takefumi-yoshii/nextjs-testing-strategy-2022 architecture

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

- Interactive diagram: https://gitdiagram.com/takefumi-yoshii/nextjs-testing-strategy-2022
- Repository: https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022

## Overview

##### Project type and purpose
- This is a full‑stack Next.js application showcasing a “testing strategy” for 2022. It includes:
- A React/Next.js frontend (pages, components, Storybook stories).
- Next.js API routes (serverless functions under src/pages/api).
- A Redis‑backed session store (via next-session, Docker Compose).
- A services layer for calling external APIs (services/api and services/api.example.com).
- Comprehensive testing: unit tests (Jest), integration (Jest + msw), end‑to‑end (Playwright), Storybook for components.

##### File structure
- Top‑level config and infra:
- docker‑compose.yaml (starts Redis).
- .env.development/production, Next.js configs (next.config.js, TypeScript).
- Jest, Playwright, Storybook configs.
- src/pages:
- _app.page.tsx, _document.page.tsx (Next.js custom wrappers).
- page routes for Posts and Users (list, detail, new, edit).
- API routes under src/pages/api (login, logout, posts, users).
- src/components:
- Follows Atomic Design (atoms → molecules → organisms → templates).
- Each component has .tsx, tests, stories, and styles.
- src/lib/next:
- Session management (next-session), API and GSSP middlewares for authentication, error handling.
- src/services:
- Client‑side fetchers and type definitions for your own API (services/api) and example external API (services/api.example.com).
- tests and e2e directories:
- Jest custom matchers, msw mocks, browser/node mocks, Playwright tests.

##### README
- Confirms Redis dependency and how to run the dev server: docker‑compose up (Redis) → yarn dev.

##### Detail
- Component hierarchy (atomic → molecules → organisms → templates) optionally as a side inset.
- Docker Compose starting Redis and the session flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        Browser["Browser"]:::frontend
        Storybook["Storybook"]:::testing
    end

    %% Server Layer
    subgraph "Next.js Server"
        direction TB
        subgraph "Pages (SSR/GSSP)"
            direction TB
            _app["_app.page.tsx"]:::server
            _doc["_document.page.tsx"]:::server
            index["index.page.tsx"]:::server
            PostsFolder["posts/"]:::server
            UsersFolder["users/"]:::server
        end
        subgraph "API Routes"
            direction TB
            ApiFolder["src/pages/api/"]:::server
        end
        subgraph "Middlewares"
            direction TB
            ApiMw["API Middlewares"]:::server
            Gsspmw["GSSP Middlewares"]:::server
        end
        SessionStore["Session Store Module"]:::server
    end

    %% Datastore
    Redis["Redis"]:::db

    %% External API
    ExternalAPI["api.example.com"]:::external

    %% Services Layer
    subgraph "Services Layer"
        direction TB
        ServicesInt["services/api"]:::service
        ServicesExt["services/api.example.com"]:::service
    end

    %% Testing Tools
    subgraph "Testing Tools"
        direction TB
        Jest["Jest + MSW"]:::testing
        Playwright["Playwright"]:::testing
    end

    %% Connections
    Browser -->|"Page Requests / API Calls"| _app
    Browser -->|"Page Requests / API Calls"| index
    Browser -->|"Fetch via SDK"| ServicesInt
    Browser -->|"Fetch via SDK"| ServicesExt
    _app -->|"Session Read/Write"| Redis
    index -->|"Session Read/Write"| Redis
    ApiFolder -->|"Uses Middlewares"| ApiMw
    _app -->|"Uses GSSP Middleware"| Gsspmw
    ApiFolder -->|"Session Read/Write"| Redis
    ServicesExt -->|"HTTP Calls"| ExternalAPI
    ApiMw -->|"Attach Session"| SessionStore
    Gsspmw -->|"Attach Session"| SessionStore
    Jest -->|"Mocks APIs via MSW"| ApiFolder
    Playwright -->|"E2E Tests on Browser"| Browser

    %% Click Events
    click _app "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/src/pages/_app.page.tsx"
    click _doc "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/src/pages/_document.page.tsx"
    click index "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/src/pages/index.page.tsx"
    click PostsFolder "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/tree/main/src/pages/posts/"
    click UsersFolder "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/tree/main/src/pages/users/"
    click ApiFolder "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/tree/main/src/pages/api/"
    click SessionStore "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/src/lib/next-session/index.ts"
    click ApiMw "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/tree/main/src/lib/next/api/middlewares/"
    click Gsspmw "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/tree/main/src/lib/next/gssp/middlewares/"
    click ServicesInt "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/src/services/api/index.ts"
    click ServicesExt "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/src/services/api.example.com/index.ts"
    click Jest "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/jest.config.js"
    click Playwright "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/blob/main/playwright.config.ts"
    click Storybook "https://github.com/takefumi-yoshii/nextjs-testing-strategy-2022/tree/main/.storybook/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0288D1,stroke-width:2px
    classDef server fill:#E3F2FD,stroke:#1976D2,stroke-width:2px
    classDef db fill:#E8F5E9,stroke:#388E3C,stroke-width:2px
    classDef service fill:#E8F5FF,stroke:#1976D2,stroke-width:2px
    classDef external fill:#FFF8E1,stroke:#F9A825,stroke-width:2px,stroke-dasharray: 5 5
    classDef testing fill:#F3E5F5,stroke:#8E24AA,stroke-width:2px,stroke-dasharray: 5 5
```
