# nithinpasula/healthsync architecture

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

- Interactive diagram: https://gitdiagram.com/nithinpasula/healthsync
- Repository: https://github.com/nithinpasula/healthsync

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Next.js (app router), TypeScript, and Tailwind CSS that provides patient appointment management (registering patients, booking appointments, success flow).
- It uses Appwrite as its backend-as-a-service (database, auth), and Sentry for monitoring/instrumentation.

##### File-Structure Analysis
- **app/** – Next.js App Router (server & client components), pages for admin, patients (with dynamic routes for userId), API routes under app/api/sentry-example-api.
- **components/** & **components/ui/** – React UI components, form fields, modals, data tables, theme provider.
- **lib/** – Shared utilities: Validation, appwrite.config.ts, action wrappers for patients/appointments, helper utils.
- **types/** & **constants/** – TypeScript definitions for Appwrite entities and global constants.
- **Configuration** files: next.config.mjs, tsconfig.json, tailwind.config.ts, postcss.config.mjs, Sentry configs.

##### Key Architectural Insights from README
- Standard Next.js setup with SSR/SSG, uses next/font, deployed on Vercel.
- No monolithic server code: backend logic is in API route handlers calling Appwrite SDK.

##### Main Components and Their Relationships
a. Client Browser (React/Next.js UI)
b. Next.js Server / Edge Functions (Server Components + API Routes)
c. Appwrite Backend (Auth, Database, Storage)
d. Sentry (Monitoring: client + server + edge)
e. Static Asset Hosting (Vercel CDN serving /public)

##### Interactions & Data Flow
- User → Browser → Next.js App Router → renders pages or client components
- Client Components → call Next.js API Routes (edge or lambda) for CRUD operations
- API Routes → invoke Appwrite SDK (lib/appwrite.config.ts) → Appwrite DB/Storage
- Throughout, Sentry SDK instruments both client and server requests
- Static assets served directly from the CDN

##### Architectural Patterns & Principles
- **Separation of Concerns**: UI components vs. API logic vs. domain actions (lib/actions).
- **Server-Component/Client-Component Split** with Next.js app router.
- **API Facade**: Next.js API routes abstract Appwrite calls for frontend.
- **Type-Safety**: TypeScript types in types/ drive end-to-end safety.
- **Theming & Design System**: Centralized UI primitives in components/ui & tailwind config.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Client Browser (React UI)"
        direction TB
        subgraph "UI Library"
            direction TB
            Button["button.tsx"]:::frontend
            Input["input.tsx"]:::frontend
            FormUI["form.tsx"]:::frontend
            Dialog["dialog.tsx"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            ThemeProvider["theme-provider.tsx"]:::frontend
            CustomFormField["CustomFormField.tsx"]:::frontend
            FileUploader["FileUploader.tsx"]:::frontend
            AppointmentModal["AppointmentModal.tsx"]:::frontend
            PasskeyModal["PasskeyModal.tsx"]:::frontend
            StatCard["StatCard.tsx"]:::frontend
            StatusBadge["StatusBadge.tsx"]:::frontend
            SubmitButton["SubmitButton.tsx"]:::frontend
        end
        subgraph "Domain Forms"
            direction TB
            RegisterForm["RegisterForm.tsx"]:::frontend
            PatientForm["PatientForm.tsx"]:::frontend
            AppointmentForm["AppointmentForm.tsx"]:::frontend
        end
        subgraph "Data Table"
            direction TB
            DataTable["DataTable.tsx"]:::frontend
            Columns["columns.tsx"]:::frontend
        end
    end

    %% Next.js Server / Edge
    subgraph "Next.js Server / Edge Functions"
        direction TB
        SSR["SSR Pages & Server Components"]:::backend
        API["API Route: /api/sentry-example-api"]:::api
    end

    %% Appwrite Backend
    subgraph "Appwrite Backend"
        direction TB
        AppwriteConfig["lib/appwrite.config.ts"]:::backend
        DB["Database"]:::db
        Auth["Auth"]:::db
        Storage["Storage"]:::db
    end

    %% Monitoring
    subgraph "Sentry (Monitoring)"
        direction TB
        Sentry["Sentry Cloud"]:::monitor
    end

    %% CDN
    subgraph "CDN / Static Assets"
        direction TB
        Assets["/public/assets"]:::cdn
    end

    %% Build & Deployment
    subgraph "Build & Deployment Settings"
        direction TB
        Settings["next.config.mjs\ntailwind.config.ts\npostcss.config.mjs\ntsconfig.json"]:::settings
    end

    %% Relationships
    Button -->|renders| SSR
    Input -->|renders| SSR
    FormUI -->|renders| SSR
    Dialog -->|renders| SSR

    ThemeProvider -->|wraps UI| SSR
    CustomFormField -->|used in forms| SSR
    FileUploader -->|used in forms| SSR
    AppointmentModal -->|used in pages| SSR
    PasskeyModal -->|used in pages| SSR
    StatCard -->|display stats| SSR
    StatusBadge -->|status display| SSR
    SubmitButton -->|form submit| SSR

    RegisterForm -->|uses API| API
    PatientForm -->|uses API| API
    AppointmentForm -->|uses API| API

    DataTable -->|uses API| API
    Columns -->|defines cols| DataTable

    SSR -->|"renders pages"| Button
    SSR -->|"renders pages"| Input

    SSR -->|"calls"| API
    API -->|"calls SDK"| AppwriteConfig
    AppwriteConfig -->|reads/writes| DB
    AppwriteConfig -->|auth operations| Auth
    AppwriteConfig -->|file ops| Storage

    SSR -->|"telemetry"| Sentry
    API -->|"telemetry"| Sentry
    Button -->|"telemetry"| Sentry

    SSR -->|"loads assets"| Assets
    Button -->|"loads assets"| Assets

    SSR -->|"build config"| Settings

    %% Click Events
    click Button "https://github.com/nithinpasula/healthsync/blob/main/components/ui/button.tsx"
    click Input "https://github.com/nithinpasula/healthsync/blob/main/components/ui/input.tsx"
    click FormUI "https://github.com/nithinpasula/healthsync/blob/main/components/ui/form.tsx"
    click Dialog "https://github.com/nithinpasula/healthsync/blob/main/components/ui/dialog.tsx"
    click ThemeProvider "https://github.com/nithinpasula/healthsync/blob/main/components/theme-provider.tsx"
    click CustomFormField "https://github.com/nithinpasula/healthsync/blob/main/components/CustomFormField.tsx"
    click FileUploader "https://github.com/nithinpasula/healthsync/blob/main/components/FileUploader.tsx"
    click AppointmentModal "https://github.com/nithinpasula/healthsync/blob/main/components/AppointmentModal.tsx"
    click PasskeyModal "https://github.com/nithinpasula/healthsync/blob/main/components/PasskeyModal.tsx"
    click StatCard "https://github.com/nithinpasula/healthsync/blob/main/components/StatCard.tsx"
    click StatusBadge "https://github.com/nithinpasula/healthsync/blob/main/components/StatusBadge.tsx"
    click SubmitButton "https://github.com/nithinpasula/healthsync/blob/main/components/SubmitButton.tsx"
    click RegisterForm "https://github.com/nithinpasula/healthsync/blob/main/components/forms/RegisterForm.tsx"
    click PatientForm "https://github.com/nithinpasula/healthsync/blob/main/components/forms/PatientForm.tsx"
    click AppointmentForm "https://github.com/nithinpasula/healthsync/blob/main/components/forms/AppointmentForm.tsx"
    click DataTable "https://github.com/nithinpasula/healthsync/blob/main/components/table/DataTable.tsx"
    click Columns "https://github.com/nithinpasula/healthsync/blob/main/components/table/columns.tsx"
    click AppwriteConfig "https://github.com/nithinpasula/healthsync/blob/main/lib/appwrite.config.ts"
    click Settings "https://github.com/nithinpasula/healthsync/blob/main/next.config.mjs"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef backend fill:#90EE90,stroke:#000
    classDef api fill:#32CD32,stroke:#000
    classDef db fill:#FFA500,stroke:#000
    classDef monitor fill:#DDA0DD,stroke:#000
    classDef cdn fill:#D3D3D3,stroke:#000
    classDef settings fill:#F0E68C,stroke:#000
```
