# xclarissa/nextjs_health_system architecture

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

- Interactive diagram: https://gitdiagram.com/xclarissa/nextjs_health_system
- Repository: https://github.com/xclarissa/nextjs_health_system

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Next.js (App Router) for the frontend/UI layer and Appwrite as a backend-as-a-service (database, auth, storage). It integrates with Twilio (for SMS/notifications), Stylized with TailwindCSS and ShadCN UI components, all written in TypeScript.

##### High-Level File-Structure Analysis
- Top-level:
- app/ – Next.js App Router pages and layouts
- components/ – React UI components and forms
- lib/ – wrappers around Appwrite SDK (actions, config, utility functions, validation)
- constants/, types/ – shared types and constants
- next.config.mjs, tailwind.config.ts, postcss.config.mjs – build/deployment and styling configuration
- There are no traditional microservices; the app client/server logic lives in Next.js pages and calls out to Appwrite.

##### README Insights
- Uses Appwrite for all backend services (database CRUD, authentication, storage).
- Uses Twilio alongside Appwrite, likely invoked from lib/actions when scheduling appointments or sending notifications.
- Styling: Tailwind + ShadCN; Fonts optimized via next/font.

##### Main Components & Interactions
A. Frontend (Next.js App)
– app/layout.tsx: global layout, theme-provider
– app/page.tsx & dynamic routes under app/patients/[userId]
– components: UI primitives (button, input), forms (AppointmentForm, PatientForm, RegisterForm)
B. Business Logic Layer (lib/actions)
– appointment.actions.ts & patient.actions.ts wrap Appwrite SDK calls
– lib/validation.ts enforces form/business rules
– lib/utils.ts for shared utilities
C. Backend-as-a-Service (Appwrite)
– Authentication (users, sessions)
– Database collections (patients, appointments)
– Storage for file uploads (via FileUploader component)
– [Optional] Cloud functions if Twilio integration is serverless
D. External Service (Twilio)
– SMS/notification API triggered by appointment.actions or an Appwrite function
E. Static Assets

##### Relationships & Data Flows
1. User opens React pages in browser → Next.js SSR/ISR or client components render forms/UI.
2. User submits a form → component calls lib/actions (REST or Appwrite JS SDK)
3. lib/actions → communicates with Appwrite (database write/read or auth)
4. On appointment creation, actions layer invokes Twilio API (either directly or via Appwrite Cloud Function)
5. Responses flow back to UI for real-time feedback (success pages, error handling)

