# asguizar/nutritrackapp architecture

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

- Interactive diagram: https://gitdiagram.com/asguizar/nutritrackapp
- Repository: https://github.com/asguizar/nutritrackapp

## Overview

##### Project type and purpose
- NutriTrack is a full-stack, single-page web application (SPA) built in React-TypeScript for nutritionists.
- The “backend” is serverless Firebase (Authentication + Firestore).

##### File structure
- src/index.tsx → React app entry point, wraps App.tsx in BrowserRouter and AuthContext.
- src/App.tsx → Top-level routes (Login vs protected Dashboard flows).
- src/contexts/AuthContext.tsx → Global auth state, route guard logic.
- src/config/firebase.ts → Firebase initialization + exports (auth, firestore).
- src/components/* → UI views:
- Login.tsx
- Dashboard.tsx (patient list + metrics overview)
- AppointmentCalendar.tsx
- NewPatient.tsx
- PatientProfile.tsx (history, charts via Plotly/Recharts)
- Tailwind/Tailwind config + postcss config govern styling.
- firestore.rules & indexes define security boundaries and query optimizations.

##### README for additional insights
- Stack: React18 + TS, Tailwind CSS, Plotly (charts), Firebase Auth, Firestore (real-time listeners).
- Key features: secure login, per-user data isolation, real-time patient & appointment updates, analytics dashboards.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend"
        subgraph "UI Layer"
            Login["Login View"]:::ui
            Dashboard["Dashboard"]:::ui
            AppointmentCalendar["Appointment Calendar"]:::ui
            NewPatient["New Patient Form"]:::ui
            PatientProfile["Patient Profile"]:::ui
        end
        subgraph "Context & Routing"
            EntryPoint["index.tsx"]:::ctx
            AppRouter["App.tsx (Routes)"]:::ctx
            AuthContext["AuthContext"]:::ctx
        end
        subgraph "Config/API Layer"
            FirebaseService["FirebaseService"]:::api
        end
    end

    %% Firebase Services
    subgraph "Firebase Services"
        AuthService["Authentication Service"]:::fs
        FirestoreDB["Firestore Database"]:::fs
    end

    %% Security & Indexes
    SecurityRules["firestore.rules"]:::sec
    Indexes["firestore.indexes.json"]:::sec

    %% Connections
    EntryPoint -->|"wraps App & AuthContext"| AppRouter
    AppRouter -->|"uses AuthContext"| AuthContext
    Login -->|"calls signIn"| AuthContext
    AuthContext -->|"signInWithEmailAndPassword"| AuthService
    AppRouter -->|"guards"| Dashboard
    Dashboard -->|"onSnapshot(patients)"| FirebaseService
    AppointmentCalendar -->|"CRUD appointments"| FirebaseService
    PatientProfile -->|"onSnapshot(metrics)"| FirebaseService
    FirebaseService -->|"Auth SDK"| AuthService
    FirebaseService -->|"Firestore SDK"| FirestoreDB
    FirestoreDB -->|"enforced by"| SecurityRules
    FirestoreDB -->|"indexed by"| Indexes

    %% Click Events
    click EntryPoint "https://github.com/asguizar/nutritrackapp/blob/main/src/index.tsx"
    click AppRouter "https://github.com/asguizar/nutritrackapp/blob/main/src/App.tsx"
    click AuthContext "https://github.com/asguizar/nutritrackapp/blob/main/src/contexts/AuthContext.tsx"
    click FirebaseService "https://github.com/asguizar/nutritrackapp/blob/main/src/config/firebase.ts"
    click Login "https://github.com/asguizar/nutritrackapp/blob/main/src/components/Login.tsx"
    click Dashboard "https://github.com/asguizar/nutritrackapp/blob/main/src/components/Dashboard.tsx"
    click AppointmentCalendar "https://github.com/asguizar/nutritrackapp/blob/main/src/components/AppointmentCalendar.tsx"
    click NewPatient "https://github.com/asguizar/nutritrackapp/blob/main/src/components/NewPatient.tsx"
    click PatientProfile "https://github.com/asguizar/nutritrackapp/blob/main/src/components/PatientProfile.tsx"
    click SecurityRules "https://github.com/asguizar/nutritrackapp/blob/main/firestore.rules"
    click Indexes "https://github.com/asguizar/nutritrackapp/blob/main/firestore.indexes.json"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef ctx fill:#FFFACD,stroke:#333,stroke-width:1px;
    classDef api fill:#FFFACD,stroke:#333,stroke-width:1px;
    classDef fs fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef sec fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
