# benhoangquan/udem_ai_website_v2 architecture

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

- Interactive diagram: https://gitdiagram.com/benhoangquan/udem_ai_website_v2
- Repository: https://github.com/benhoangquan/udem_ai_website_v2

## Overview

##### Project Type and Purpose
- The project is a full-stack web application. The frontend is built with Next.js (React, TypeScript, Tailwind CSS, shadcn UI components), and the backend is a Sanity.io CMS that manages content via custom schemas and includes scripts for generating and importing mock data.
- The application serves dynamic content where the frontend consumes data managed by the backend CMS.

##### Main Components
a. Frontend:
- Built with Next.js, with a clear separation of concerns: pages, components (organized into sub-folders like activities, blog, common, main, resources, team), hooks, services, and utility libraries.
- The client-side consumes the Sanity CMS API via a custom sanity client (see frontend/src/lib/sanity.ts) and leverages Tailwind CSS & shadcn UI for styling and component design.

b. Backend:
- Implements Sanity.io CMS with custom schema definitions. Schemas are divided into “documents” (e.g., activity.ts, blog.ts, category.ts, generalInfo.ts, member.ts, resource.ts) and “objects” (like blockContent, location, schedule, socialLinks) which define reusable parts of content.
- Contains scripts for generating and importing both mock and real data, which are crucial for development and testing of the content.
- Uses TypeScript and configuration files like sanity.config.ts and sanity.cli.ts.

c. Data Flow:
- The frontend interacts with the Sanity CMS by querying content via the custom sanity client; hence, there is a direct data flow between the frontend and backend.
- The backend’s scripts (for both mock and real data) are used to populate the Sanity CMS with initial or sample data.

##### Key Relationships/Interactions
- The frontend (Next.js app) requests data from the backend (Sanity CMS) endpoints. This involves function calls from the service layer (in frontend/src/services) using the sanity client found in frontend/src/lib/sanity.ts.
- There’s a clear separation between content management (backend) and content consumption (frontend). Data is modeled in the backend with a document/objects schema and consumed on various frontend pages (e.g., pages/blog, pages/activities, pages/team).
- Development workflows are defined by separate commands for starting the frontend (http://localhost:3000) and backend (http://localhost:3333 for Sanity Studio).

##### Architectural Patterns and Principles
- Separation of Concerns: The code is clearly divided into frontend and backend with their own readmes, package management, and configurations.
- Modularization: Both the frontend and backend have modular folder structures (e.g., components, pages, hooks vs. schemaTypes, scripts) that emphasize reusable and maintainable code.
- Data-driven design: The backend utilizes data schemas and mock/real data scripts to manage content, which then drives the rendering on the frontend.
- Use of well-known frameworks and libraries: Next.js for server-side rendered React apps on the frontend and Sanity.io for flexible content management on the backend.

- Frontend:
- Styling and UI libraries like Tailwind CSS and shadcn UI.
- Connection to the Sanity client which handles communication with the CMS.

- Backend:
- Schema Definitions (Documents and Objects)
- Data Population Scripts (mock-data and real-data scripts)
- Sanity Studio configuration & CLI

- Interaction Between Components:

- UI and presentation layers (frontend components, pages, and hooks)
- Business logic/service layers (services, utility libraries)
- Data management (CMS schemas, data import scripts)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Group
    subgraph "Frontend (Next.js)"
        FE_Pages["Pages"]:::frontend
        FE_Components["Components"]:::frontend
        FE_Hooks["Hooks"]:::frontend
        FE_Services["Services"]:::frontend
        FE_SanityClient["Sanity Client"]:::frontend
    end

    %% Backend Group
    subgraph "Backend (Sanity.io CMS)"
        BE_Config["Sanity Config & CLI"]:::backend
        BE_Documents["Schema Documents"]:::backend
        BE_Objects["Schema Objects"]:::backend
        BE_Mock["Mock Data Scripts"]:::backend
        BE_Real["Real Data Scripts"]:::backend
    end

    %% Frontend Internal Interactions
    FE_Services -->|"uses"| FE_SanityClient
    FE_Pages -->|"renders data from"| FE_SanityClient

    %% Frontend to Backend Interaction
    FE_SanityClient -->|"ContentQuery"| BE_Documents
    FE_SanityClient -->|"ContentQuery"| BE_Objects

    %% Backend Data Population
    BE_Mock -->|"data import"| BE_Documents
    BE_Mock -->|"data import"| BE_Objects
    BE_Real -->|"data import"| BE_Documents
    BE_Real -->|"data import"| BE_Objects

    %% Click Events for Frontend Components
    click FE_Pages "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/frontend/src/pages"
    click FE_Components "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/frontend/src/components"
    click FE_Hooks "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/frontend/src/hooks"
    click FE_Services "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/frontend/src/services"
    click FE_SanityClient "https://github.com/benhoangquan/udem_ai_website_v2/blob/main/frontend/src/lib/sanity.ts"

    %% Click Events for Backend Components
    click BE_Config "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/backend"
    click BE_Documents "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/backend/schemaTypes/documents"
    click BE_Objects "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/backend/schemaTypes/objects"
    click BE_Mock "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/backend/scripts/mock-data"
    click BE_Real "https://github.com/benhoangquan/udem_ai_website_v2/tree/main/backend/scripts/real-data"

    %% Styling Classes
    classDef frontend fill:#A2D9CE,stroke:#1ABC9C,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
```
