How benhoangquan/udem_ai_website_v2 works
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)