# trtien05/pregnancygrowthtrackingsystem-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/trtien05/pregnancygrowthtrackingsystem-frontend
- Repository: https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend

## Overview

##### Project Type and Purpose
- This is a front-end Single Page Application (SPA) built with React using Vite as the bundler. The README shows it as a minimal template for React with Hot Module Replacement (HMR) using either Babel or SWC.
- Although primarily a front-end application, the rich component hierarchy (with pages for Admin, Blog, Checkout, member areas, health calculators, etc.) indicates that this project is a feature-rich web interface. It likely serves a multi-functional website with both public and authenticated sections, including admin dashboards and user membership management.

##### Analyzing the File Structure
- There is a clear separation between static files (index.html, public) and the source code (src).
- Components: Contains reusable UI components (e.g., AchievementSection, AuthForm, BlogPost, Calculator forms, Sidebar, etc.).
- Pages: Organized by feature (Home, Login, Register, Admin, BlogDetail, Checkout, etc.), which represent route-driven components.
- Layouts: Contains layout definitions (MainLayout, AdminLayout) that wrap pages to provide consistent headers, footers, menus, etc.
- Routes: Modules (AdminRoutes.jsx, AuthRoutes.jsx, MainRoutes.jsx) that configure navigation and access flow.
- Services and Utils: Abstract API calls (blogPostService.js, userService.js) and helper functions (apiCaller.js, cookieUtils.js), plus configuration settings in src/config.
- Hooks: Custom hooks for authentication and document management.
- There are configuration files for ESLint, Prettier, and Vite, which indicate code style, linting, and bundling choices.

a. UI Layer:
- Pages: Represent different routes such as Home, Login, Register, Dashboard (customer, admin, member areas), Blog, Checkout, and various tool pages (DueDateCalculator, OvulationCalculator, etc.).
- Layouts: Two main layouts (MainLayout and AdminLayout) that structure the visible pages.
- Components: Reusable UI widgets like AuthForm, BlogPost, BarChart, Sidebar, MembershipPlan, etc., which are used within pages and layouts.

b. Routing and Navigation:
- Route Files: AdminRoutes, AuthRoutes, MainRoutes, which determine the navigation structure and access control.
- The App.jsx and main.jsx files, which serve as entry points, bringing together routing and global state.

c. Service and Utility Layer:
- Services: blogPostService and userService manage external API calls/business logic.
- Utils: Helper functions for API calls and cookie operations.
- Configuration: Constants, routes, cookie and localStorage utilities that dictate application behavior.

d. Build and Configuration:
- Vite and its configuration (vite.config.js) handle module bundling.
- ESLint and Prettier configs ensure code quality and consistency.

##### Highlighting Relationships and Interactions
- Data Flow: The UI layer (pages and components) interacts with the service layer via API calls. Custom hooks (e.g., useAuth) mediate state and effects.
- Layout Wrapping: Layouts such as MainLayout and AdminLayout serve as wrappers for pages to maintain consistent UI (with headers, footers, menus).
- Routing: Page components are selected based on the routes configured by the route files, defining both public and restricted (admin, member) areas.
- Assets & Styling: The assets and CSS completions are referenced by components to render the UI correctly.
- Build Tools: The Vite configuration integrates with the development tools (e.g., React Fast Refresh provided by the specified plugins).

##### Architectural Patterns and Design Principles
- Component-based architecture: The project follows React’s component model, ensuring separation of concerns.
- Modular separation: Files are organized by concerns – components, pages, layouts, services, and configuration.
- Routing and Guarding: AuthRoutes and AdminRoutes show that navigation and access control are separated to enforce security and proper flow.
- Reuse and Extensibility: Many UI elements and calculators are built as independent, reusable components that can be extended further.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% UI/Presentation Layer
    subgraph "UI/Presentation Layer"
        UI_Pages["Pages"]:::ui
        UI_Layouts["Layouts"]:::ui
        UI_Components["Reusable Components"]:::ui
    end

    %% Routing & Navigation Layer
    subgraph "Routing & Navigation Layer"
        RT_Routes["Route Files"]:::routing
        RT_App["App Entry"]:::routing
        RT_Main["Main Entry"]:::routing
    end

    %% Service / Business Logic Layer
    subgraph "Service/Business Logic Layer"
        S_API["API Services"]:::service
        S_Utils["Utilities & Configs"]:::service
        S_Hooks["Custom Hooks"]:::service
    end

    %% Build & Configuration Layer
    subgraph "Build & Configuration Layer"
        B_Vite["Vite Config"]:::build
        B_ESLint["ESLint Config"]:::build
        B_Prettierrc["Prettier Config"]:::build
    end

    %% Relationships - Routing and UI
    RT_Routes -->|"routes-to"| UI_Pages
    RT_App -->|"initializes"| UI_Pages
    RT_Main -->|"initializes"| UI_Pages

    %% Relationships - UI Layer
    UI_Pages -->|"wrappedIn"| UI_Layouts
    UI_Components -->|"integratedIn"| UI_Pages

    %% Relationships - UI and Service Layers
    UI_Pages -->|"calls"| S_API
    UI_Pages -->|"calls"| S_Utils
    UI_Components -->|"triggers"| S_Hooks
    S_API -->|"utilizes"| S_Utils

    %% Relationships - Build & Configuration Layer connections (dotted arrows)
    B_Vite -.->|"configures"| RT_Routes
    B_ESLint -.->|"enforces"| UI_Components
    B_Prettierrc -.->|"styles"| UI_Pages

    %% Click Events
    click UI_Pages "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/tree/main/src/pages"
    click UI_Layouts "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/tree/main/src/layouts"
    click UI_Components "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/tree/main/src/components"
    click RT_Routes "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/tree/main/src/routes"
    click RT_App "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/blob/main/src/App.jsx"
    click RT_Main "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/blob/main/src/main.jsx"
    click S_API "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/tree/main/src/services"
    click S_Utils "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/tree/main/src/utils"
    click S_Hooks "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/tree/main/src/hooks"
    click B_Vite "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/blob/main/vite.config.js"
    click B_ESLint "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/blob/main/.eslintrc.cjs"
    click B_Prettierrc "https://github.com/trtien05/pregnancygrowthtrackingsystem-frontend/blob/main/.prettierrc.json"

    %% Styles
    classDef ui fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef routing fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef service fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef build fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
```
