# adity0208/carelinks architecture

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

- Interactive diagram: https://gitdiagram.com/adity0208/carelinks
- Repository: https://github.com/adity0208/carelinks

## Overview

Based on your project’s file structure and the detailed README, CareLinks is a full-stack web application that helps community health workers manage patient records, appointments, vaccination tracking, and more. The application uses a modern React (with TypeScript) frontend combined with Firebase services (Firestore, Authentication, Hosting, and Cloud Functions) to provide real-time data updates and serverless backend logic. In addition, several AI modules (both GenAI and Vertex AI) are integrated to offer data insights, risk predictions, and even chatbot functionalities, all of which further enhance healthcare-related features.

##### Main Components
- Frontend:
- Represented by the React/TypeScript code in the src directory (components, pages, hooks, routes, etc.).
- Visual components such as AI panels, chat interfaces, dashboards, and navigation elements.
- Backend/Serverless Logic:
- The Firebase Cloud Functions (under functions/) that provide server-side logic, such as data processing and real-time updates.
- Firebase Authentication to handle secure user sign-ins and role-based access control.
- Database:
- Firestore (real-time database) that supports patient data, appointment schedules, vaccination records, etc.
- AI Services:
- AI modules from the src/services/ai, vertexAI, and genAI directories for generating insights, risk assessments, and summary predictions.
- External Service and Integration Layers:
- OpenAI integration for chatbot responses and additional analytics.
- Google Sheets integration to facilitate data management or external reporting.
- Deployment/Configuration Components:
- Firebase Hosting (configured in firebase.json and the supported CI/CD workflows in .github/workflows).
- Build script outputs found in the build folder.
- Configuration and rules files (firestore.rules, storage.rules) that define security and infrastructure policies.

##### Relationships and Interactions
- Authentication flow: the React frontend communicates with Firebase Authentication, which in turn secures data access across the entire system.
- Communication between the frontend components and the AI services (for example, how risk analysis and summary generators get called to provide insights).

##### Architectural Patterns and Principles
- Service-Oriented Architecture: Demonstrate how the serverless backend (Cloud Functions) isolates business logic from the frontend.
- Modular Component Design: Emphasize how the frontend is structured into various modules (AI, chat, dashboard, navigation, etc.) to support scalability and ease of maintenance.
- Real-time Data Sync: Clearly label components that use Firestore’s real-time update capability.
- Security Best Practices: Point out the use of Firebase Authentication, the .gitignore rules (for sensitive files), and the Firestore security rules.

##### Technologies and Frameworks
- Frontend: React, TypeScript, TailwindCSS.
- Backend: Firebase Cloud Functions, Firestore, Firebase Hosting, Firebase Authentication.
- AI: OpenAI integration and Vertex AI modules.
- Others: Vite (as seen in vite.config.ts), ESLint configurations, and various utility and configuration files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        UI["React UI"]:::frontend
    end

    subgraph "Backend/API Layer"
        CF["Firebase Cloud Functions"]:::backend
        FA["Firebase Auth"]:::backend
    end

    subgraph "Data & Integration Layer"
        FS["Firestore"]:::database
        GAI["GenAI Services"]:::ai
        VAI["Vertex AI Services"]:::ai
        GS["Google Sheets"]:::external
        DEP["Firebase Hosting & CI/CD"]:::deployment
        BO["Build Outputs"]:::deployment
    end

    UI -->|"Authentication"| FA
    UI -->|"APIcalls"| CF
    CF <-->|"Real-time"| FS
    CF -->|"AIRequest"| GAI
    CF -->|"AIRequest"| VAI
    UI -->|"DirectAI"| GAI
    UI -->|"DirectAI"| VAI
    CF -->|"DataSync"| GS
    DEP -->|"DeploysUI"| UI
    DEP -->|"DeploysFunctions"| CF
    BO -->|"ServesUI"| UI

    click UI "https://github.com/adity0208/carelinks/tree/main/src"
    click CF "https://github.com/adity0208/carelinks/tree/main/functions"
    click FA "https://github.com/adity0208/carelinks/blob/main/src/config/firebase.ts"
    click FS "https://github.com/adity0208/carelinks/blob/main/firestore.rules"
    click GAI "https://github.com/adity0208/carelinks/tree/main/src/services/ai/genai"
    click VAI "https://github.com/adity0208/carelinks/tree/main/src/services/ai/vertex"
    click GS "https://github.com/adity0208/carelinks/blob/main/src/services/googleSheets.ts"
    click DEP "https://github.com/adity0208/carelinks/blob/main/firebase.json"
    click BO "https://github.com/adity0208/carelinks/tree/main/build"

    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef database fill:#f4a460,stroke:#000,stroke-width:2px;
    classDef ai fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef external fill:#ffb6c1,stroke:#000,stroke-width:2px;
    classDef deployment fill:#d3d3d3,stroke:#000,stroke-width:2px;
```
