# imroniel/leafcheck-ai architecture

> Architecture diagram of the GitHub repository imroniel/leafcheck-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/imroniel/leafcheck-ai
- Repository: https://github.com/imroniel/leafcheck-ai

## Overview

Leaf-Check-AI is a mobile plant-care product combining plant records, image-based diagnosis, sensor telemetry, and care guidance. Its principal flow is a mobile user managing plants and scans, with the app communicating with backend routes that persist records or invoke diagnosis providers; sensor firmware is a separate telemetry source. The README also describes AR overlays and analytics, but the sampled files do not establish their implementation or wiring, so those links are marked unverified. Edges reflect excerpts, SOURCE INDEX references, or README statements; unsampled modules are represented conservatively.

Main entry points: [`frontend/app/(tabs)/index.tsx`](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/index.tsx) (Expo Mobile App), [`backend/src/server.ts`](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/server.ts) (HTTP Server and Routing), [`backend/src/routes/scan.ts`](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/scan.ts) (Scan Diagnosis), [`backend/src/lib/prisma-pg.ts`](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/prisma-pg.ts) (PostgreSQL Data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile App"]
  node_mobile["Expo Mobile App<br/>[index.tsx]"]
  node_authui["Mobile Authentication<br/>[auth.tsx]"]
  node_session["Session Coordinator<br/>[session.ts]"]
  node_tokens[("Secure Token Storage")]
  node_localstate[("Local Setup State")]
  node_garden["Garden and Plant Care<br/>[garden.tsx]"]
  node_scanning["Plant Scan Flow<br/>[scan-flow.ts]"]
  node_dashboard["Health and Care Dashboard<br/>[tasks.tsx]"]
  node_camera["Camera and AR View<br/>[camera.tsx]"]
  node_api["Backend API Client<br/>[api.ts]"]
end

subgraph group_backend["Backend API"]
  node_server["HTTP Server and Routing<br/>[server.ts]"]
  node_authroutes["Authentication Routes<br/>[auth.ts]"]
  node_authlogic["Session and Token Logic<br/>[auth.ts]"]
  node_plantroutes["Plant Records<br/>[plants.ts]"]
  node_scanroutes["Scan Diagnosis<br/>[scan.ts]"]
  node_airoutes["AI Analysis<br/>[ai.ts]"]
  node_telemetry["Sensor Telemetry<br/>[telemetry.ts]"]
  node_pg[("PostgreSQL Data<br/>[prisma-pg.ts]")]
  node_mongo[("Telemetry Store<br/>[prisma.ts]")]
end

subgraph group_integrations["Diagnosis Providers"]
  node_gemini["Gemini Diagnosis<br/>[gemini.ts]"]
  node_plantid["Plant Identification Providers<br/>[plantnet.ts]"]
  node_catalog["Plant Catalog Provider<br/>[perenual.ts]"]
end

subgraph group_hardware["Sensor Hardware"]
  node_firmware["ESP32 Sensor Firmware<br/>[main.cpp]"]
end

node_user(("Plant Care User"))

node_user -->|"manages plants"| node_mobile
node_mobile -.->|"authenticates"| node_authui
node_authui -->|"coordinates sessions"| node_session
node_authui -->|"binds session"| node_api
node_authui -.->|"uses token storage"| node_tokens
node_mobile -.->|"manages collection"| node_garden
node_mobile -.->|"starts scans"| node_scanning
node_mobile -.->|"reviews care"| node_dashboard
node_user -.->|"views plant overlays"| node_camera
node_mobile -.->|"stores setup data"| node_localstate
node_api -.->|"sends API requests"| node_server
node_server -->|"routes requests"| node_authroutes
node_server -->|"routes requests"| node_plantroutes
node_server -->|"routes requests"| node_scanroutes
node_server -->|"routes requests"| node_airoutes
node_server -->|"routes requests"| node_telemetry
node_authroutes -->|"uses session logic"| node_authlogic
node_authroutes -->|"reads and writes"| node_pg
node_authlogic -->|"persists sessions"| node_pg
node_plantroutes -->|"persists plant records"| node_pg
node_scanroutes -->|"uses database"| node_pg
node_scanroutes -->|"uses database"| node_mongo
node_scanroutes -->|"requests diagnosis"| node_gemini
node_scanroutes -->|"identifies species"| node_plantid
node_scanroutes -->|"looks up plant data"| node_catalog
node_airoutes -->|"requests analysis"| node_gemini
node_telemetry -->|"uses database"| node_pg
node_telemetry -->|"uses database"| node_mongo
node_firmware -.->|"sends sensor readings"| node_telemetry
node_mobile -.->|"reviews analytics"| node_dashboard

click node_mobile "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/index.tsx"
click node_authui "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/context/auth.tsx"
click node_session "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/session.ts"
click node_tokens "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/token-storage.native.ts"
click node_localstate "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/local-state-storage.ts"
click node_garden "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/garden.tsx"
click node_scanning "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/scan-flow.ts"
click node_dashboard "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/tasks.tsx"
click node_camera "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/camera.tsx"
click node_api "https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/api.ts"
click node_server "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/server.ts"
click node_authroutes "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/auth.ts"
click node_authlogic "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/auth.ts"
click node_plantroutes "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/plants.ts"
click node_scanroutes "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/scan.ts"
click node_airoutes "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/ai.ts"
click node_telemetry "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/telemetry.ts"
click node_pg "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/prisma-pg.ts"
click node_mongo "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/prisma.ts"
click node_gemini "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/gemini.ts"
click node_plantid "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/plantnet.ts"
click node_catalog "https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/perenual.ts"
click node_firmware "https://github.com/imroniel/leafcheck-ai/blob/main/hardware/firmware/src/main.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mobile,node_authui,node_session,node_tokens,node_localstate,node_garden,node_scanning,node_dashboard,node_camera,node_api,node_user toneBlue
class node_server,node_authroutes,node_authlogic,node_plantroutes,node_scanroutes,node_airoutes,node_telemetry,node_pg,node_mongo toneAmber
class node_gemini,node_plantid,node_catalog toneMint
class node_firmware toneRose
```

## Components

### Mobile App

- [Expo Mobile App](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/index.tsx): `frontend/app/(tabs)/index.tsx`
- [Mobile Authentication](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/context/auth.tsx): `frontend/context/auth.tsx`
- [Session Coordinator](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/session.ts): `frontend/services/session.ts`
- [Secure Token Storage](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/token-storage.native.ts): `frontend/services/token-storage.native.ts`
- [Local Setup State](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/local-state-storage.ts): `frontend/services/local-state-storage.ts`
- [Garden and Plant Care](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/garden.tsx): `frontend/app/(tabs)/garden.tsx`
- [Plant Scan Flow](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/scan-flow.ts): `frontend/services/scan-flow.ts`
- [Health and Care Dashboard](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/tasks.tsx): `frontend/app/(tabs)/tasks.tsx`
- [Camera and AR View](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/app/(tabs)/camera.tsx): `frontend/app/(tabs)/camera.tsx`
- [Backend API Client](https://github.com/imroniel/leafcheck-ai/blob/main/frontend/services/api.ts): `frontend/services/api.ts`

### Backend API

- [HTTP Server and Routing](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [Authentication Routes](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/auth.ts): `backend/src/routes/auth.ts`
- [Session and Token Logic](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/auth.ts): `backend/src/lib/auth.ts`
- [Plant Records](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/plants.ts): `backend/src/routes/plants.ts`
- [Scan Diagnosis](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/scan.ts): `backend/src/routes/scan.ts`
- [AI Analysis](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/ai.ts): `backend/src/routes/ai.ts`
- [Sensor Telemetry](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/routes/telemetry.ts): `backend/src/routes/telemetry.ts`
- [PostgreSQL Data](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/prisma-pg.ts): `backend/src/lib/prisma-pg.ts`
- [Telemetry Store](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/prisma.ts): `backend/src/lib/prisma.ts`

### Diagnosis Providers

- [Gemini Diagnosis](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/gemini.ts): `backend/src/lib/gemini.ts`
- [Plant Identification Providers](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/plantnet.ts): `backend/src/lib/plantnet.ts`
- [Plant Catalog Provider](https://github.com/imroniel/leafcheck-ai/blob/main/backend/src/lib/perenual.ts): `backend/src/lib/perenual.ts`

### Sensor Hardware

- [ESP32 Sensor Firmware](https://github.com/imroniel/leafcheck-ai/blob/main/hardware/firmware/src/main.cpp): `hardware/firmware/src/main.cpp`

### Other components

- **Plant Care User**

## Connections

- Plant Care User → Expo Mobile App: manages plants
- Expo Mobile App → Mobile Authentication: authenticates
- Mobile Authentication → Session Coordinator: coordinates sessions (evidence: `frontend/context/auth.tsx`)
- Mobile Authentication → Backend API Client: binds session (evidence: `frontend/context/auth.tsx`)
- Mobile Authentication → Secure Token Storage: uses token storage
- Expo Mobile App → Garden and Plant Care: manages collection
- Expo Mobile App → Plant Scan Flow: starts scans
- Expo Mobile App → Health and Care Dashboard: reviews care
- Plant Care User → Camera and AR View: views plant overlays
- Expo Mobile App → Local Setup State: stores setup data
- Backend API Client → HTTP Server and Routing: sends API requests
- HTTP Server and Routing → Authentication Routes: routes requests (evidence: `backend/src/server.ts`)
- HTTP Server and Routing → Plant Records: routes requests (evidence: `backend/src/server.ts`)
- HTTP Server and Routing → Scan Diagnosis: routes requests (evidence: `backend/src/server.ts`)
- HTTP Server and Routing → AI Analysis: routes requests (evidence: `backend/src/server.ts`)
- HTTP Server and Routing → Sensor Telemetry: routes requests (evidence: `backend/src/server.ts`)
- Authentication Routes → Session and Token Logic: uses session logic (evidence: `backend/src/routes/auth.ts`)
- Authentication Routes → PostgreSQL Data: reads and writes (evidence: `backend/src/routes/auth.ts`)
- Session and Token Logic → PostgreSQL Data: persists sessions (evidence: `backend/src/lib/auth.ts`)
- Plant Records → PostgreSQL Data: persists plant records (evidence: `backend/src/routes/plants.ts`)
- Scan Diagnosis → PostgreSQL Data: uses database (evidence: `backend/src/routes/scan.ts`)
- Scan Diagnosis → Telemetry Store: uses database (evidence: `backend/src/routes/scan.ts`)
- Scan Diagnosis → Gemini Diagnosis: requests diagnosis (evidence: `backend/src/routes/scan.ts`)
- Scan Diagnosis → Plant Identification Providers: identifies species (evidence: `backend/src/routes/scan.ts`)
- Scan Diagnosis → Plant Catalog Provider: looks up plant data (evidence: `backend/src/routes/scan.ts`)
- AI Analysis → Gemini Diagnosis: requests analysis (evidence: `backend/src/routes/ai.ts`)
- Sensor Telemetry → PostgreSQL Data: uses database (evidence: `backend/src/routes/telemetry.ts`)
- Sensor Telemetry → Telemetry Store: uses database (evidence: `backend/src/routes/telemetry.ts`)
- ESP32 Sensor Firmware → Sensor Telemetry: sends sensor readings
- Expo Mobile App → Health and Care Dashboard: reviews analytics
