# h3d-anhntl/blog-app architecture

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

- Interactive diagram: https://gitdiagram.com/h3d-anhntl/blog-app
- Repository: https://github.com/h3d-anhntl/blog-app

## Overview

##### Project Type and Purpose
- This is a full-stack web application built using Next.js (bootstrapped with create-next-app). The project appears to be a content-driven or blog-like application that includes multiple API endpoints for handling posts, comments, categories, and authentication.
- The existence of Prisma configuration (prisma/schema.prisma) suggests that the project leverages a database, with Prisma acting as the ORM layer for data modeling and queries.

##### Key Components and Their Roles
a. Frontend (Client-Side) Components:
- Pages and Views: Located under the “src/app” folder (e.g., homepage, blog page, login page, write page, post pages). These components provide the user interface and render the content.
- Reusable UI Components: Found in “src/app/components” (for navigation, card lists, comments, theme toggles, etc.) which are used to build the page layouts.
- Global Styling & Fonts: Managed through “globals.css”, Tailwind CSS configuration (tailwind.config.js), and Next.js font optimization.
- Context & Providers: “src/context” and “src/providers” maintain application states such as theme and authentication, ensuring a consistent experience across the UI.

b. Backend/API Components:
- API Routes: Organized in “src/app/api”, these include endpoints for authentication ([...nextauth]), posts, comments, and categories. They handle server-side logic such as authentication workflows or data fetching.
- Authentication: Specific endpoints (in /api/auth) show that the app supports user authentication (e.g., via NextAuth) and likely handles secure logins.
- Prisma Database Connectors: With the “prisma/schema.prisma” file, the application communicates with the database using Prisma. This layer is key for data persistence (posts, comments, categories, user data).

c. Configuration & Deployment:
- Build and configuration files (next.config.mjs, jsconfig.json, postcss.config.mjs, tailwind.config.js) set up the application’s behavior and styling.
- GitHub workflows and .eslint configuration files ensure code quality and continuous integration.
- README instructions and Vercel deployment guidance describe development practices and deployment targets.

##### Specific Elements
- “Client / Browser” for UI and pages.
- “Next.js Server” for routing and API handling.
- “API Endpoints” (with sub-labels for auth, posts, comments, categories).
- “Database (via Prisma)”
- “Context Providers” for theme and auth.
- Client → API Endpoints (showing requests).
- API Endpoints → Database (indicating data CRUD operations).
- API Endpoints → Client (responses/data rendering).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A1["Pages and Views"]:::frontend
        A2["Reusable UI Components"]:::frontend
        A3["Global Styling & Fonts"]:::config
        A4["Context & Providers"]:::frontend
    end

    %% Next.js Server Layer
    subgraph "Next.js Server Layer"
        B1["API: Authentication"]:::api
        B2["API: Posts"]:::api
        B3["API: Comments"]:::api
        B4["API: Categories"]:::api
        D1["Build & Config"]:::config
        D2["CI/CD & Code Quality"]:::ci
    end

    %% Database Layer
    subgraph "Database Layer"
        C1["Database (Prisma)"]:::db
    end

    %% Data Flow from Frontend to API Endpoints
    A1 -->|"HTTP_Request"| B1
    A1 -->|"HTTP_Request"| B2
    A1 -->|"HTTP_Request"| B3
    A1 -->|"HTTP_Request"| B4

    %% API Endpoints accessing the Database
    B1 -->|"DB_Query"| C1
    B2 -->|"DB_Query"| C1
    B3 -->|"DB_Query"| C1
    B4 -->|"DB_Query"| C1

    %% Responses from API Endpoints back to Frontend
    B1 -->|"HTTP_Response"| A1
    B2 -->|"HTTP_Response"| A1
    B3 -->|"HTTP_Response"| A1
    B4 -->|"HTTP_Response"| A1

    %% Configuration flows supporting API endpoints
    D1 -->|"Configures"| B1
    D1 -->|"Configures"| B2
    D1 -->|"Configures"| B3
    D1 -->|"Configures"| B4
    D2 -->|"Integrates_with"| D1

    %% Click Events
    click A1 "https://github.com/h3d-anhntl/blog-app/tree/develop/src/app"
    click A2 "https://github.com/h3d-anhntl/blog-app/tree/develop/src/app/components"
    click A3 "https://github.com/h3d-anhntl/blog-app/blob/develop/src/app/globals.css"
    click A4 "https://github.com/h3d-anhntl/blog-app/tree/develop/src/context"
    click B1 "https://github.com/h3d-anhntl/blog-app/blob/develop/src/app/api/auth/[...nextauth]"
    click B2 "https://github.com/h3d-anhntl/blog-app/tree/develop/src/app/api"
    click B3 "https://github.com/h3d-anhntl/blog-app/tree/develop/src/app/api"
    click B4 "https://github.com/h3d-anhntl/blog-app/tree/develop/src/app/api"
    click C1 "https://github.com/h3d-anhntl/blog-app/blob/develop/prisma/schema.prisma"
    click D1 "https://github.com/h3d-anhntl/blog-app/blob/develop/next.config.mjs"
    click D2 "https://github.com/h3d-anhntl/blog-app/tree/develop/.github/workflows"

    %% Class Definitions for colours
    classDef frontend fill:#aee1f9,stroke:#333,stroke-width:2px;
    classDef api fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef db fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef config fill:#fadbd8,stroke:#333,stroke-width:2px;
    classDef ci fill:#d7bde2,stroke:#333,stroke-width:2px;
```
