# diego-alonso-05/greenherb-api architecture

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

- Interactive diagram: https://gitdiagram.com/diego-alonso-05/greenherb-api
- Repository: https://github.com/diego-alonso-05/greenherb-api

## Overview

GREENHERB is a Spring REST API for herb-growing plans, environmental measurements and alerts, with JWT login and refresh tokens. The principal flow is a client creating a plan, submitting a measurement, and retrieving or resolving generated alerts; measurement handling compares conditions with the active plan and may send notifications. Herb catalog CRUD/CSV import and audit logging are additional implemented capabilities. The README identifies herbs and audit as present, though its scope note is inconsistent; edges are limited to relationships supported by excerpts, the source index, or README.

Main entry points: [`src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java`](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java) (Measurement processing), [`src/main/java/com/greenherb/greenherb_api/service/AuthService.java`](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/AuthService.java) (Login service), [`src/main/java/com/greenherb/greenherb_api/service/HerbService.java`](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/HerbService.java) (Herb catalog service), [`src/main/java/com/greenherb/greenherb_api/controller/AuthController.java`](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/AuthController.java) (Authentication API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and security"]
  node_authapi["Authentication API"]
  node_auth["Login service<br/>[AuthService.java]"]
  node_jwt["JWT service<br/>[JwtService.java]"]
  node_refresh["Refresh tokens"]
  node_jwtfilter["JWT request filter<br/>[JwtAuthFilter.java]"]
  node_securityconfig["Security configuration"]
  node_userrepo[("User repository")]
  node_tokenrepo[("Refresh token repository")]
end

subgraph group_growing["Growing operations"]
  node_plansapi["Plans API"]
  node_plans["Plan rules<br/>[PlanService.java]"]
  node_planrepo[("Plan repository")]
end

subgraph group_signals["Measurements and alerts"]
  node_measureapi["Measurements API"]
  node_measurement["Measurement processing"]
  node_measurementrepo[("Measurement repository")]
  node_alertapi["Alerts API"]
  node_alertservice["Alert handling<br/>[AlertService.java]"]
  node_alertrepo[("Alert repository")]
  node_temp["Temperature gateway"]
  node_notify["Notification gateway"]
end

subgraph group_catalog["Herb catalog and audit"]
  node_herbapi["Herbs API"]
  node_herbservice["Herb catalog service<br/>[HerbService.java]"]
  node_herbrepo[("Herb repository")]
  node_auditapi["Audit API"]
  node_auditrepo[("Audit repository")]
end

node_client(("API client"))

node_client -->|"logs in"| node_authapi
node_authapi -->|"delegates login"| node_auth
node_auth -->|"looks up user"| node_userrepo
node_auth -->|"creates access token"| node_jwt
node_auth -->|"creates refresh token"| node_refresh
node_refresh -->|"stores token"| node_tokenrepo
node_jwtfilter -->|"validates token"| node_jwt
node_securityconfig -.->|"registers filter"| node_jwtfilter
node_client -->|"manages plans"| node_plansapi
node_plansapi -->|"delegates"| node_plans
node_plans -->|"validates and persists"| node_planrepo
node_client -->|"submits measurement"| node_measureapi
node_measureapi -->|"delegates"| node_measurement
node_measurement -->|"saves reading"| node_measurementrepo
node_measurement -->|"reads active plan"| node_planrepo
node_measurement -->|"checks and saves alerts"| node_alertrepo
node_measurement -->|"sends alert notice"| node_notify
node_measurement -.->|"optional integration"| node_temp
node_client -->|"queries or resolves"| node_alertapi
node_alertapi -->|"delegates"| node_alertservice
node_alertservice -->|"reads and updates"| node_alertrepo
node_client -.->|"manages herb catalog"| node_herbapi
node_herbapi -->|"delegates"| node_herbservice
node_herbservice -->|"imports and persists"| node_herbrepo
node_herbservice -->|"writes audit records"| node_auditrepo
node_client -.->|"requests audit"| node_auditapi
node_auditapi -->|"queries logs"| node_auditrepo

click node_authapi "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/AuthController.java"
click node_auth "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/AuthService.java"
click node_jwt "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/security/JwtService.java"
click node_refresh "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/RefreshTokenService.java"
click node_jwtfilter "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/security/JwtAuthFilter.java"
click node_securityconfig "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/config/SecurityConfig.java"
click node_userrepo "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/UserRepository.java"
click node_tokenrepo "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/RefreshTokenRepository.java"
click node_plansapi "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/PlanController.java"
click node_plans "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/PlanService.java"
click node_planrepo "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/PlanRepository.java"
click node_measureapi "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/MeasurementController.java"
click node_measurement "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java"
click node_measurementrepo "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/MeasurementRepository.java"
click node_alertapi "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/AlertController.java"
click node_alertservice "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/AlertService.java"
click node_alertrepo "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/AlertRepository.java"
click node_temp "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/gateway/TemperatureGateway.java"
click node_notify "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/gateway/NotificationGateway.java"
click node_herbapi "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/HerbController.java"
click node_herbservice "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/HerbService.java"
click node_herbrepo "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/HerbRepository.java"
click node_auditapi "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/AuditController.java"
click node_auditrepo "https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/AuditLogRepository.java"

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_authapi,node_auth,node_jwt,node_refresh,node_jwtfilter,node_securityconfig,node_userrepo,node_tokenrepo,node_client toneBlue
class node_plansapi,node_plans,node_planrepo toneAmber
class node_measureapi,node_measurement,node_measurementrepo,node_alertapi,node_alertservice,node_alertrepo,node_temp,node_notify toneMint
class node_herbapi,node_herbservice,node_herbrepo,node_auditapi,node_auditrepo toneRose
```

## Components

### Access and security

- [Authentication API](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/AuthController.java): `src/main/java/com/greenherb/greenherb_api/controller/AuthController.java`
- [Login service](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/AuthService.java): `src/main/java/com/greenherb/greenherb_api/service/AuthService.java`
- [JWT service](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/security/JwtService.java): `src/main/java/com/greenherb/greenherb_api/security/JwtService.java`
- [Refresh tokens](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/RefreshTokenService.java): `src/main/java/com/greenherb/greenherb_api/service/RefreshTokenService.java`
- [JWT request filter](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/security/JwtAuthFilter.java): `src/main/java/com/greenherb/greenherb_api/security/JwtAuthFilter.java`
- [Security configuration](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/config/SecurityConfig.java): `src/main/java/com/greenherb/greenherb_api/config/SecurityConfig.java`
- [User repository](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/UserRepository.java): `src/main/java/com/greenherb/greenherb_api/repository/UserRepository.java`
- [Refresh token repository](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/RefreshTokenRepository.java): `src/main/java/com/greenherb/greenherb_api/repository/RefreshTokenRepository.java`

### Growing operations

- [Plans API](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/PlanController.java): `src/main/java/com/greenherb/greenherb_api/controller/PlanController.java`
- [Plan rules](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/PlanService.java): `src/main/java/com/greenherb/greenherb_api/service/PlanService.java`
- [Plan repository](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/PlanRepository.java): `src/main/java/com/greenherb/greenherb_api/repository/PlanRepository.java`

### Measurements and alerts

- [Measurements API](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/MeasurementController.java): `src/main/java/com/greenherb/greenherb_api/controller/MeasurementController.java`
- [Measurement processing](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java): `src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java`
- [Measurement repository](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/MeasurementRepository.java): `src/main/java/com/greenherb/greenherb_api/repository/MeasurementRepository.java`
- [Alerts API](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/AlertController.java): `src/main/java/com/greenherb/greenherb_api/controller/AlertController.java`
- [Alert handling](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/AlertService.java): `src/main/java/com/greenherb/greenherb_api/service/AlertService.java`
- [Alert repository](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/AlertRepository.java): `src/main/java/com/greenherb/greenherb_api/repository/AlertRepository.java`
- [Temperature gateway](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/gateway/TemperatureGateway.java): `src/main/java/com/greenherb/greenherb_api/gateway/TemperatureGateway.java`
- [Notification gateway](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/gateway/NotificationGateway.java): `src/main/java/com/greenherb/greenherb_api/gateway/NotificationGateway.java`

### Herb catalog and audit

- [Herbs API](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/HerbController.java): `src/main/java/com/greenherb/greenherb_api/controller/HerbController.java`
- [Herb catalog service](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/service/HerbService.java): `src/main/java/com/greenherb/greenherb_api/service/HerbService.java`
- [Herb repository](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/HerbRepository.java): `src/main/java/com/greenherb/greenherb_api/repository/HerbRepository.java`
- [Audit API](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/controller/AuditController.java): `src/main/java/com/greenherb/greenherb_api/controller/AuditController.java`
- [Audit repository](https://github.com/diego-alonso-05/greenherb-api/blob/main/src/main/java/com/greenherb/greenherb_api/repository/AuditLogRepository.java): `src/main/java/com/greenherb/greenherb_api/repository/AuditLogRepository.java`

### Other components

- **API client**

## Connections

- API client → Authentication API: logs in
- Authentication API → Login service: delegates login (evidence: `src/main/java/com/greenherb/greenherb_api/controller/AuthController.java`)
- Login service → User repository: looks up user (evidence: `src/main/java/com/greenherb/greenherb_api/service/AuthService.java`)
- Login service → JWT service: creates access token (evidence: `src/main/java/com/greenherb/greenherb_api/service/AuthService.java`)
- Login service → Refresh tokens: creates refresh token (evidence: `src/main/java/com/greenherb/greenherb_api/service/AuthService.java`)
- Refresh tokens → Refresh token repository: stores token (evidence: `src/main/java/com/greenherb/greenherb_api/service/RefreshTokenService.java`)
- JWT request filter → JWT service: validates token (evidence: `src/main/java/com/greenherb/greenherb_api/security/JwtAuthFilter.java`)
- Security configuration → JWT request filter: registers filter
- API client → Plans API: manages plans
- Plans API → Plan rules: delegates (evidence: `src/main/java/com/greenherb/greenherb_api/controller/PlanController.java`)
- Plan rules → Plan repository: validates and persists (evidence: `src/main/java/com/greenherb/greenherb_api/service/PlanService.java`)
- API client → Measurements API: submits measurement
- Measurements API → Measurement processing: delegates (evidence: `src/main/java/com/greenherb/greenherb_api/controller/MeasurementController.java`)
- Measurement processing → Measurement repository: saves reading (evidence: `src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java`)
- Measurement processing → Plan repository: reads active plan (evidence: `src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java`)
- Measurement processing → Alert repository: checks and saves alerts (evidence: `src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java`)
- Measurement processing → Notification gateway: sends alert notice (evidence: `src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java`)
- Measurement processing → Temperature gateway: optional integration (evidence: `src/main/java/com/greenherb/greenherb_api/service/MeasurementService.java`)
- API client → Alerts API: queries or resolves
- Alerts API → Alert handling: delegates (evidence: `src/main/java/com/greenherb/greenherb_api/controller/AlertController.java`)
- Alert handling → Alert repository: reads and updates (evidence: `src/main/java/com/greenherb/greenherb_api/service/AlertService.java`)
- API client → Herbs API: manages herb catalog
- Herbs API → Herb catalog service: delegates (evidence: `src/main/java/com/greenherb/greenherb_api/controller/HerbController.java`)
- Herb catalog service → Herb repository: imports and persists (evidence: `src/main/java/com/greenherb/greenherb_api/service/HerbService.java`)
- Herb catalog service → Audit repository: writes audit records (evidence: `src/main/java/com/greenherb/greenherb_api/service/HerbService.java`)
- API client → Audit API: requests audit
- Audit API → Audit repository: queries logs (evidence: `src/main/java/com/greenherb/greenherb_api/controller/AuditController.java`)
