# keilevv/leaf_classifier architecture

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

- Interactive diagram: https://gitdiagram.com/keilevv/leaf_classifier
- Repository: https://github.com/keilevv/leaf_classifier

## Overview

Leaf Classifier lets users submit leaf images, receive model predictions, and review or edit saved classifications; administrators manage classifications, users, species, and classifier models. The frontend calls a backend API, which coordinates persistence and the separate Python classifier. The README also documents distinct species, history, settings, and model-management capabilities. The graph uses sampled frontend hooks and service code plus documented capabilities and tree paths; several route-to-controller links are omitted because those implementations were not sampled.

Main entry points: [`backend/src/app.ts`](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/app.ts) (API application), [`backend/src/services/PlantClassifierService.ts`](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/services/PlantClassifierService.ts) (Classification workflow), [`frontend/src/App.jsx`](https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/App.jsx) (Pages and routes), [`frontend/src/Services`](https://github.com/keilevv/leaf_classifier/tree/main/frontend/src/Services) (API services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_webapp["Pages and routes<br/>[App.jsx]"]
  node_authhook["Authentication hook<br/>[useAuth.js]"]
  node_classifierhook["Classifier hook<br/>[useClassifier.js]"]
  node_adminhook["Admin hook<br/>[useAdmin.js]"]
  node_frontendservices["API services"]
end

subgraph group_api["Backend API"]
  node_backendapp["API application<br/>[app.ts]"]
  node_authroutes["Auth routes<br/>[auth.ts]"]
  node_classifieroutes["Classifier routes<br/>[plantClassifier.ts]"]
  node_adminroutes["Admin routes<br/>[admin.ts]"]
  node_authservice["Authentication<br/>[AuthService.ts]"]
  node_plantservice["Classification workflow"]
  node_adminservice["Administration<br/>[AdminService.ts]"]
  node_speciesroutes["Species management<br/>[species.ts]"]
  node_userroutes["User management<br/>[user.ts]"]
  node_classificationrepo["Classification data access"]
  node_authrepo["Authentication data access<br/>[AuthRepository.ts]"]
  node_adminrepo["Administration data access<br/>[AdminRepository.ts]"]
end

subgraph group_ml["Classifier service"]
  node_classifierapp["Prediction service<br/>[predict.py]"]
  node_retrain["Model management<br/>[retrain.py]"]
end

subgraph group_integrations["External services"]
  node_database[("PostgreSQL")]
  node_r2[("Cloudflare R2")]
  node_google(("Google sign-in"))
end

node_user(("User"))

node_user -->|"uses"| node_webapp
node_webapp -->|"authenticates through"| node_authhook
node_webapp -->|"uploads and reviews"| node_classifierhook
node_webapp -->|"administers through"| node_adminhook
node_authhook -->|"requests auth"| node_frontendservices
node_classifierhook -->|"requests predictions"| node_frontendservices
node_adminhook -->|"requests administration"| node_frontendservices
node_frontendservices -->|"calls API"| node_backendapp
node_backendapp -->|"mounts"| node_authroutes
node_backendapp -->|"mounts"| node_classifieroutes
node_backendapp -->|"mounts"| node_adminroutes
node_backendapp -->|"mounts"| node_speciesroutes
node_backendapp -->|"mounts"| node_userroutes
node_authservice -->|"reads and creates users"| node_authrepo
node_authrepo -->|"queries"| node_database
node_plantservice -->|"sends image for prediction"| node_classifierapp
node_plantservice -.->|"stores image"| node_r2
node_plantservice -->|"creates and queries records"| node_classificationrepo
node_classificationrepo -->|"queries"| node_database
node_adminservice -->|"reads and updates records"| node_adminrepo
node_adminrepo -->|"queries"| node_database
node_adminservice -.->|"renames stored images"| node_r2
node_plantservice -->|"requests model operations"| node_retrain
node_authroutes -.->|"supports sign-in"| node_google

click node_webapp "https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/App.jsx"
click node_authhook "https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/hooks/useAuth.js"
click node_classifierhook "https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/hooks/useClassifier.js"
click node_adminhook "https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/hooks/useAdmin.js"
click node_frontendservices "https://github.com/keilevv/leaf_classifier/tree/main/frontend/src/Services"
click node_backendapp "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/app.ts"
click node_authroutes "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/auth.ts"
click node_classifieroutes "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/plantClassifier.ts"
click node_adminroutes "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/admin.ts"
click node_authservice "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/services/AuthService.ts"
click node_plantservice "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/services/PlantClassifierService.ts"
click node_adminservice "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/services/AdminService.ts"
click node_speciesroutes "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/species.ts"
click node_userroutes "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/user.ts"
click node_classificationrepo "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/repositories/ClassificationRepository.ts"
click node_authrepo "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/repositories/AuthRepository.ts"
click node_adminrepo "https://github.com/keilevv/leaf_classifier/blob/main/backend/src/repositories/AdminRepository.ts"
click node_classifierapp "https://github.com/keilevv/leaf_classifier/blob/main/classifier/app/routes/predict.py"
click node_retrain "https://github.com/keilevv/leaf_classifier/blob/main/classifier/app/routes/retrain.py"

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_webapp,node_authhook,node_classifierhook,node_adminhook,node_frontendservices,node_user toneBlue
class node_backendapp,node_authroutes,node_classifieroutes,node_adminroutes,node_authservice,node_plantservice,node_adminservice,node_speciesroutes,node_userroutes,node_classificationrepo,node_authrepo,node_adminrepo toneAmber
class node_classifierapp,node_retrain toneMint
class node_database,node_r2,node_google toneRose
```

## Components

### Web application

- [Pages and routes](https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Authentication hook](https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/hooks/useAuth.js): `frontend/src/hooks/useAuth.js`
- [Classifier hook](https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/hooks/useClassifier.js): `frontend/src/hooks/useClassifier.js`
- [Admin hook](https://github.com/keilevv/leaf_classifier/blob/main/frontend/src/hooks/useAdmin.js): `frontend/src/hooks/useAdmin.js`
- [API services](https://github.com/keilevv/leaf_classifier/tree/main/frontend/src/Services): `frontend/src/Services`

### Backend API

- [API application](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [Auth routes](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/auth.ts): `backend/src/routes/auth.ts`
- [Classifier routes](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/plantClassifier.ts): `backend/src/routes/plantClassifier.ts`
- [Admin routes](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/admin.ts): `backend/src/routes/admin.ts`
- [Authentication](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/services/AuthService.ts): `backend/src/services/AuthService.ts`
- [Classification workflow](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/services/PlantClassifierService.ts): `backend/src/services/PlantClassifierService.ts`
- [Administration](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/services/AdminService.ts): `backend/src/services/AdminService.ts`
- [Species management](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/species.ts): `backend/src/routes/species.ts`
- [User management](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/routes/user.ts): `backend/src/routes/user.ts`
- [Classification data access](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/repositories/ClassificationRepository.ts): `backend/src/repositories/ClassificationRepository.ts`
- [Authentication data access](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/repositories/AuthRepository.ts): `backend/src/repositories/AuthRepository.ts`
- [Administration data access](https://github.com/keilevv/leaf_classifier/blob/main/backend/src/repositories/AdminRepository.ts): `backend/src/repositories/AdminRepository.ts`

### Classifier service

- [Prediction service](https://github.com/keilevv/leaf_classifier/blob/main/classifier/app/routes/predict.py): `classifier/app/routes/predict.py`
- [Model management](https://github.com/keilevv/leaf_classifier/blob/main/classifier/app/routes/retrain.py): `classifier/app/routes/retrain.py`

### External services

- **PostgreSQL**
- **Cloudflare R2**
- **Google sign-in**

### Other components

- **User**

## Connections

- User → Pages and routes: uses
- Pages and routes → Authentication hook: authenticates through
- Pages and routes → Classifier hook: uploads and reviews
- Pages and routes → Admin hook: administers through
- Authentication hook → API services: requests auth
- Classifier hook → API services: requests predictions
- Admin hook → API services: requests administration
- API services → API application: calls API
- API application → Auth routes: mounts
- API application → Classifier routes: mounts
- API application → Admin routes: mounts
- API application → Species management: mounts
- API application → User management: mounts
- Authentication → Authentication data access: reads and creates users
- Authentication data access → PostgreSQL: queries
- Classification workflow → Prediction service: sends image for prediction
- Classification workflow → Cloudflare R2: stores image
- Classification workflow → Classification data access: creates and queries records
- Classification data access → PostgreSQL: queries
- Administration → Administration data access: reads and updates records
- Administration data access → PostgreSQL: queries
- Administration → Cloudflare R2: renames stored images
- Classification workflow → Model management: requests model operations
- Auth routes → Google sign-in: supports sign-in
