# ealanisln/vet-family-23 architecture

> Architecture diagram of the GitHub repository ealanisln/vet-family-23, 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/ealanisln/vet-family-23
- Repository: https://github.com/ealanisln/vet-family-23

## Overview

##### Project type and purpose
- Vet Family is a full-stack web application for veterinary clinic management.
- Built on Next.js (App Router) + TypeScript, with a Prisma-powered MongoDB backend.
- Key domains: user & pet management, appointments, billing, reminders, multi-role admin panel, public site and blog (via Sanity).

##### File structure
- Top-level files: next.config.js, Docker Compose, Prisma folder (schema + migrations), Sanity config, scripts for DB sync.
- src/app: App Router pages split into route groups:
- (admin) – admin dashboard and POS system
- (main) – public customer portal (view/edit profile, pet info, booking)
- (contact) – blog and public pages
- api – Next.js API routes for auth, CRUD on clients/pets/inventory/pos, health checks
- components/ – reusable UI components organized by domain (Admin, POS, Inventory, Blog, etc.)
- lib/, services/, utils/ – data-access helpers, external integration code (mailer, Cloudinary, Kinde)
- prisma/ – ORM schema.prisma defining User, Pet, MedicalHistory, Appointment, Billing, Reminder, Staff models
- sanity/ – headless CMS for blog (schemas, client utilities)

##### README for additional insights
- Confirms tech stack: Next.js + TypeScript, MongoDB + Prisma, Sanity CMS, Kinde for authentication
- Summarizes domain models and relationships
- Lists major features (appointments, billing, reminders, multi-role support)

- Browser / Client (React + Next.js pages)
- Next.js Server (App Router + API Routes)
- Authentication Service (Kinde)
- Database (MongoDB via Prisma ORM)
- Headless CMS (Sanity)
- External Media Service (Cloudinary)
- Email Service (mailer.ts)
- Scripts / Cron Jobs (db-sync.sh, reminder emails)
- Client ↔ Next.js Server (SSR, CSR, API calls)
- Server → MongoDB (queries/mutations via Prisma)
- Server ↔ Kinde (auth flows, token validation)
- Server ↔ Sanity API (fetch blog content)
- Server ↔ Cloudinary SDK (upload/fetch images)
- Server → Email Service (send reminders/invoices)
- Cron/Script → Server → DB (sync/data-maintenance)
c. Architectural patterns & design principles:
- Monolithic “full-stack” SSR/CSR application using Next.js App Router
- File-system routing divides public vs admin UI
- Domain layering: UI components → actions/services → API routes → ORM → DB
- Dependency injection via lib/ and services/ for third-party clients
- Headless CMS decoupled from main DB
d. Key technologies & libraries:
- Next.js, React, TypeScript, Tailwind CSS
- Prisma ORM → MongoDB
- Kinde SDK for authentication
- Sanity headless CMS
- Cloudinary for image hosting
- Node mailer or custom mailer.ts for emails
- Docker Compose for local dev

