# nguyenhung-hub/blog-ui architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenhung-hub/blog-ui
- Repository: https://github.com/nguyenhung-hub/blog-ui

## Overview

##### Main Components
- Next.js Framework: At the core, the Next.js framework manages routing (via the file system), server-side rendering, and static site generation. Mark the Next.js engine as the central framework layer.
- Sections by Application Area:
- Admin Section: Located under src/app/(admin) with features such as dashboard, write functionality, and specialized components (_components folder). This group is used for administrative actions like managing posts, profiles, and resources.
- Authentication: Under src/app/(auth) housing the login (dang-nhap) and logout pages for handling user sessions.
- Main/Public Section: Under src/app/(main) which handles the public routes (for posts, resources, etc.) and includes its own set of common UI components.
- State Management & Services:
- Store: Located in src/store (with reducers, providers, and services) for managing global state, including specific slices like user, editor, and search functionality.
- Service Layer: Files in src/service provide API or business logic interactions for posts, categories, resources, and user data.
- Utility Modules: Including configuration (src/config), custom hooks (src/hook), utility functions (src/util), and a set of interfaces and types (src/interfaces and src/types) that help maintain type safety and shared contracts.

##### Out Relationships and Interactions
- Routing & Page Components: The Next.js file-based routing (as seen under src/app with distinct grouping for admin, auth, and main) drives the user navigation. Each page component (e.g., page.tsx files) should be shown as endpoints that render views.
- UI Components Interactions: Indicate that pages use reusable components (like headers, footers, sidebars, and cards) from folders such as src/components and the subfolders within src/app (e.g., dashboard/_components).
- Utility Integration: Show that common functions (src/util), configuration information (src/config), and custom hooks (src/hook) are supporting the logic and behavior of both components and services.

##### Architectural Patterns and Design Principles
- Modular & Layered Structure: Emphasize division into UI (pages and components), Service (API/data handling), and State layers.
- File-System Based Routing: Display how Next.js leverages folder structure for route definitions.
- Separation of Concerns: Different folders responsibly encapsulate admin, auth, and main functionalities.
- Reusability: Many components (in src/components and subcomponents under the app folders) are designed for reuse across different parts of the application.
- Type Safety and Custom Hooks: The use of TypeScript interfaces (src/interfaces and src/types) and custom hooks (src/hook) suggests an architecture that values maintainability and consistency.

##### Putting It All Together
- Branch out three main sections: Admin, Auth, and Main interfaces.
- Under each section, include sub-components:
- For Admin: Dashboard pages, write routes, and components like SideBarDashboard and Card components.
- For Auth: Login and logout pages.
- For Main: Dynamic routes for posts and resources, along with shared UI components (e.g., Header, Footer, Nav components).
- Sections to the global state management layer and indicate their interactions with the service layer.
- External dependencies such as Next.js libraries (e.g., next/font) and any third-party integrations shown in the configuration (Tailwind, ESLint, Prettier, etc.).

## Diagram (Mermaid)

```mermaid
graph TD
    Nextjs["Next.js Framework"]:::framework

    subgraph "Application Modules"
        Admin["Admin Module"]:::module
        Auth["Auth Module"]:::module
        Main["Main/Public Module"]:::module
    end

    Shared["Shared UI Components"]:::components
    Store["Global Store"]:::state
    Service["Service Layer"]:::service

    subgraph "Utility & Type Safety"
        Util["Util"]:::utility
        Config["Config"]:::utility
        Hook["Hook"]:::utility
        Interfaces["Interfaces"]:::type
        Types["Types"]:::type
    end

    %% Connections from Next.js Framework to Application Modules
    Nextjs -->|"routesTo"| Admin
    Nextjs -->|"routesTo"| Auth
    Nextjs -->|"routesTo"| Main

    %% Connections from Application Modules to Shared UI Components and Global Store
    Admin -->|"uses"| Shared
    Auth  -->|"uses"| Shared
    Main  -->|"uses"| Shared

    Admin -->|"stateAccess"| Store
    Auth  -->|"stateAccess"| Store
    Main  -->|"stateAccess"| Store

    %% Global State interacts with Service Layer
    Store -->|"triggers"| Service

    %% Service Layer utilizes Utility modules and Type Safety
    Service -->|"utilizes"| Util
    Service -->|"utilizes"| Config
    Service -->|"utilizes"| Hook
    Service -->|"utilizes"| Interfaces
    Service -->|"utilizes"| Types

    %% Click Events
    click Nextjs "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/app"
    click Admin "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/app/(admin)"
    click Auth "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/app/(auth)"
    click Main "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/app/(main)"
    click Shared "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/components"
    click Store "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/store"
    click Service "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/service"
    click Util "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/util"
    click Config "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/config"
    click Hook "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/hook"
    click Interfaces "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/interfaces"
    click Types "https://github.com/nguyenhung-hub/blog-ui/tree/master/src/types"

    %% Styles
    classDef framework fill:#a2d2ff,stroke:#333,stroke-width:2px;
    classDef module fill:#ffafcc,stroke:#333,stroke-width:2px;
    classDef components fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef state fill:#fdffb6,stroke:#333,stroke-width:2px;
    classDef service fill:#ffadad,stroke:#333,stroke-width:2px;
    classDef utility fill:#d0f4de,stroke:#333,stroke-width:2px;
    classDef type fill:#dcedf6,stroke:#333,stroke-width:2px;
```
