# mg6mg/nextjs-simple-blog architecture

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

- Interactive diagram: https://gitdiagram.com/mg6mg/nextjs-simple-blog
- Repository: https://github.com/mg6mg/nextjs-simple-blog

## Overview

##### Main Components
- Frontend Application – The Next.js application which is organized under the “app” directory. This contains the main routing logic with subfolders for articles, tags, search, and other pages.
- UI Components – Located in the “components” directory. These include the Article, ArticleList, Pagination, Header, Footer, Nav, Date, TagList, etc. They form the building blocks of various pages.
- MicroCMS Integration – Found in the “libs” directory (e.g., microcms.ts) and referenced in the constants. This module is responsible for fetching data from microCMS.
- Configuration & Environment – Environment variables and configuration files (Next.js config, .env file instructions, ESLint, npm config files) form a foundation for deployment and operation.
- Static Assets – The “public” directory holds images and any static files such as the cover image and Vercel deployment reference images.

##### Relationships and Interactions
- The “app” directory defines the routing structure. For instance, dynamic paths for articles ([slug]), tags ([tagId]), and search components are mapped to specific page components.
- Each page in “app” typically pulls in UI components from the “components” folder, establishing a clear separation of presentation (components) from page routing.
- The integration layer (libs/microcms.ts) communicates with the external microCMS service. Pages and components that display CMS data depend on this module to fetch content.
- Global styling such as “globals.css” and specific module styles (found in both app and components directories) define the look and feel.
- Deployment settings are guided by environment variables (documented in the README) and these, along with the Next.js configuration (next.config.js), ensure the correct operation in both local and production environments (e.g., on Vercel).

##### Architectural Patterns and Design Principles
- Modular Design – Separation between the view (UI/components) and the data layer (microCMS integration, utilities).
- Dynamic Routing – The “app” directory follows Next.js conventions (e.g., "[slug]" for dynamic routes).
- Server-Side Rendering & Static Generation – Implied by Next.js usage which may fetch data at request time or build time from microCMS.
- Separation of Concerns – Different directories for components, pages, utilities, and configuration, ensuring clear boundaries.

##### Relevant Technologies and Frameworks
- Next.js for the frontend application architecture and routing.
- microCMS as the headless Content Management System.
- Node.js (version 18+) as the runtime environment.
- CSS Modules (as seen by .module.css files) for component-scoped styling.
- Vercel as a deployment platform.

– “Next.js Routing (App Directory)” – Subdivide for Articles, Tags, Search, etc.
– “UI Components” – Enclose components like Article, ArticleListItem, Pagination, etc.
– Data flow from the Next.js pages to the microCMS integration module.
– Composition flow from pages to UI components.
- Clearly label every component. Under or next to each, note the key files (e.g., “articles/[slug]/page.tsx” for article routing, “libs/microcms.ts” for CMS integration).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Next.js Routing Layer
    subgraph "Next.js Routing (App)"
        A["Next.js Routing (App)"]:::routing
        B["Article Page (/articles/[slug]/page.tsx)"]:::routing
        C["Tags Page (/tags/[tagId]/page.tsx)"]:::routing
        D["Search Page (/search/page.tsx)"]:::routing
    end
    A --> B
    A --> C
    A --> D

    %% UI Components Layer
    subgraph "UI Components"
        E["UI Components (Article,ArticleList,Pagination,Header,Footer,Nav,Date,TagList)"]:::ui
    end

    %% MicroCMS Integration
    F["MicroCMS Integration (libs/microcms.ts)"]:::cms
    G["External microCMS API"]:::cms

    %% Configuration & Environment
    subgraph "Configuration & Environment"
        H1["next.config.js"]:::config
        H2[".eslintrc.json"]:::config
        H3[".npmrc"]:::config
        H4["constants/index.ts"]:::config
    end

    %% Static Assets
    I["Static Assets (public)"]:::static

    %% Connections from Routing Pages to UI Components and MicroCMS Integration
    B --> E
    C --> E
    D --> E

    B --> F
    C --> F
    D --> F

    %% MicroCMS Integration calls External microCMS API
    F --> G

    %% Configuration supports both Routing and MicroCMS Integration
    H1 --> A
    H2 --> A
    H3 --> A
    H4 --> A

    H1 --> F
    H2 --> F
    H3 --> F
    H4 --> F

    %% UI Components uses Static Assets
    I --> E

    %% Click Events
    click A "https://github.com/mg6mg/nextjs-simple-blog/tree/main/app"
    click E "https://github.com/mg6mg/nextjs-simple-blog/tree/main/components"
    click F "https://github.com/mg6mg/nextjs-simple-blog/blob/main/libs/microcms.ts"
    click H1 "https://github.com/mg6mg/nextjs-simple-blog/blob/main/next.config.js"
    click H2 "https://github.com/mg6mg/nextjs-simple-blog/blob/main/.eslintrc.json"
    click H3 "https://github.com/mg6mg/nextjs-simple-blog/blob/main/.npmrc"
    click H4 "https://github.com/mg6mg/nextjs-simple-blog/blob/main/constants/index.ts"
    click I "https://github.com/mg6mg/nextjs-simple-blog/tree/main/public"

    %% Styling
    classDef routing fill:#ade1f9,stroke:#1f77b4,stroke-width:2px;
    classDef ui fill:#ffddb3,stroke:#ff8c00,stroke-width:2px;
    classDef cms fill:#d4fccc,stroke:#28a745,stroke-width:2px;
    classDef config fill:#e1d5e7,stroke:#6f42c1,stroke-width:2px;
    classDef static fill:#f9e2ae,stroke:#f39c12,stroke-width:2px;
```
