# nas0703/ipds-4.2.1 architecture

> Architecture diagram of the GitHub repository nas0703/ipds-4.2.1, 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/nas0703/ipds-4.2.1
- Repository: https://github.com/nas0703/ipds-4.2.1

## Overview

This is a multi-estate plantation operations platform: users work in a browser app to record and review estate activity, with a server API, Supabase-backed state, and AI-assisted knowledge features. Its domain areas include harvest and receipt capture, rainfall, grading, fertilizer, weeding, pruning, employees, and reporting. The sampled sources establish the app shell, authentication, transaction/OCR handling, and RAG flow; most other feature connections are based only on the repository tree and are therefore omitted rather than asserted.

Main entry points: [`src/App.tsx`](https://github.com/nas0703/ipds-4.2.1/blob/main/src/App.tsx) (Application shell), [`src/server/routes/ai/rag.routes.ts`](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/routes/ai/rag.routes.ts) (Knowledge API), [`src/server/services/ragEngine.service.ts`](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/services/ragEngine.service.ts) (Grounded RAG), [`src/server/db.ts`](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/db.ts) (Supabase access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Web application"]
  node_app["Application shell<br/>[App.tsx]"]
  node_estate["Estate context<br/>[estateContext.ts]"]
  node_registry["Estate registry<br/>[estateRegistry.ts]"]
end

subgraph group_identity["Identity and access"]
  node_auth_ui["Sign-in state<br/>[useAuth.ts]"]
  node_rbac["Role permissions<br/>[rbacService.ts]"]
  node_auth_api["API authentication<br/>[auth.ts]"]
end

subgraph group_operations["Estate operations"]
  node_transactions["Harvest records"]
  node_ocr["Receipt OCR<br/>[ocrService.ts]"]
  node_rainfall["Rainfall records<br/>[useRainfallData.ts]"]
  node_grading["Fruit grading"]
  node_fertilizer["Fertilizer operations"]
  node_weeding["Weeding operations<br/>[MerumputModule.tsx]"]
  node_pruning["Pruning operations<br/>[PruningModule.tsx]"]
  node_employees["Employee management"]
end

subgraph group_insights["Reporting and insights"]
  node_dashboard["Estate dashboard<br/>[DashboardTab.tsx]"]
  node_hasil["Harvest analytics"]
  node_exports["Report exports"]
end

subgraph group_backend["API and AI services"]
  node_api["HTTP server<br/>[server.ts]"]
  node_rag_routes["Knowledge API<br/>[rag.routes.ts]"]
  node_rag_engine["Grounded RAG"]
  node_knowledge["Manual knowledge"]
  node_ingestion["PDF ingestion"]
  node_db[("Supabase access<br/>[db.ts]")]
end

node_user(("Estate user"))
node_supabase[("Supabase service")]

node_user -->|"uses"| node_app
node_app -->|"loads auth"| node_auth_ui
node_app -->|"resolves estate"| node_estate
node_estate -->|"resolves config"| node_registry
node_auth_ui -->|"checks roles"| node_rbac
node_auth_ui -->|"requests session"| node_api
node_app -->|"loads state"| node_transactions
node_transactions -->|"parses receipt"| node_ocr
node_api -->|"configures access"| node_db
node_api -->|"mounts routes"| node_rag_routes
node_rag_routes -->|"authenticates"| node_auth_api
node_rag_routes -->|"generates answer"| node_rag_engine
node_rag_routes -->|"ingests documents"| node_ingestion
node_rag_engine -->|"retrieves chunks"| node_knowledge
node_ingestion -->|"generates embeddings"| node_rag_engine
node_rag_engine -->|"queries knowledge"| node_db
node_knowledge -->|"loads knowledge"| node_db
node_db -.->|"connects"| node_supabase

click node_app "https://github.com/nas0703/ipds-4.2.1/blob/main/src/App.tsx"
click node_estate "https://github.com/nas0703/ipds-4.2.1/blob/main/src/utils/estateContext.ts"
click node_registry "https://github.com/nas0703/ipds-4.2.1/blob/main/src/config/estateRegistry.ts"
click node_auth_ui "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/auth/hooks/useAuth.ts"
click node_rbac "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/auth/services/rbacService.ts"
click node_auth_api "https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/middleware/auth.ts"
click node_transactions "https://github.com/nas0703/ipds-4.2.1/blob/main/src/hooks/useTransactionState.ts"
click node_ocr "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/input/services/ocrService.ts"
click node_rainfall "https://github.com/nas0703/ipds-4.2.1/blob/main/src/hooks/useRainfallData.ts"
click node_grading "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/kualiti/services/penggredanService.ts"
click node_fertilizer "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/fertilizer/FertilizerModule.tsx"
click node_weeding "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/merumput/MerumputModule.tsx"
click node_pruning "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/pruning/PruningModule.tsx"
click node_employees "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/pekerja/services/employeeMasterService.ts"
click node_dashboard "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/dashboard/components/DashboardTab.tsx"
click node_hasil "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/hasil/hooks/useHasilAnalytics.ts"
click node_exports "https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/export/services/excelExportService.ts"
click node_api "https://github.com/nas0703/ipds-4.2.1/blob/main/server.ts"
click node_rag_routes "https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/routes/ai/rag.routes.ts"
click node_rag_engine "https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/services/ragEngine.service.ts"
click node_knowledge "https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/services/mslKnowledge.service.ts"
click node_ingestion "https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/services/pdfIngestion.service.ts"
click node_db "https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/db.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_estate,node_registry,node_user toneBlue
class node_auth_ui,node_rbac,node_auth_api,node_supabase toneAmber
class node_transactions,node_ocr,node_rainfall,node_grading,node_fertilizer,node_weeding,node_pruning,node_employees toneMint
class node_dashboard,node_hasil,node_exports toneRose
class node_api,node_rag_routes,node_rag_engine,node_knowledge,node_ingestion,node_db toneIndigo
```

## Components

### Web application

- [Application shell](https://github.com/nas0703/ipds-4.2.1/blob/main/src/App.tsx): `src/App.tsx`
- [Estate context](https://github.com/nas0703/ipds-4.2.1/blob/main/src/utils/estateContext.ts): `src/utils/estateContext.ts`
- [Estate registry](https://github.com/nas0703/ipds-4.2.1/blob/main/src/config/estateRegistry.ts): `src/config/estateRegistry.ts`

### Identity and access

- [Sign-in state](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/auth/hooks/useAuth.ts): `src/features/auth/hooks/useAuth.ts`
- [Role permissions](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/auth/services/rbacService.ts): `src/features/auth/services/rbacService.ts`
- [API authentication](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/middleware/auth.ts): `src/server/middleware/auth.ts`

### Estate operations

- [Harvest records](https://github.com/nas0703/ipds-4.2.1/blob/main/src/hooks/useTransactionState.ts): `src/hooks/useTransactionState.ts`
- [Receipt OCR](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/input/services/ocrService.ts): `src/features/input/services/ocrService.ts`
- [Rainfall records](https://github.com/nas0703/ipds-4.2.1/blob/main/src/hooks/useRainfallData.ts): `src/hooks/useRainfallData.ts`
- [Fruit grading](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/kualiti/services/penggredanService.ts): `src/features/kualiti/services/penggredanService.ts`
- [Fertilizer operations](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/fertilizer/FertilizerModule.tsx): `src/features/fertilizer/FertilizerModule.tsx`
- [Weeding operations](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/merumput/MerumputModule.tsx): `src/features/merumput/MerumputModule.tsx`
- [Pruning operations](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/pruning/PruningModule.tsx): `src/features/pruning/PruningModule.tsx`
- [Employee management](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/pekerja/services/employeeMasterService.ts): `src/features/pekerja/services/employeeMasterService.ts`

### Reporting and insights

- [Estate dashboard](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/dashboard/components/DashboardTab.tsx): `src/features/dashboard/components/DashboardTab.tsx`
- [Harvest analytics](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/hasil/hooks/useHasilAnalytics.ts): `src/features/hasil/hooks/useHasilAnalytics.ts`
- [Report exports](https://github.com/nas0703/ipds-4.2.1/blob/main/src/features/export/services/excelExportService.ts): `src/features/export/services/excelExportService.ts`

### API and AI services

- [HTTP server](https://github.com/nas0703/ipds-4.2.1/blob/main/server.ts): `server.ts`
- [Knowledge API](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/routes/ai/rag.routes.ts): `src/server/routes/ai/rag.routes.ts`
- [Grounded RAG](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/services/ragEngine.service.ts): `src/server/services/ragEngine.service.ts`
- [Manual knowledge](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/services/mslKnowledge.service.ts): `src/server/services/mslKnowledge.service.ts`
- [PDF ingestion](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/services/pdfIngestion.service.ts): `src/server/services/pdfIngestion.service.ts`
- [Supabase access](https://github.com/nas0703/ipds-4.2.1/blob/main/src/server/db.ts): `src/server/db.ts`

### Other components

- **Estate user**
- **Supabase service**

## Connections

- Estate user → Application shell: uses (evidence: `src/App.tsx`)
- Application shell → Sign-in state: loads auth (evidence: `src/App.tsx`)
- Application shell → Estate context: resolves estate (evidence: `src/App.tsx`)
- Estate context → Estate registry: resolves config (evidence: `src/utils/estateContext.ts`)
- Sign-in state → Role permissions: checks roles (evidence: `src/features/auth/hooks/useAuth.ts`)
- Sign-in state → HTTP server: requests session (evidence: `src/features/auth/hooks/useAuth.ts`)
- Application shell → Harvest records: loads state (evidence: `src/App.tsx`)
- Harvest records → Receipt OCR: parses receipt (evidence: `src/hooks/useTransactionState.ts`)
- HTTP server → Supabase access: configures access (evidence: `server.ts`)
- HTTP server → Knowledge API: mounts routes (evidence: `server.ts`)
- Knowledge API → API authentication: authenticates (evidence: `src/server/routes/ai/rag.routes.ts`)
- Knowledge API → Grounded RAG: generates answer (evidence: `src/server/routes/ai/rag.routes.ts`)
- Knowledge API → PDF ingestion: ingests documents (evidence: `src/server/routes/ai/rag.routes.ts`)
- Grounded RAG → Manual knowledge: retrieves chunks (evidence: `src/server/services/ragEngine.service.ts`)
- PDF ingestion → Grounded RAG: generates embeddings (evidence: `src/server/services/pdfIngestion.service.ts`)
- Grounded RAG → Supabase access: queries knowledge (evidence: `src/server/services/ragEngine.service.ts`)
- Manual knowledge → Supabase access: loads knowledge (evidence: `src/server/services/mslKnowledge.service.ts`)
- Supabase access → Supabase service: connects
