# se2-9/frontend architecture

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

- Interactive diagram: https://gitdiagram.com/se2-9/frontend
- Repository: https://github.com/se2-9/frontend

## Overview

##### Main Components
- Frontend UI Layer:
- This includes all the UI components located in the "src/components" folder. They encompass specialized components for authentication (login form, registration forms), user profile management, payment processing, posts, requests, reviews, and other reusable UI pieces (e.g., buttons, dialogs, forms).
- Generic UI components under "src/components/ui" that form the building blocks of the application interface.
- Page Routing and Layout:
- "src/app" directory. This folder contains the Next.js page components for various routes such as authentication (login, registration, verify-code), profiles, payment, student and tutor related pages, and error handling (not-found.tsx).
- Layout components (global layout, globals.css, navigation bars) that define the overall structure.
- Data Management and Business Logic:
- The "src/lib" folder groups API service functionalities (in subdirectories like "api" and "validations"). These modules encapsulate communication with back-end endpoints, authentication, payment, post management, and more.
- Similarly, include "src/dtos" and "src/types" which define data structures and contracts, ensuring type safety and consistency.
- State Management and Hooks:
- "src/store" directory (e.g., auth-store, post-store) and custom hooks in "src/hooks" that manage global state and side effects like fetching data from APIs.
- Providers and Integration Points:
- Components in "src/providers" (e.g., auth-providers, query-providers) integrate the state management and API data into the component hierarchies via React contexts or other provider patterns.
- Utility Functions:
- "src/utils" and mapping functions under "src/utils/mapper" that transform data and encapsulate shared helper functions.
- Configuration & Deployment:
- Don’t forget the configuration artifacts such as "next.config.ts", "Dockerfile", "docker-compose.yml", and various linting/formatting configurations. These are key to understanding how the application is built, linted, and deployed.

##### Out Relationships and Interactions
- The View Layer (UI Components and Pages)
- The Data/Business Logic Layer (API Services, Validations, DTOs)
- The State Management Layer (Stores and Hooks)
- Integration Providers that tie components with state and data APIs
- From the UI (pages and components) to the API layer (lib/api) where server communication occurs.
- From API calls to state updates in the stores and hooks.
- From providers wrapping the UI components to the context in which they receive state and API data.
- If applicable, note external services (e.g., payment services like Omise) that are used via API calls documented in the "src/lib/api/payment.ts" and corresponding DTOs.

##### Important Architectural Patterns and Design Principles
- Modular Design – The project adheres to separation-of-concerns by breaking down UI, business logic, and state management into distinct directories.
- Next.js Routing – The “src/app” structure indicates the use of Next.js app directory routing, where each folder (and nested groupings like (auth), student, tutor) denotes a specific route and view.
- Reusability – Many reusable UI components are centralized under "src/components/ui", and business logic is abstracted into logical API layers.
- Integration of third-party services – Notice the presence of third-party payment handling (Omise) and validations, which suggests integration considerations on the API layer.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Frontend UI Layer"
        NP["Next.js Pages"]
        GS["Global Styles"]
        LC["Layout Component"]
        EP["Error Page"]
        UIC["UI Components"]
        RUI["Reusable UI Components"]
    end

    subgraph "Data/Business Logic Layer"
        API["API Services"]
        DTO["DTOs"]
        TYP["Types"]
    end

    subgraph "State Management Layer"
        SS["State Stores"]
        CH["Custom Hooks"]
    end

    subgraph "Providers & Integration"
        PVD["Providers"]
    end

    subgraph "Utility Functions"
        UT["Utils"]
        DM["Data Mappers"]
        TR["Token Refresh"]
    end

    subgraph "Configuration & Deployment"
        NCC["Next.js Config"]
        DF["Dockerfile"]
        DC["Docker Compose"]
        ESL[".eslintrc.js"]
        ESLM["eslint.config.mjs"]
        PRE["prettier.config.js"]
        POC["postcss.config.mjs"]
        TC["tailwind.config.ts"]
    end

    %% Relationships
    NP -->|"callsAPI"| API
    NP -->|"wrappedBy"| PVD
    PVD -->|"updates"| SS
    API -->|"updateState"| SS
    API -->|"utilizes"| UT
    UIC -->|"triggers"| CH
    CH -->|"syncs"| SS
    API -->|"uses"| DTO
    API -->|"uses"| TYP
    UT -->|"maps"| DM
    UT -->|"schedules"| TR

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef state fill:#FFFFE0,stroke:#333,stroke-width:2px;
    classDef provider fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:2px;

    class NP,GS,LC,EP,UIC,RUI ui;
    class API,DTO,TYP api;
    class SS,CH state;
    class PVD provider;
    class UT,DM,TR util;
    class NCC,DF,DC,ESL,ESLM,PRE,POC,TC config;

    %% Click Events
    click UIC "https://github.com/se2-9/frontend/tree/main/src/components/"
    click RUI "https://github.com/se2-9/frontend/tree/main/src/components/ui/"
    click NP "https://github.com/se2-9/frontend/tree/main/src/app/"
    click GS "https://github.com/se2-9/frontend/blob/main/src/app/globals.css"
    click LC "https://github.com/se2-9/frontend/blob/main/src/app/layout.tsx"
    click EP "https://github.com/se2-9/frontend/blob/main/src/app/not-found.tsx"
    click API "https://github.com/se2-9/frontend/tree/main/src/lib/api/"
    click DTO "https://github.com/se2-9/frontend/tree/main/src/dtos/"
    click TYP "https://github.com/se2-9/frontend/tree/main/src/types/"
    click SS "https://github.com/se2-9/frontend/tree/main/src/store/"
    click CH "https://github.com/se2-9/frontend/tree/main/src/hooks/"
    click PVD "https://github.com/se2-9/frontend/tree/main/src/providers/"
    click UT "https://github.com/se2-9/frontend/tree/main/src/utils/"
    click DM "https://github.com/se2-9/frontend/tree/main/src/utils/mapper/"
    click TR "https://github.com/se2-9/frontend/blob/main/src/utils/scheduleTokenRefresh.ts"
    click NCC "https://github.com/se2-9/frontend/blob/main/next.config.ts"
    click DF "https://github.com/se2-9/frontend/tree/main/Dockerfile"
    click DC "https://github.com/se2-9/frontend/blob/main/docker-compose.yml"
    click ESL "https://github.com/se2-9/frontend/blob/main/.eslintrc.js"
    click ESLM "https://github.com/se2-9/frontend/blob/main/eslint.config.mjs"
    click PRE "https://github.com/se2-9/frontend/blob/main/prettier.config.js"
    click POC "https://github.com/se2-9/frontend/blob/main/postcss.config.mjs"
    click TC "https://github.com/se2-9/frontend/blob/main/tailwind.config.ts"
```
