# neiht13/egfr-ldl-calculator architecture

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

- Interactive diagram: https://gitdiagram.com/neiht13/egfr-ldl-calculator
- Repository: https://github.com/neiht13/egfr-ldl-calculator

## Overview

##### Main Components Identification
- Frontend Interface (Next.js Application):
– The primary entry points are found in the app directory (page.tsx and layout.tsx).
– It consists of dedicated calculator files (Calculator.tsx, EGFRCalculator.tsx, LDLCalculator.tsx) and individual UI components like Button, CustomSelect, InputGroup, etc.
- UI Components:
– Sub-modules in the app/components folder handle discrete UI features such as the language toggle, tab components, and display functions (FormulaText, Result).
– The LanguageContext and translations indicate that internationalization (i18n) is supported.
- Styles & Theming:
– Global styles are managed in app/styles/globals.css and styled with Tailwind (tailwind.config.ts).
- Configuration & Build Tools:
– The project configuration is visible in Next.js-specific files (next.config.ts, tsconfig.json), PostCSS (postcss.config.mjs), and package.json for managing dependencies.
- Public Assets:

##### Relationships and Interactions
- User Flow:
– The initial page (page.tsx) renders the layout (layout.tsx) and displays navigation elements (Tabs) for switching between the eGFR and LDL calculators.
- Calculator Workflow:
– Depending on user selection, either the EGFRCalculator or LDLCalculator module becomes active.
– Input components (InputGroup, CustomSelect) capture user data such as measurements and personal details.
– On submission, calculation components apply the corresponding formula (MDRD/Jaffe for eGFR or Friedewald for LDL) and display results through the Result component, along with visual hints (FormulaText) and error notifications.
- Internationalization:
– The LanguageContext and LanguageToggle components assure that text and UI elements are displayed in Vietnamese or English based on user selection.
- Component Integration:
– Reusable UI elements (Buttons, Tabs, etc.) are integrated across the calculators to facilitate a consistent and interactive user interface.
- Data Flow:
– All data flow from user input → state management (likely encapsulated within React’s state/hooks in these components) → processing within calculator components → updated UI with calculation results.

##### Architectural Patterns and Design Principles
- Component-Based Architecture:
– The project is modularized into reusable components (present in the components folder) to maintain separation of concerns and enhance scalability.
- Single Page Application (SPA) Model:
– Built on Next.js, the project leverages both server side rendering (SSR) and client side interactivity, but is conceptually a SPA focused on a single page with multiple calculator views.
- Separation of Concerns:
– Logic for calculations is separated from presentation logic; UI components are decoupled from business calculations.
- Internationalization & Responsiveness:
– The inclusion of language context and responsive design configurations through Tailwind indicates careful attention to user experience.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        A1["App/Page (page.tsx)"]:::presentation
        A2["Layout (layout.tsx)"]:::presentation
        NF["Next.js Framework"]:::framework
    end

    %% Calculator Layer
    subgraph "Calculator Layer"
        C1["Calculator Container"]:::calculator
        EG["eGFR Calculator"]:::calculator
        LD["LDL Calculator"]:::calculator
    end

    %% UI Components
    subgraph "UI Components"
        T1["Tabs"]:::ui
        T2["Tab"]:::ui
        B["Button"]:::ui
        CS["Custom Select"]:::ui
        IG["Input Group"]:::ui
        FT["Formula Text"]:::ui
        RD["Result Display"]:::ui
    end

    %% Internationalization Components
    subgraph "Internationalization"
        LC["Language Context"]:::intl
        LT["Language Toggle"]:::intl
        TR["Translations"]:::intl
    end

    %% Configuration and Assets
    subgraph "Configuration & Assets"
        GS["Global Styles"]:::config
        TC["Tailwind Config"]:::config
        NC["Next.js Config"]:::config
        TS["TS Config"]:::config
        PC["PostCSS Config"]:::config
        PK["Package.json"]:::config
        PA["Public Assets"]:::assets
    end

    %% Relationships
    NF --> A1
    A1 -->|"renders"| A2
    A2 -->|"includes"| C1
    C1 -->|"selects"| EG
    C1 -->|"selects"| LD
    A2 -->|"integrates"| T1
    T1 -->|"contains"| T2
    A2 -->|"integrates"| B
    A2 -->|"integrates"| CS
    A2 -->|"integrates"| IG
    A2 -->|"displays"| FT
    A2 -->|"displays"| RD

    IG -->|"captures"| C1
    EG -->|"calculates"| FT
    LD -->|"calculates"| RD

    A2 -->|"incorporates"| LC
    LC -->|"controls"| LT
    LT -->|"applies"| TR

    A1 -->|"styled by"| GS
    GS -->|"configured by"| TC
    NF -->|"configured by"| NC
    NC --> TS
    NC --> PC
    NC --> PK
    A2 -->|"uses"| PA

    %% Click Events
    click A1 "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/page.tsx"
    click A2 "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/layout.tsx"
    click C1 "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/Calculator.tsx"
    click EG "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/EGFRCalculator.tsx"
    click LD "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/LDLCalculator.tsx"
    click B "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/Button.tsx"
    click CS "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/CustomSelect.tsx"
    click IG "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/InputGroup.tsx"
    click FT "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/FormulaText.tsx"
    click RD "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/Result.tsx"
    click T2 "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/Tab.tsx"
    click T1 "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/Tabs.tsx"
    click LC "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/LanguageContext.tsx"
    click LT "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/LanguageToggle.tsx"
    click TR "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/components/translations.ts"
    click GS "https://github.com/neiht13/egfr-ldl-calculator/blob/main/app/styles/globals.css"
    click TC "https://github.com/neiht13/egfr-ldl-calculator/blob/main/tailwind.config.ts"
    click NC "https://github.com/neiht13/egfr-ldl-calculator/blob/main/next.config.ts"
    click TS "https://github.com/neiht13/egfr-ldl-calculator/blob/main/tsconfig.json"
    click PC "https://github.com/neiht13/egfr-ldl-calculator/blob/main/postcss.config.mjs"
    click PK "https://github.com/neiht13/egfr-ldl-calculator/blob/main/package.json"
    click PA "https://github.com/neiht13/egfr-ldl-calculator/tree/main/public"

    %% Styles
    classDef presentation fill:#f9f,stroke:#333,stroke-width:2px;
    classDef framework fill:#bbf,stroke:#333,stroke-width:2px;
    classDef calculator fill:#bfb,stroke:#333,stroke-width:2px;
    classDef ui fill:#ff9,stroke:#333,stroke-width:2px;
    classDef intl fill:#9ff,stroke:#333,stroke-width:2px;
    classDef config fill:#fbb,stroke:#333,stroke-width:2px;
    classDef assets fill:#ddd,stroke:#333,stroke-width:2px;
```
