# edilson-nantes/brain-agriculture architecture

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

- Interactive diagram: https://gitdiagram.com/edilson-nantes/brain-agriculture
- Repository: https://github.com/edilson-nantes/brain-agriculture

## Overview

Brain Agriculture API is a NestJS service for managing farmers, their farms, and farm harvests, with a dashboard for aggregate analysis. The main workflow is an HTTP request handled by a domain controller, delegated to a service for validation and persistence, and returned as domain data. Farmer-to-farm and farm-to-harvest relationships are represented in the entities; creating farms and harvests also checks the parent record. PostgreSQL is configured through TypeORM. Some module wiring and dashboard routes are supported by the README or source index rather than sampled implementation excerpts.

Main entry points: [`src/app.module.ts`](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/app.module.ts) (Nest application), [`src/farm/farm.service.ts`](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farm/farm.service.ts) (Farm service), [`src/harvest/harvest.service.ts`](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/harvest/harvest.service.ts) (Harvest service), [`src/farmer/farmer.controller.ts`](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farmer/farmer.controller.ts) (Farmer API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Application runtime"]
  node_app["Nest application<br/>[app.module.ts]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_land["Farmers and farms"]
  node_farmer_api["Farmer API"]
  node_farmer_service["Farmer service<br/>[farmer.service.ts]"]
  node_farmer_entity["Farmer record<br/>[farmer.entity.ts]"]
  node_farmer_validation["Farmer validation"]
  node_farmer_dto["Farmer DTOs"]
  node_farm_api["Farm API<br/>[farm.controller.ts]"]
  node_farm_service["Farm service<br/>[farm.service.ts]"]
  node_farm_entity["Farm record<br/>[farm.entity.ts]"]
  node_farm_validation["Farm area checks"]
  node_farm_dto["Farm DTOs"]
end

subgraph group_harvest["Harvest management"]
  node_harvest_api["Harvest API"]
  node_harvest_service["Harvest service<br/>[harvest.service.ts]"]
  node_harvest_entity["Harvest record<br/>[harvest.entity.ts]"]
  node_harvest_validation["Harvest area checks"]
  node_harvest_dto["Harvest DTOs"]
end

subgraph group_analytics["Dashboard analytics"]
  node_dashboard_api["Dashboard API"]
  node_dashboard_service["Dashboard queries"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"configures TypeORM"| node_postgres
node_app -->|"registers module"| node_farmer_api
node_app -->|"registers module"| node_farm_api
node_app -->|"registers module"| node_harvest_api
node_app -->|"registers module"| node_dashboard_api
node_client -->|"calls endpoints"| node_farmer_api
node_farmer_api -->|"delegates requests"| node_farmer_service
node_farmer_service -->|"persists records"| node_farmer_entity
node_farmer_service -->|"validates identifier"| node_farmer_validation
node_farmer_api -->|"accepts and returns"| node_farmer_dto
node_client -->|"calls endpoints"| node_farm_api
node_farm_api -->|"delegates requests"| node_farm_service
node_farm_service -->|"persists records"| node_farm_entity
node_farm_service -->|"checks farmer"| node_farmer_service
node_farm_service -->|"checks land area"| node_farm_validation
node_farm_api -->|"accepts and returns"| node_farm_dto
node_client -->|"calls endpoints"| node_harvest_api
node_harvest_api -->|"delegates requests"| node_harvest_service
node_harvest_service -->|"persists records"| node_harvest_entity
node_harvest_service -->|"checks parent farm"| node_farm_service
node_harvest_service -->|"checks cultivated area"| node_harvest_validation
node_harvest_api -->|"accepts and returns"| node_harvest_dto
node_client -->|"requests summary"| node_dashboard_api
node_dashboard_api -->|"delegates query"| node_dashboard_service
node_dashboard_service -->|"aggregates farm data"| node_farm_entity
node_farmer_entity -->|"relates to farms"| node_farm_entity
node_farm_entity -->|"relates to harvests"| node_harvest_entity

click node_app "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/app.module.ts"
click node_farmer_api "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farmer/farmer.controller.ts"
click node_farmer_service "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farmer/farmer.service.ts"
click node_farmer_entity "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farmer/entities/farmer.entity.ts"
click node_farmer_validation "https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farmer/validators"
click node_farmer_dto "https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farmer/dtos"
click node_farm_api "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farm/farm.controller.ts"
click node_farm_service "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farm/farm.service.ts"
click node_farm_entity "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farm/entities/farm.entity.ts"
click node_farm_validation "https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farm/validators"
click node_farm_dto "https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farm/dtos"
click node_harvest_api "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/harvest/harvest.controller.ts"
click node_harvest_service "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/harvest/harvest.service.ts"
click node_harvest_entity "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/harvest/entities/harvest.entity.ts"
click node_harvest_validation "https://github.com/edilson-nantes/brain-agriculture/tree/main/src/harvest/validators"
click node_harvest_dto "https://github.com/edilson-nantes/brain-agriculture/tree/main/src/harvest/dtos"
click node_dashboard_api "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/dashboard/dashboard.controller.ts"
click node_dashboard_service "https://github.com/edilson-nantes/brain-agriculture/blob/main/src/dashboard/dashboard.service.ts"

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_app,node_postgres,node_client toneBlue
class node_farmer_api,node_farmer_service,node_farmer_entity,node_farmer_validation,node_farmer_dto,node_farm_api,node_farm_service,node_farm_entity,node_farm_validation,node_farm_dto toneAmber
class node_harvest_api,node_harvest_service,node_harvest_entity,node_harvest_validation,node_harvest_dto toneMint
class node_dashboard_api,node_dashboard_service toneRose
```

## Components

### Application runtime

- [Nest application](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/app.module.ts): `src/app.module.ts`
- **PostgreSQL**

### Farmers and farms

- [Farmer API](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farmer/farmer.controller.ts): `src/farmer/farmer.controller.ts`
- [Farmer service](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farmer/farmer.service.ts): `src/farmer/farmer.service.ts`
- [Farmer record](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farmer/entities/farmer.entity.ts): `src/farmer/entities/farmer.entity.ts`
- [Farmer validation](https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farmer/validators): `src/farmer/validators`
- [Farmer DTOs](https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farmer/dtos): `src/farmer/dtos`
- [Farm API](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farm/farm.controller.ts): `src/farm/farm.controller.ts`
- [Farm service](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farm/farm.service.ts): `src/farm/farm.service.ts`
- [Farm record](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/farm/entities/farm.entity.ts): `src/farm/entities/farm.entity.ts`
- [Farm area checks](https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farm/validators): `src/farm/validators`
- [Farm DTOs](https://github.com/edilson-nantes/brain-agriculture/tree/main/src/farm/dtos): `src/farm/dtos`

### Harvest management

- [Harvest API](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/harvest/harvest.controller.ts): `src/harvest/harvest.controller.ts`
- [Harvest service](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/harvest/harvest.service.ts): `src/harvest/harvest.service.ts`
- [Harvest record](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/harvest/entities/harvest.entity.ts): `src/harvest/entities/harvest.entity.ts`
- [Harvest area checks](https://github.com/edilson-nantes/brain-agriculture/tree/main/src/harvest/validators): `src/harvest/validators`
- [Harvest DTOs](https://github.com/edilson-nantes/brain-agriculture/tree/main/src/harvest/dtos): `src/harvest/dtos`

### Dashboard analytics

- [Dashboard API](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/dashboard/dashboard.controller.ts): `src/dashboard/dashboard.controller.ts`
- [Dashboard queries](https://github.com/edilson-nantes/brain-agriculture/blob/main/src/dashboard/dashboard.service.ts): `src/dashboard/dashboard.service.ts`

### Other components

- **API client**

## Connections

- API client → Nest application: sends requests (evidence: `README.md`)
- Nest application → PostgreSQL: configures TypeORM (evidence: `src/app.module.ts`)
- Nest application → Farmer API: registers module (evidence: `src/app.module.ts`)
- Nest application → Farm API: registers module (evidence: `src/app.module.ts`)
- Nest application → Harvest API: registers module (evidence: `src/app.module.ts`)
- Nest application → Dashboard API: registers module (evidence: `src/app.module.ts`)
- API client → Farmer API: calls endpoints (evidence: `README.md`)
- Farmer API → Farmer service: delegates requests (evidence: `src/farmer/farmer.controller.ts`)
- Farmer service → Farmer record: persists records (evidence: `src/farmer/farmer.service.ts`)
- Farmer service → Farmer validation: validates identifier (evidence: `src/farmer/farmer.service.ts`)
- Farmer API → Farmer DTOs: accepts and returns (evidence: `src/farmer/farmer.controller.ts`)
- API client → Farm API: calls endpoints (evidence: `README.md`)
- Farm API → Farm service: delegates requests (evidence: `src/farm/farm.controller.ts`)
- Farm service → Farm record: persists records (evidence: `src/farm/farm.service.ts`)
- Farm service → Farmer service: checks farmer (evidence: `src/farm/farm.service.ts`)
- Farm service → Farm area checks: checks land area (evidence: `src/farm/farm.service.ts`)
- Farm API → Farm DTOs: accepts and returns (evidence: `src/farm/farm.controller.ts`)
- API client → Harvest API: calls endpoints (evidence: `README.md`)
- Harvest API → Harvest service: delegates requests (evidence: `src/harvest/harvest.controller.ts`)
- Harvest service → Harvest record: persists records (evidence: `src/harvest/harvest.service.ts`)
- Harvest service → Farm service: checks parent farm (evidence: `src/harvest/harvest.service.ts`)
- Harvest service → Harvest area checks: checks cultivated area (evidence: `src/harvest/harvest.service.ts`)
- Harvest API → Harvest DTOs: accepts and returns (evidence: `src/harvest/harvest.controller.ts`)
- API client → Dashboard API: requests summary (evidence: `README.md`)
- Dashboard API → Dashboard queries: delegates query (evidence: `src/dashboard/dashboard.controller.ts`)
- Dashboard queries → Farm record: aggregates farm data (evidence: `src/dashboard/dashboard.service.ts`)
- Farmer record → Farm record: relates to farms (evidence: `src/farmer/entities/farmer.entity.ts`)
- Farm record → Harvest record: relates to harvests (evidence: `src/farm/entities/farm.entity.ts`)