##### Architectural Patterns & Design Principles
– Presentation Layer (Next.js + ShadCN components) separated from Business Logic Layer (lib/actions).
– BaaS pattern: offloading auth, DB, storage to Appwrite; no custom backend servers.
– Dynamic routing via Next.js App Router for nested resources (patients, appointments).
– Form-first approach: small reusable form components + validation.
– Utility first styling (TailwindCSS) and design tokens (constants, theme provider).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Next.js)" 
        direction TB
        Browser(["Browser"]):::frontend
        Layout["Global Layout"]:::frontend
        Home["Home Page"]:::frontend
        PatientDashboard["Patient Dashboard"]:::frontend
        NewAppointment["New Appointment Page"]:::frontend
        SuccessPage["Appointment Success Page"]:::frontend
        RegisterPage["Patient Registration Page"]:::frontend
        AppointmentForm["AppointmentForm"]:::frontend
        PatientForm["PatientForm"]:::frontend
        RegisterForm["RegisterForm"]:::frontend
        FileUploader["FileUploader"]:::frontend
        UI_Button["Button"]:::frontend
        UI_Input["Input"]:::frontend
        UI_Label["Label"]:::frontend
        UI_Checkbox["Checkbox"]:::frontend
        UI_Radio["RadioGroup"]:::frontend
        UI_Select["Select"]:::frontend
        UI_Textarea["Textarea"]:::frontend
        UI_Form["Form Wrapper"]:::frontend
        ThemeProvider["Theme Provider"]:::frontend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer" 
        direction TB
        AppointmentActions["Appointment Actions"]:::biz
        PatientActions["Patient Actions"]:::biz
        Validation["Validation Logic"]:::biz
        Utils["Utility Functions"]:::biz
    end

    %% Appwrite Services
    subgraph "Appwrite Services" 
        direction TB
        AW_Auth(["Auth Service"]):::service
        AW_DB(["Database Service"]):::service
        AW_Storage(["Storage Service"]):::service
        AW_Functions(["Cloud Functions"]):::service
    end

    %% External Service
    Twilio(["Twilio SMS API"]):::service

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

    %% Data Flows
    Browser --> Layout
    Layout --> Home
    Home --> PatientDashboard
    PatientDashboard --> NewAppointment
    NewAppointment --> SuccessPage
    PatientDashboard --> RegisterPage

    NewAppointment --> AppointmentForm
    PatientDashboard --> PatientForm
    RegisterPage --> RegisterForm

    AppointmentForm --> AppointmentActions
    PatientForm --> PatientActions
    RegisterForm --> PatientActions
    FileUploader --> AW_Storage

    AppointmentActions --> AW_DB
    AppointmentActions --> AW_Auth
    AppointmentActions --> AW_Functions
    AppointmentActions --> Twilio

    PatientActions --> AW_DB
    PatientActions --> AW_Auth

    Validation --> AppointmentForm
    Validation --> PatientForm
    Validation --> RegisterForm

    Utils --> AppointmentActions
    Utils --> PatientActions
    Utils --> Layout

    AW_DB --> Home
    AW_DB --> PatientDashboard

    %% Click Events
    click Layout "https://github.com/xclarissa/nextjs_health_system/blob/main/app/layout.tsx"
    click Home "https://github.com/xclarissa/nextjs_health_system/blob/main/app/page.tsx"
    click PatientDashboard "https://github.com/xclarissa/nextjs_health_system/blob/main/app/patients/[userId]/page.tsx"
    click NewAppointment "https://github.com/xclarissa/nextjs_health_system/blob/main/app/patients/[userId]/new-appointment/page.tsx"
    click SuccessPage "https://github.com/xclarissa/nextjs_health_system/blob/main/app/patients/[userId]/new-appointment/success/page.tsx"
    click RegisterPage "https://github.com/xclarissa/nextjs_health_system/blob/main/app/patients/[userId]/register/page.tsx"
    click AppointmentForm "https://github.com/xclarissa/nextjs_health_system/blob/main/components/forms/AppointmentForm.tsx"
    click PatientForm "https://github.com/xclarissa/nextjs_health_system/blob/main/components/forms/PatientForm.tsx"
    click RegisterForm "https://github.com/xclarissa/nextjs_health_system/blob/main/components/forms/RegisterForm.tsx"
    click FileUploader "https://github.com/xclarissa/nextjs_health_system/blob/main/components/FileUploader.tsx"
    click UI_Button "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/button.tsx"
    click UI_Input "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/input.tsx"
    click UI_Label "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/label.tsx"
    click UI_Checkbox "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/checkbox.tsx"
    click UI_Radio "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/radio-group.tsx"
    click UI_Select "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/select.tsx"
    click UI_Textarea "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/textarea.tsx"
    click UI_Form "https://github.com/xclarissa/nextjs_health_system/blob/main/components/ui/form.tsx"
    click ThemeProvider "https://github.com/xclarissa/nextjs_health_system/blob/main/components/theme-provider.tsx"
    click AppointmentActions "https://github.com/xclarissa/nextjs_health_system/blob/main/lib/actions/appointment.actions.ts"
    click PatientActions "https://github.com/xclarissa/nextjs_health_system/blob/main/lib/actions/patient.actions.ts"
    click Validation "https://github.com/xclarissa/nextjs_health_system/blob/main/lib/validation.ts"
    click Utils "https://github.com/xclarissa/nextjs_health_system/blob/main/lib/utils.ts"
    click Assets "https://github.com/xclarissa/nextjs_health_system/tree/main/public/assets/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef biz fill:#E6FFDA,stroke:#28A745,color:#23612D;
    classDef service fill:#FFE4B5,stroke:#FF8C00,color:#8B4513;
    classDef asset fill:#F0F0F0,stroke:#A0A0A0,color:#606060;
```
