# phamhau23/blog architecture

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

- Interactive diagram: https://gitdiagram.com/phamhau23/blog
- Repository: https://github.com/phamhau23/blog

## Overview

##### Project Overview and Core Purpose
- Recognize that this is a full-stack Next.js application built using create-next-app.
- Its primary function is to serve a dynamic blog and category website, with embedded API routes that deliver content (blogs, categories, and home pages) to the client.
- The UI is component-driven (React components stored under the “components” directory), while the “app/api” subdirectories contain API endpoints for blog posts, home pages, and categories.

##### Main Components
a. Frontend/Client Side:
- The Next.js “app” layer which includes pages, layouts, loading states, and styles (e.g., app/page.tsx, app/layout.tsx, app/globals.css).
- Client-side rendering of dynamic pages for blogs and categories.
b. API Endpoints:
- The “app/api” folder is subdivided into relevant endpoints:
- Blog API (under app/api/blog/[id]/route.ts)
- Categories API (under app/api/categories/route.ts)
- Home API (with both list and dynamic [id] endpoints)
c. UI Components:
- The “components” directory contains essential UI elements like headers, banners, sliders, sidebars, and buttons (e.g., Header.tsx, Banner.tsx, LoadMoreButton.tsx).
d. Services and Utilities:
- “services” directory (e.g., services/getApi.tsx, services/getBlogById.tsx) for handling calls to API endpoints or external data fetching.
- “utils” directory (utils/date.ts) for common utility functions.
e. External & Configuration:
- A Firebase configuration file (firebase.config.ts) which might be used for authentication or data storage.
- Other configuration files such as next.config.ts, postcss.config.mjs, and tsconfig.json that govern build and runtime.

##### Relationships and Data Flow
- Routing split:
– Client requests a page (e.g., a blog post or category) which is served via a page component in the “app” directory.
– The page component calls API endpoints (from app/api) to fetch dynamic content from the server.
– The “services” layer (getApi and getBlogById) is used by components or pages to encapsulate API calls.
- That the UI components render the data fetched from these API endpoints.
- Optionally, represent the external integration point with Firebase (if it is used for data persistence, authentication, etc.) by linking it to the API or service layer.

##### Architectural Patterns and Design Principles
- Separation of concerns:
– The routing and API logic is separated from the UI components.
– Reusable components modularize the UI.
– Service modules abstract the external API calls.
- Convention-driven, file-based routing approach that Next.js uses.

## Diagram (Mermaid)

