# kouljihate/farm-irrigation-system architecture

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

- Interactive diagram: https://gitdiagram.com/kouljihate/farm-irrigation-system
- Repository: https://github.com/kouljihate/farm-irrigation-system

## Overview

Farm Irrigation Workbench is a Flask application for designing farm irrigation layouts, with MongoDB as the documented source of truth. Users initialize a project with farm and water-source geometry, refine sectors and zones on a shared map, plan pipework and valves, lay out rows, trees, and driplines, then review hydraulic checks and export reports. The graph preserves those documented domain stages and the principal supporting layers. Several route and core relationships are based on the SOURCE INDEX or README because their implementations were not excerpted; unsupported details are omitted.

Main entry points: [`app.py`](https://github.com/kouljihate/farm-irrigation-system/blob/main/app.py) (Flask app), [`routes/field.py`](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/field.py) (Field layout), [`routes/hydrology.py`](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/hydrology.py) (Hydrology planning), [`routes/geometry.py`](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/geometry.py) (Sectors and zones)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_flask["Flask app<br/>[app.py]"]
  node_config["Design configuration<br/>[config.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_map["Shared map editor<br/>[map.js]"]
  node_api["GeoJSON API<br/>[api.py]"]
end

subgraph group_design["Farm design"]
  node_project["Project setup<br/>[project.py]"]
  node_kml["KML import<br/>[kml_io.py]"]
  node_geometry["Sectors and zones<br/>[geometry.py]"]
  node_geometry_core["Geometry operations<br/>[geometry.py]"]
  node_smart_geometry["Smart geometry<br/>[smart_geometry.py]"]
  node_async["Geometry task queue<br/>[async_tasks.py]"]
  node_field["Field layout<br/>[field.py]"]
  node_rows["Row layout<br/>[rows.py]"]
  node_trees["Tree placement<br/>[trees.py]"]
  node_driplines["Dripline layout<br/>[driplines.py]"]
end

subgraph group_engineering["Engineering"]
  node_validation["Input validation<br/>[validation.py]"]
  node_hydrology["Hydrology planning<br/>[hydrology.py]"]
  node_hydraulics["Hydraulic checks<br/>[hydraulics.py]"]
  node_piping["Pipe routing<br/>[piping.py]"]
  node_valves["Valve rules<br/>[valve_rules.py]"]
end

subgraph group_persistence["Persistence and reporting"]
  node_export["Exports and BOM<br/>[export.py]"]
  node_bom["Bill of materials<br/>[bom.py]"]
  node_queries["Read queries<br/>[queries.py]"]
  node_repository["Write repository<br/>[repository.py]"]
  node_mongo[("MongoDB")]
  node_connection["Database connection<br/>[connection.py]"]
  node_schema["Database schema<br/>[schema.py]"]
end

node_user(("Farm designer"))

node_user -->|"uses"| node_flask
node_flask -->|"registers"| node_auth
node_flask -->|"registers"| node_project
node_flask -->|"registers"| node_geometry
node_flask -->|"registers"| node_hydrology
node_flask -->|"registers"| node_field
node_flask -->|"registers"| node_export
node_flask -->|"registers"| node_api
node_project -->|"imports with"| node_kml
node_project -.->|"writes project"| node_repository
node_user -->|"edits geometry"| node_map
node_map -->|"loads and saves"| node_api
node_geometry -->|"uses"| node_smart_geometry
node_geometry -->|"uses"| node_geometry_core
node_geometry -->|"validates with"| node_validation
node_geometry -->|"dispatches tasks"| node_async
node_geometry -.->|"writes geometry"| node_repository
node_hydrology -->|"uses"| node_geometry_core
node_hydrology -->|"uses"| node_piping
node_hydrology -->|"uses"| node_valves
node_hydrology -->|"validates with"| node_validation
node_hydrology -->|"reads via"| node_queries
node_hydrology -->|"writes via"| node_repository
node_project -->|"runs checks"| node_hydraulics
node_field -->|"uses"| node_rows
node_field -->|"uses"| node_trees
node_field -->|"uses"| node_driplines
node_field -->|"validates with"| node_validation
node_field -->|"reads via"| node_queries
node_field -->|"writes via"| node_repository
node_export -->|"builds BOM"| node_bom
node_export -->|"uses"| node_geometry_core
node_export -->|"reads via"| node_queries
node_api -->|"reads via"| node_queries
node_queries -->|"gets database"| node_connection
node_repository -->|"gets database"| node_connection
node_connection -->|"connects to"| node_mongo
node_connection -->|"ensures indexes"| node_schema

click node_flask "https://github.com/kouljihate/farm-irrigation-system/blob/main/app.py"
click node_config "https://github.com/kouljihate/farm-irrigation-system/blob/main/config.py"
click node_auth "https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/auth.py"
click node_project "https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/project.py"
click node_kml "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/kml_io.py"
click node_map "https://github.com/kouljihate/farm-irrigation-system/blob/main/static/js/map.js"
click node_geometry "https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/geometry.py"
click node_geometry_core "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/geometry.py"
click node_smart_geometry "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/smart_geometry.py"
click node_async "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/async_tasks.py"
click node_validation "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/validation.py"
click node_hydrology "https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/hydrology.py"
click node_hydraulics "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/hydraulics.py"
click node_piping "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/piping.py"
click node_valves "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/valve_rules.py"
click node_field "https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/field.py"
click node_rows "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/rows.py"
click node_trees "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/trees.py"
click node_driplines "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/driplines.py"
click node_api "https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/api.py"
click node_export "https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/export.py"
click node_bom "https://github.com/kouljihate/farm-irrigation-system/blob/main/core/bom.py"
click node_queries "https://github.com/kouljihate/farm-irrigation-system/blob/main/db/queries.py"
click node_repository "https://github.com/kouljihate/farm-irrigation-system/blob/main/db/repository.py"
click node_connection "https://github.com/kouljihate/farm-irrigation-system/blob/main/db/connection.py"
click node_schema "https://github.com/kouljihate/farm-irrigation-system/blob/main/db/schema.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_flask,node_config,node_auth,node_map,node_api toneBlue
class node_project,node_kml,node_geometry,node_geometry_core,node_smart_geometry,node_async,node_field,node_rows,node_trees,node_driplines toneAmber
class node_validation,node_hydrology,node_hydraulics,node_piping,node_valves toneMint
class node_export,node_bom,node_queries,node_repository,node_mongo,node_connection,node_schema toneRose
class node_user toneIndigo
```

## Components

### Web application

- [Flask app](https://github.com/kouljihate/farm-irrigation-system/blob/main/app.py): `app.py`
- [Design configuration](https://github.com/kouljihate/farm-irrigation-system/blob/main/config.py): `config.py`
- [Authentication](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/auth.py): `routes/auth.py`
- [Shared map editor](https://github.com/kouljihate/farm-irrigation-system/blob/main/static/js/map.js): `static/js/map.js`
- [GeoJSON API](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/api.py): `routes/api.py`

### Farm design

- [Project setup](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/project.py): `routes/project.py`
- [KML import](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/kml_io.py): `core/kml_io.py`
- [Sectors and zones](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/geometry.py): `routes/geometry.py`
- [Geometry operations](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/geometry.py): `core/geometry.py`
- [Smart geometry](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/smart_geometry.py): `core/smart_geometry.py`
- [Geometry task queue](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/async_tasks.py): `core/async_tasks.py`
- [Field layout](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/field.py): `routes/field.py`
- [Row layout](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/rows.py): `core/rows.py`
- [Tree placement](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/trees.py): `core/trees.py`
- [Dripline layout](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/driplines.py): `core/driplines.py`

### Engineering

- [Input validation](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/validation.py): `core/validation.py`
- [Hydrology planning](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/hydrology.py): `routes/hydrology.py`
- [Hydraulic checks](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/hydraulics.py): `core/hydraulics.py`
- [Pipe routing](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/piping.py): `core/piping.py`
- [Valve rules](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/valve_rules.py): `core/valve_rules.py`

### Persistence and reporting

- [Exports and BOM](https://github.com/kouljihate/farm-irrigation-system/blob/main/routes/export.py): `routes/export.py`
- [Bill of materials](https://github.com/kouljihate/farm-irrigation-system/blob/main/core/bom.py): `core/bom.py`
- [Read queries](https://github.com/kouljihate/farm-irrigation-system/blob/main/db/queries.py): `db/queries.py`
- [Write repository](https://github.com/kouljihate/farm-irrigation-system/blob/main/db/repository.py): `db/repository.py`
- **MongoDB**
- [Database connection](https://github.com/kouljihate/farm-irrigation-system/blob/main/db/connection.py): `db/connection.py`
- [Database schema](https://github.com/kouljihate/farm-irrigation-system/blob/main/db/schema.py): `db/schema.py`

### Other components

- **Farm designer**

## Connections

- Farm designer → Flask app: uses (evidence: `README.md`)
- Flask app → Authentication: registers (evidence: `app.py`)
- Flask app → Project setup: registers (evidence: `app.py`)
- Flask app → Sectors and zones: registers (evidence: `app.py`)
- Flask app → Hydrology planning: registers (evidence: `app.py`)
- Flask app → Field layout: registers (evidence: `app.py`)
- Flask app → Exports and BOM: registers (evidence: `app.py`)
- Flask app → GeoJSON API: registers (evidence: `app.py`)
- Project setup → KML import: imports with (evidence: `routes/project.py`)
- Project setup → Write repository: writes project (evidence: `routes/project.py`)
- Farm designer → Shared map editor: edits geometry (evidence: `README.md`)
- Shared map editor → GeoJSON API: loads and saves (evidence: `README.md`)
- Sectors and zones → Smart geometry: uses (evidence: `routes/geometry.py`)
- Sectors and zones → Geometry operations: uses (evidence: `routes/geometry.py`)
- Sectors and zones → Input validation: validates with (evidence: `routes/geometry.py`)
- Sectors and zones → Geometry task queue: dispatches tasks (evidence: `routes/geometry.py`)
- Sectors and zones → Write repository: writes geometry (evidence: `routes/geometry.py`)
- Hydrology planning → Geometry operations: uses (evidence: `routes/hydrology.py`)
- Hydrology planning → Pipe routing: uses (evidence: `routes/hydrology.py`)
- Hydrology planning → Valve rules: uses (evidence: `routes/hydrology.py`)
- Hydrology planning → Input validation: validates with (evidence: `routes/hydrology.py`)
- Hydrology planning → Read queries: reads via (evidence: `routes/hydrology.py`)
- Hydrology planning → Write repository: writes via (evidence: `routes/hydrology.py`)
- Project setup → Hydraulic checks: runs checks (evidence: `routes/project.py`)
- Field layout → Row layout: uses (evidence: `routes/field.py`)
- Field layout → Tree placement: uses (evidence: `routes/field.py`)
- Field layout → Dripline layout: uses (evidence: `routes/field.py`)
- Field layout → Input validation: validates with (evidence: `routes/field.py`)
- Field layout → Read queries: reads via (evidence: `routes/field.py`)
- Field layout → Write repository: writes via (evidence: `routes/field.py`)
- Exports and BOM → Bill of materials: builds BOM (evidence: `routes/export.py`)
- Exports and BOM → Geometry operations: uses (evidence: `routes/export.py`)
- Exports and BOM → Read queries: reads via (evidence: `routes/export.py`)
- GeoJSON API → Read queries: reads via (evidence: `routes/api.py`)
- Read queries → Database connection: gets database (evidence: `db/queries.py`)
- Write repository → Database connection: gets database (evidence: `db/repository.py`)
- Database connection → MongoDB: connects to (evidence: `db/connection.py`)
- Database connection → Database schema: ensures indexes (evidence: `db/connection.py`)
