# salimbd71/bh_agrof architecture

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

- Interactive diagram: https://gitdiagram.com/salimbd71/bh_agrof
- Repository: https://github.com/salimbd71/bh_agrof

## Overview

BH Agro is an animal-health ERP delivered as SR and Admin sites sharing code and a Firebase database. Users sign in, navigate role-appropriate views, and work with customers, products, orders, stock, collections, and reports; order pricing and inventory rules support booking and invoice preview. The sampled entry point explicitly renders shared UI and collections, while the source index identifies its broader module dependencies. Several workflow links are therefore shown as unverified; unsampled module internals are not inferred.

Main entry points: [`src/main.ts`](https://github.com/salimbd71/bh_agrof/blob/main/src/main.ts) (Application entry), [`src/modules/store.ts`](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/store.ts) (ERP state and sync), [`src/modules/orderPreview.ts`](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/orderPreview.ts) (Order preview), [`src/modules/pricing.ts`](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/pricing.ts) (Pricing engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App shell"]
  node_app["Application entry<br/>[main.ts]"]
  node_mode["Site rules<br/>[appMode.ts]"]
  node_router["Browser routing<br/>[router.ts]"]
  node_ui["Shared UI<br/>[ui.ts]"]
end

subgraph group_sales["Sales operations"]
  node_customers["Customer records<br/>[customers.ts]"]
  node_orders["Order booking<br/>[orders.ts]"]
  node_preview["Order preview<br/>[orderPreview.ts]"]
  node_invoice["Invoice generation<br/>[invoice.ts]"]
  node_collections["Collections<br/>[collections.ts]"]
end

subgraph group_admin["Admin operations"]
  node_products["Product inventory<br/>[products.ts]"]
  node_stock["Stock management<br/>[stock.ts]"]
  node_depots["Depot management<br/>[depots.ts]"]
  node_reports["Reports<br/>[reports.ts]"]
  node_targets["Sales targets<br/>[targets.ts]"]
end

subgraph group_core["Shared services"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_pricing["Pricing engine<br/>[pricing.ts]"]
  node_store[("ERP state and sync<br/>[store.ts]")]
  node_firebase_config["Firebase configuration<br/>[firebase.ts]"]
end

node_user(("SR / Admin user"))
node_firebase[("Firebase Realtime Database")]

node_user -->|"uses"| node_app
node_app -->|"renders"| node_ui
node_app -->|"renders dashboard"| node_collections
node_app -.->|"reads site rules"| node_mode
node_app -.->|"uses navigation"| node_router
node_app -.->|"uses sign-in"| node_auth
node_app -.->|"uses customer views"| node_customers
node_app -.->|"uses order views"| node_orders
node_app -.->|"uses product views"| node_products
node_app -.->|"uses reports"| node_reports
node_app -.->|"uses stock views"| node_stock
node_app -.->|"uses depot views"| node_depots
node_app -.->|"uses target views"| node_targets
node_app -.->|"opens preview"| node_preview
node_auth -->|"uses state"| node_store
node_auth -->|"uses UI"| node_ui
node_orders -->|"calculates prices"| node_pricing
node_orders -->|"uses state"| node_store
node_products -->|"uses pricing"| node_pricing
node_products -->|"uses state"| node_store
node_reports -->|"reads state"| node_store
node_preview -->|"builds and exports"| node_invoice
node_preview -->|"calculates quantities"| node_pricing
node_preview -->|"reads and confirms"| node_store
node_preview -->|"shows feedback"| node_ui
node_store -->|"uses calculations"| node_pricing
node_store -->|"loads configuration"| node_firebase_config
node_store -.->|"syncs data"| node_firebase

click node_app "https://github.com/salimbd71/bh_agrof/blob/main/src/main.ts"
click node_mode "https://github.com/salimbd71/bh_agrof/blob/main/src/config/appMode.ts"
click node_router "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/router.ts"
click node_ui "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/ui.ts"
click node_auth "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/auth.ts"
click node_customers "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/customers.ts"
click node_orders "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/orders.ts"
click node_preview "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/orderPreview.ts"
click node_invoice "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/invoice.ts"
click node_pricing "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/pricing.ts"
click node_products "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/products.ts"
click node_stock "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/stock.ts"
click node_depots "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/depots.ts"
click node_collections "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/collections.ts"
click node_reports "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/reports.ts"
click node_targets "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/targets.ts"
click node_store "https://github.com/salimbd71/bh_agrof/blob/main/src/modules/store.ts"
click node_firebase_config "https://github.com/salimbd71/bh_agrof/blob/main/src/config/firebase.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_mode,node_router,node_ui,node_user toneBlue
class node_customers,node_orders,node_preview,node_invoice,node_collections,node_firebase toneAmber
class node_products,node_stock,node_depots,node_reports,node_targets toneMint
class node_auth,node_pricing,node_store,node_firebase_config toneRose
```

## Components

### App shell

- [Application entry](https://github.com/salimbd71/bh_agrof/blob/main/src/main.ts): `src/main.ts`
- [Site rules](https://github.com/salimbd71/bh_agrof/blob/main/src/config/appMode.ts): `src/config/appMode.ts`
- [Browser routing](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/router.ts): `src/modules/router.ts`
- [Shared UI](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/ui.ts): `src/modules/ui.ts`

### Sales operations

- [Customer records](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/customers.ts): `src/modules/customers.ts`
- [Order booking](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/orders.ts): `src/modules/orders.ts`
- [Order preview](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/orderPreview.ts): `src/modules/orderPreview.ts`
- [Invoice generation](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/invoice.ts): `src/modules/invoice.ts`
- [Collections](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/collections.ts): `src/modules/collections.ts`

### Admin operations

- [Product inventory](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/products.ts): `src/modules/products.ts`
- [Stock management](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/stock.ts): `src/modules/stock.ts`
- [Depot management](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/depots.ts): `src/modules/depots.ts`
- [Reports](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/reports.ts): `src/modules/reports.ts`
- [Sales targets](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/targets.ts): `src/modules/targets.ts`

### Shared services

- [Authentication](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/auth.ts): `src/modules/auth.ts`
- [Pricing engine](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/pricing.ts): `src/modules/pricing.ts`
- [ERP state and sync](https://github.com/salimbd71/bh_agrof/blob/main/src/modules/store.ts): `src/modules/store.ts`
- [Firebase configuration](https://github.com/salimbd71/bh_agrof/blob/main/src/config/firebase.ts): `src/config/firebase.ts`

### Other components

- **SR / Admin user**
- **Firebase Realtime Database**

## Connections

- SR / Admin user → Application entry: uses
- Application entry → Shared UI: renders (evidence: `src/main.ts`)
- Application entry → Collections: renders dashboard (evidence: `src/main.ts`)
- Application entry → Site rules: reads site rules (evidence: `src/main.ts`)
- Application entry → Browser routing: uses navigation (evidence: `src/main.ts`)
- Application entry → Authentication: uses sign-in (evidence: `src/main.ts`)
- Application entry → Customer records: uses customer views (evidence: `src/main.ts`)
- Application entry → Order booking: uses order views (evidence: `src/main.ts`)
- Application entry → Product inventory: uses product views (evidence: `src/main.ts`)
- Application entry → Reports: uses reports (evidence: `src/main.ts`)
- Application entry → Stock management: uses stock views (evidence: `src/main.ts`)
- Application entry → Depot management: uses depot views (evidence: `src/main.ts`)
- Application entry → Sales targets: uses target views (evidence: `src/main.ts`)
- Application entry → Order preview: opens preview (evidence: `src/main.ts`)
- Authentication → ERP state and sync: uses state (evidence: `src/modules/auth.ts`)
- Authentication → Shared UI: uses UI (evidence: `src/modules/auth.ts`)
- Order booking → Pricing engine: calculates prices (evidence: `src/modules/orders.ts`)
- Order booking → ERP state and sync: uses state (evidence: `src/modules/orders.ts`)
- Product inventory → Pricing engine: uses pricing (evidence: `src/modules/products.ts`)
- Product inventory → ERP state and sync: uses state (evidence: `src/modules/products.ts`)
- Reports → ERP state and sync: reads state (evidence: `src/modules/reports.ts`)
- Order preview → Invoice generation: builds and exports (evidence: `src/modules/orderPreview.ts`)
- Order preview → Pricing engine: calculates quantities (evidence: `src/modules/orderPreview.ts`)
- Order preview → ERP state and sync: reads and confirms (evidence: `src/modules/orderPreview.ts`)
- Order preview → Shared UI: shows feedback (evidence: `src/modules/orderPreview.ts`)
- ERP state and sync → Pricing engine: uses calculations (evidence: `src/modules/store.ts`)
- ERP state and sync → Firebase configuration: loads configuration (evidence: `src/modules/store.ts`)
- ERP state and sync → Firebase Realtime Database: syncs data
