# aman-lab1/aman-agrovet architecture

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

- Interactive diagram: https://gitdiagram.com/aman-lab1/aman-agrovet
- Repository: https://github.com/aman-lab1/aman-agrovet

## Overview

AMAN Agrovet V3 is an early-stage poultry-management web application: the README says business modules, database migrations, Firebase authentication, and financial calculations remain planned. The current runtime provides a React interface, passcode-based API authentication, and initial house, flock-batch, employee, user, and audit-log capabilities. Users enter through authenticated routes; the frontend calls an Express API, whose handlers access PostgreSQL. Other operational pages are present as scaffolding or previews. Edges reflect excerpts, indexed imports, or README statements; unsampled route and domain behavior is not assumed.

Main entry points: [`backend/src/db/index.ts`](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/db/index.ts) (PostgreSQL access), [`frontend/src/App.tsx`](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/App.tsx) (Authenticated app), [`backend/src/routes/index.ts`](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/routes/index.ts) (API routes), [`frontend/src/services/apiClient.ts`](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/services/apiClient.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["Authenticated app<br/>[App.tsx]"]
  node_authctx["Session context<br/>[AuthContext.tsx]"]
  node_login["Login page<br/>[LoginPage.tsx]"]
  node_dashboard["Dashboard preview<br/>[DashboardPage.tsx]"]
  node_opsui["Operations pages"]
  node_adminui["Admin pages"]
  node_apiclient["API client<br/>[apiClient.ts]"]
  node_operationalui["Production and finance"]
end

subgraph group_api["API and access"]
  node_api["Express API<br/>[app.ts]"]
  node_routes["API routes<br/>[index.ts]"]
  node_authmw["Auth middleware<br/>[auth.ts]"]
  node_errors["Error handling<br/>[errorHandler.ts]"]
end

subgraph group_domain["Farm operations"]
  node_houses["Houses"]
  node_batches["Flock batches"]
  node_employees["Employees"]
  node_useradmin["User management"]
end

subgraph group_persistence["Persistence and audit"]
  node_schema["Domain schemas"]
  node_db[("PostgreSQL access<br/>[index.ts]")]
  node_audit["Audit logging<br/>[audit.service.ts]"]
end

node_user(("Business user"))
node_externaldb[("PostgreSQL")]

node_user -->|"uses"| node_app
node_app -->|"provides session"| node_authctx
node_app -->|"shows when signed out"| node_login
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_opsui
node_app -->|"routes to"| node_adminui
node_authctx -->|"authenticates through"| node_apiclient
node_dashboard -->|"uses flock calculations"| node_opsui
node_opsui -->|"requests data"| node_apiclient
node_adminui -->|"requests data"| node_apiclient
node_apiclient -.->|"sends HTTP requests"| node_api
node_api -->|"mounts routes"| node_routes
node_routes -->|"applies auth"| node_authmw
node_routes -->|"dispatches batch requests"| node_batches
node_routes -->|"dispatches employee requests"| node_employees
node_routes -->|"dispatches house requests"| node_houses
node_routes -->|"dispatches user requests"| node_useradmin
node_batches -->|"queries and updates"| node_db
node_employees -->|"queries and updates"| node_db
node_houses -->|"queries and updates"| node_db
node_useradmin -->|"queries and updates"| node_db
node_db -->|"loads schema"| node_schema
node_db -->|"connects"| node_externaldb
node_batches -->|"writes audit entries"| node_audit
node_employees -->|"writes audit entries"| node_audit
node_houses -->|"writes audit entries"| node_audit
node_audit -->|"inserts audit records"| node_db
node_errors -.->|"formats errors"| node_api

click node_app "https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/App.tsx"
click node_authctx "https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/contexts/AuthContext.tsx"
click node_login "https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/pages/auth/LoginPage.tsx"
click node_dashboard "https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/pages/dashboard/DashboardPage.tsx"
click node_opsui "https://github.com/aman-lab1/aman-agrovet/tree/main/frontend/src/pages"
click node_adminui "https://github.com/aman-lab1/aman-agrovet/tree/main/frontend/src/pages"
click node_apiclient "https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/services/apiClient.ts"
click node_api "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/app.ts"
click node_routes "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/routes/index.ts"
click node_authmw "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/middleware/auth.ts"
click node_errors "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/middleware/errorHandler.ts"
click node_houses "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/houses.controller.ts"
click node_batches "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/batches.controller.ts"
click node_employees "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/employees.controller.ts"
click node_useradmin "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/users.controller.ts"
click node_operationalui "https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/pages/egg-production/EggProductionPage.tsx"
click node_schema "https://github.com/aman-lab1/aman-agrovet/tree/main/backend/src/db/schema"
click node_db "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/db/index.ts"
click node_audit "https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/services/audit.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_authctx,node_login,node_dashboard,node_opsui,node_adminui,node_apiclient,node_operationalui,node_user toneBlue
class node_api,node_routes,node_authmw,node_errors,node_externaldb toneAmber
class node_houses,node_batches,node_employees,node_useradmin toneMint
class node_schema,node_db,node_audit toneRose
```

## Components

### Web client

- [Authenticated app](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Session context](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/contexts/AuthContext.tsx): `frontend/src/contexts/AuthContext.tsx`
- [Login page](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/pages/auth/LoginPage.tsx): `frontend/src/pages/auth/LoginPage.tsx`
- [Dashboard preview](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/pages/dashboard/DashboardPage.tsx): `frontend/src/pages/dashboard/DashboardPage.tsx`
- [Operations pages](https://github.com/aman-lab1/aman-agrovet/tree/main/frontend/src/pages): `frontend/src/pages`
- [Admin pages](https://github.com/aman-lab1/aman-agrovet/tree/main/frontend/src/pages): `frontend/src/pages`
- [API client](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/services/apiClient.ts): `frontend/src/services/apiClient.ts`
- [Production and finance](https://github.com/aman-lab1/aman-agrovet/blob/main/frontend/src/pages/egg-production/EggProductionPage.tsx): `frontend/src/pages/egg-production/EggProductionPage.tsx`

### API and access

- [Express API](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [API routes](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/routes/index.ts): `backend/src/routes/index.ts`
- [Auth middleware](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`
- [Error handling](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/middleware/errorHandler.ts): `backend/src/middleware/errorHandler.ts`

### Farm operations

- [Houses](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/houses.controller.ts): `backend/src/controllers/houses.controller.ts`
- [Flock batches](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/batches.controller.ts): `backend/src/controllers/batches.controller.ts`
- [Employees](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/employees.controller.ts): `backend/src/controllers/employees.controller.ts`
- [User management](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/controllers/users.controller.ts): `backend/src/controllers/users.controller.ts`

### Persistence and audit

- [Domain schemas](https://github.com/aman-lab1/aman-agrovet/tree/main/backend/src/db/schema): `backend/src/db/schema`
- [PostgreSQL access](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/db/index.ts): `backend/src/db/index.ts`
- [Audit logging](https://github.com/aman-lab1/aman-agrovet/blob/main/backend/src/services/audit.service.ts): `backend/src/services/audit.service.ts`

### Other components

- **Business user**
- **PostgreSQL**

## Connections

- Business user → Authenticated app: uses (evidence: `frontend/src/App.tsx`)
- Authenticated app → Session context: provides session (evidence: `frontend/src/App.tsx`)
- Authenticated app → Login page: shows when signed out (evidence: `frontend/src/App.tsx`)
- Authenticated app → Dashboard preview: routes to (evidence: `frontend/src/App.tsx`)
- Authenticated app → Operations pages: routes to (evidence: `frontend/src/App.tsx`)
- Authenticated app → Admin pages: routes to (evidence: `frontend/src/App.tsx`)
- Session context → API client: authenticates through (evidence: `frontend/src/contexts/AuthContext.tsx`)
- Dashboard preview → Operations pages: uses flock calculations (evidence: `frontend/src/pages/dashboard/DashboardPage.tsx`)
- Operations pages → API client: requests data (evidence: `frontend/src/pages/egg-production/EggProductionPage.tsx`)
- Admin pages → API client: requests data (evidence: `frontend/src/pages/audit-logs/AuditLogsPage.tsx`)
- API client → Express API: sends HTTP requests
- Express API → API routes: mounts routes (evidence: `backend/src/app.ts`)
- API routes → Auth middleware: applies auth
- API routes → Flock batches: dispatches batch requests
- API routes → Employees: dispatches employee requests
- API routes → Houses: dispatches house requests
- API routes → User management: dispatches user requests
- Flock batches → PostgreSQL access: queries and updates (evidence: `backend/src/controllers/batches.controller.ts`)
- Employees → PostgreSQL access: queries and updates (evidence: `backend/src/controllers/employees.controller.ts`)
- Houses → PostgreSQL access: queries and updates (evidence: `backend/src/controllers/houses.controller.ts`)
- User management → PostgreSQL access: queries and updates (evidence: `backend/src/controllers/users.controller.ts`)
- PostgreSQL access → Domain schemas: loads schema (evidence: `backend/src/db/index.ts`)
- PostgreSQL access → PostgreSQL: connects (evidence: `backend/src/db/index.ts`)
- Flock batches → Audit logging: writes audit entries (evidence: `backend/src/controllers/batches.controller.ts`)
- Employees → Audit logging: writes audit entries (evidence: `backend/src/controllers/employees.controller.ts`)
- Houses → Audit logging: writes audit entries (evidence: `backend/src/controllers/houses.controller.ts`)
- Audit logging → PostgreSQL access: inserts audit records (evidence: `backend/src/services/audit.service.ts`)
- Error handling → Express API: formats errors (evidence: `backend/src/app.ts`)