```mermaid
graph TD
    Browser("Client Browser"):::frontend

    subgraph "Next.js Pages"
        subgraph "Home & Global Layout"
            homePage["Home Page (page.tsx)"]:::frontend
            layout["Layout (layout.tsx)"]:::frontend
            globals["Globals (globals.css)"]:::frontend
            loading1["Loading (loading.tsx)"]:::frontend
        end
        subgraph "Blog Pages"
            blogPage["Blog Page ([id] page.tsx)"]:::frontend
            blogLoading["Blog Loading ([id] loading.tsx)"]:::frontend
            blogNotFound["Blog Not Found ([id] not-found.tsx)"]:::frontend
        end
        subgraph "Category Pages"
            categoryPage["Category Page (page.tsx)"]:::frontend
            categoryLoading["Category Loading (loading.tsx)"]:::frontend
            categoryDynamic["Category Dynamic ([category] page.tsx)"]:::frontend
            categoryLoadingDynamic["Category Dynamic Loading ([category] loading.tsx)"]:::frontend
        end
    end

    subgraph "UI Components"
        header["Header"]:::frontend
        banner["Banner"]:::frontend
        blogContent["BlogContent"]:::frontend
        featuredCategories["FeaturedCategories"]:::frontend
        featuredSlider["FeaturedSlider"]:::frontend
        latestBlogs["LatestBlogs"]:::frontend
        latestPosts["LatestPosts"]:::frontend
        loadMoreButton["LoadMoreButton"]:::frontend
        menuMobile["MenuMobile"]:::frontend
        menuMobileBtn["MenuMobileBtn"]:::frontend
        mostViewedBlogs["MostViewedBlogs"]:::frontend
        sidebar["Sidebar"]:::frontend
    end

    subgraph "API Endpoints"
        apiHomeMain["Home API (route.ts)"]:::api
        apiHomeDynamic["Home API ([id] route.ts)"]:::api
        apiBlog["Blog API ([id] route.ts)"]:::api
        apiCategories["Categories API (route.ts)"]:::api
    end

    subgraph "Services & Utilities"
        serviceGetApi["Service: getApi (getApi.tsx)"]:::services
        serviceGetBlog["Service: getBlogById (getBlogById.tsx)"]:::services
        utility["Utility: date (date.ts)"]:::services
    end

    subgraph "External / Config"
        external["Configuration (firebase.config.ts, next.config.ts, postcss.config.mjs, tsconfig.json, icons)"]:::external
    end

    %% Relationships
    Browser -->|"requests"| homePage
    Browser -->|"requests"| blogPage
    Browser -->|"requests"| categoryPage

    %% Pages render UI Components
    homePage -->|"renders"| header
    blogPage -->|"renders"| blogContent
    categoryPage -->|"renders"| sidebar

    %% Pages fetch data from API endpoints
    homePage -->|"fetches"| apiHomeMain
    blogPage -->|"fetches"| apiBlog
    categoryPage -->|"fetches"| apiCategories

    %% API Endpoints call Services
    apiHomeMain -->|"uses"| serviceGetApi
    apiHomeDynamic -->|"uses"| serviceGetApi
    apiBlog -->|"uses"| serviceGetBlog
    apiCategories -->|"uses"| serviceGetApi

    %% Services use Utility
    serviceGetApi -->|"helpers"| utility
    serviceGetBlog -->|"helpers"| utility

    %% API Endpoints interact with External Config
    apiHomeMain -->|"external"| external
    apiHomeDynamic -->|"external"| external
    apiBlog -->|"external"| external
    apiCategories -->|"external"| external

    %% Additional composition among UI components (optional)
    banner --> blogContent
    featuredCategories --> sidebar
    loadMoreButton --> latestBlogs

    %% Click Events for Next.js Page Components – Home & Global Layout
    click homePage "https://github.com/phamhau23/blog/blob/main/app/page.tsx"
    click layout "https://github.com/phamhau23/blog/blob/main/app/layout.tsx"
    click globals "https://github.com/phamhau23/blog/blob/main/app/globals.css"
    click loading1 "https://github.com/phamhau23/blog/blob/main/app/loading.tsx"

    %% Click Events for Blog Page Components
    click blogPage "https://github.com/phamhau23/blog/blob/main/app/blog/[id]/page.tsx"
    click blogLoading "https://github.com/phamhau23/blog/blob/main/app/blog/[id]/loading.tsx"
    click blogNotFound "https://github.com/phamhau23/blog/blob/main/app/blog/[id]/not-found.tsx"

    %% Click Events for Categories Page Components
    click categoryPage "https://github.com/phamhau23/blog/blob/main/app/categories/page.tsx"
    click categoryLoading "https://github.com/phamhau23/blog/blob/main/app/categories/loading.tsx"
    click categoryDynamic "https://github.com/phamhau23/blog/blob/main/app/categories/[category]/page.tsx"
    click categoryLoadingDynamic "https://github.com/phamhau23/blog/blob/main/app/categories/[category]/loading.tsx"

    %% Click Events for API Endpoints
    click apiHomeMain "https://github.com/phamhau23/blog/blob/main/app/api/home/route.ts"
    click apiHomeDynamic "https://github.com/phamhau23/blog/blob/main/app/api/home/[id]/route.ts"
    click apiBlog "https://github.com/phamhau23/blog/blob/main/app/api/blog/[id]/route.ts"
    click apiCategories "https://github.com/phamhau23/blog/blob/main/app/api/categories/route.ts"

    %% Click Events for UI Components
    click header "https://github.com/phamhau23/blog/blob/main/components/Header.tsx"
    click banner "https://github.com/phamhau23/blog/blob/main/components/Banner.tsx"
    click blogContent "https://github.com/phamhau23/blog/blob/main/components/BlogContent.tsx"
    click featuredCategories "https://github.com/phamhau23/blog/blob/main/components/FeaturedCategories.tsx"
    click featuredSlider "https://github.com/phamhau23/blog/blob/main/components/FeaturedSlider.tsx"
    click latestBlogs "https://github.com/phamhau23/blog/blob/main/components/LatestBlogs.tsx"
    click latestPosts "https://github.com/phamhau23/blog/blob/main/components/LatestPosts.tsx"
    click loadMoreButton "https://github.com/phamhau23/blog/blob/main/components/LoadMoreButton.tsx"
    click menuMobile "https://github.com/phamhau23/blog/blob/main/components/MenuMobile.tsx"
    click menuMobileBtn "https://github.com/phamhau23/blog/blob/main/components/MenuMobileBtn.tsx"
    click mostViewedBlogs "https://github.com/phamhau23/blog/blob/main/components/MostViewedBlogs.tsx"
    click sidebar "https://github.com/phamhau23/blog/blob/main/components/Sidebar.tsx"

    %% Click Events for Services & Utilities
    click serviceGetApi "https://github.com/phamhau23/blog/blob/main/services/getApi.tsx"
    click serviceGetBlog "https://github.com/phamhau23/blog/blob/main/services/getBlogById.tsx"
    click utility "https://github.com/phamhau23/blog/blob/main/utils/date.ts"

    %% Click Event for External & Configuration
    click external "https://github.com/phamhau23/blog/blob/main/firebase.config.ts"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef api fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef services fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#784212,stroke-width:2px;
```