##### Elements
- Orange for database
- Gray for external services
- Annotations for major route groups (/(admin), /(main), /api)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Browser["Browser / Client (React + Next.js UI)"]:::frontend
        subgraph "Admin Dashboard & POS UI"
            direction TB
            AdminUI["Admin UI Routes"]:::frontend
        end
        subgraph "Public Customer Portal UI"
            direction TB
            PublicUI["Customer Portal UI Routes"]:::frontend
        end
        subgraph "Blog & Public Site"
            direction TB
            BlogUI["Blog & Public UI Routes"]:::frontend
        end
    end

    %% Server Layer
    subgraph "Server Layer" 
        direction TB
        NextServer["Next.js App Router"]:::server
        APIRoutes["Next.js API Routes"]:::server
        BizLogic["Business Logic Actions / Services"]:::server
        Utils["Utility Libraries & Helpers"]:::server
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        MongoDB["MongoDB (Prisma ORM)"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Auth["Authentication Service (Kinde)"]:::external
        CMS["Headless CMS (Sanity)"]:::external
        Media["External Media Service (Cloudinary)"]:::external
        Email["Email Service (Mailer)"]:::external
        Cron["Cron Jobs / Scripts"]:::external
    end

    %% Connections
    Browser -->|uses UI Routes| NextServer
    AdminUI --> NextServer
    PublicUI --> NextServer
    BlogUI --> NextServer

    NextServer -->|routes handling| APIRoutes
    APIRoutes -->|calls| BizLogic
    BizLogic -->|uses| Utils
    APIRoutes -->|queries/mutations| MongoDB

    NextServer -->|auth flows| Auth
    APIRoutes -->|token validation| Auth

    NextServer -->|fetch content| CMS
    APIRoutes -->|CMS API calls| CMS

    APIRoutes -->|image upload/fetch| Media
    BizLogic -->|calls mailer| Email

    Cron -->|triggers scripts| NextServer
    Cron -->|sync DB| MongoDB
    Cron -->|send reminders| Email

    %% Click events for component mapping
    click NextServer "https://github.com/ealanisln/vet-family-23/tree/main/src/app"
    click APIRoutes "https://github.com/ealanisln/vet-family-23/tree/main/src/app/api"
    click Auth "https://github.com/ealanisln/vet-family-23/blob/main/lib/kinde-config.ts"
    click Auth "https://github.com/ealanisln/vet-family-23/blob/main/src/providers/KindeProvider.tsx"
    click Auth "https://github.com/ealanisln/vet-family-23/blob/main/src/app/api/auth/[...kindeAuth]/route.ts"
    click Auth "https://github.com/ealanisln/vet-family-23/blob/main/src/app/api/kinde-token/route.ts"
    click Auth "https://github.com/ealanisln/vet-family-23/blob/main/src/app/api/kinde-webhook/route.ts"
    click MongoDB "https://github.com/ealanisln/vet-family-23/blob/main/prisma/schema.prisma"
    click MongoDB "https://github.com/ealanisln/vet-family-23/tree/main/prisma/migrations/**"
    click MongoDB "https://github.com/ealanisln/vet-family-23/blob/main/lib/prismaDB.ts"
    click CMS "https://github.com/ealanisln/vet-family-23/blob/main/sanity.config.ts"
    click CMS "https://github.com/ealanisln/vet-family-23/tree/main/src/sanity/lib"
    click CMS "https://github.com/ealanisln/vet-family-23/tree/main/src/sanity/schemas"
    click Media "https://github.com/ealanisln/vet-family-23/blob/main/lib/cloudinary.ts"
    click Media "https://github.com/ealanisln/vet-family-23/blob/main/utils/cloudinary.ts"
    click Media "https://github.com/ealanisln/vet-family-23/blob/main/dist/utils/cloudinary.js"
    click Media "https://github.com/ealanisln/vet-family-23/blob/main/src/components/GaleriaFotos/cloudinary-image.tsx"
    click Email "https://github.com/ealanisln/vet-family-23/blob/main/lib/mailer.ts"
    click Cron "https://github.com/ealanisln/vet-family-23/blob/main/scripts/db-sync.sh"
    click AdminUI "https://github.com/ealanisln/vet-family-23/tree/main/src/app/(admin)"
    click AdminUI "https://github.com/ealanisln/vet-family-23/tree/main/src/components/Admin"
    click AdminUI "https://github.com/ealanisln/vet-family-23/tree/main/src/components/POS"
    click PublicUI "https://github.com/ealanisln/vet-family-23/tree/main/src/app/(main)"
    click PublicUI "https://github.com/ealanisln/vet-family-23/tree/main/src/components/Clientes"
    click PublicUI "https://github.com/ealanisln/vet-family-23/tree/main/src/components/ClienteForm"
    click BlogUI "https://github.com/ealanisln/vet-family-23/tree/main/src/app/(contact)/blog"
    click BlogUI "https://github.com/ealanisln/vet-family-23/tree/main/src/components/Blog"
    click BlogUI "https://github.com/ealanisln/vet-family-23/tree/main/src/components/BlogNavbar"
    click BizLogic "https://github.com/ealanisln/vet-family-23/tree/main/src/app/actions"
    click BizLogic "https://github.com/ealanisln/vet-family-23/tree/main/src/services"
    click Utils "https://github.com/ealanisln/vet-family-23/tree/main/src/lib"
    click Utils "https://github.com/ealanisln/vet-family-23/tree/main/src/utils"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef server fill:#DFFFE0,stroke:#28A745,color:#28A745;
    classDef database fill:#FFE4B5,stroke:#E36209,color:#E36209;
    classDef external fill:#F0F0F0,stroke:#6A737D,color:#6A737D;
```
