How aryan-a1/hal works
1. Overall shape
HAL is a two-tier application: a React/Vite single-page frontend and a FastAPI backend. The frontend is the user-facing dashboard, while the backend owns authentication, crop records, AI-assisted insights, and persistence.
2. Frontend boundary
The frontend is organized as feature pages (Dashboard, CatchUp, CropDisease, CropIrrigation, Schemes, Login, Signup) composed from smaller UI sections. Shared UI primitives live under components/ui, and the app shell is wired in main.tsx/App.tsx.
3. Frontend state and client-side services
Zustand stores (useAuthStore, useChatStore, useLanguageStore, useNotificationStore, useProfileStore) hold cross-cutting client state such as session, language, and chat UI. API access is isolated in frontend/src/services, which acts as the only intended bridge from the UI to backend endpoints.
4. Internationalization and UX
The frontend includes bilingual English/Hindi support via locale JSON files and a translation hook. This is not just cosmetic; it affects how the dashboard, assistant, and support flows are rendered for farmers in the field.
5. Backend entry point and API surface
backend/main.py is the FastAPI composition root that mounts feature routers and static assets. The backend is split into routers by domain: auth, crop, disease, irrigation, weather, chatbot, scheme, catchup, and stores.
6. Authentication and user model
Authentication is JWT-based, with helper utilities in backend/utils/auth.py. User data is modeled in backend/models/user.py and validated through Pydantic schemas in backend/schemas/user.py, creating a clean boundary between request payloads, domain models, and token/session logic.
7. Crop and farm data domain
Crop lifecycle data is centered on backend/models/crop.py and related schemas. The crop/router pair exposes farm tracking features that feed the dashboard, history views, and catch-up summaries shown in the frontend.
8. Disease intelligence path
Crop disease analysis is a dedicated subsystem: routers/disease.py handles requests, services/disease_service.py and services/ai_insights.py provide the analysis logic, and backend/data/disease_solutions.json supplies curated remediation guidance. The frontend disease flow includes image upload, analysis, report, and nearby-store lookup screens.
9. Irrigation intelligence path
Irrigation is split between API routing and a service layer under backend/services/irrigation. forecast_engine.py and ml_service.py consume model artifacts and agronomic configuration data in data/irrigation_prediction/ and models/irrigation/ to generate water-use recommendations from crop, soil, and climate inputs.
10. Weather, chatbot, and support content
Weather insights are encapsulated in backend/services/weather_service.py and exposed through the weather router. The chatbot router likely fronts an external LLM integration described in the README, while the schemes and stores routers serve reference/utility content for farmers.
11. Persistence and file storage
The runtime database is SQLite (hal.db, with test.db for testing), managed through SQLAlchemy in backend/database.py. The backend also writes/serves local files under backend/static/audio and backend/uploads, which supports voice responses and uploaded media without needing object storage.
12. Offline data and ML lifecycle
There is a clear separation between runtime inference and model development. Training/evaluation scripts live under ml/irrigation/, while serialized production artifacts live under models/irrigation/. This suggests the irrigation recommender is deployed as a local ML asset rather than calling a remote inference service.
13. Testing and maintenance
The repo includes backend tests (test_auth.py, test_crop.py, test_api.py) and frontend tests under frontend/src/test. backend/reset_db.py indicates a developer-oriented reset path for rebuilding local state during iteration.
14. Diagramming guidance
For an architecture diagram, the key boundaries are: user/browser ↔ frontend SPA ↔ FastAPI routers ↔ service layer ↔ SQLite/local files/external AI APIs. The strongest domain partitions are authentication, crop monitoring, disease analysis, irrigation forecasting, and advisory content delivery.
Main entry points: main.py Backend app · services Service layer · main.tsx App shell · auth.py Auth domain
Components 17
Frontend SPA
React/Vite dashboard and farmer workflows
- App shell · Wires routing, layout, and global providers
frontend/src/main.tsx - Feature pages · Dashboard, catch-up, disease, irrigation, schemes, auth
frontend/src/pages - Shared UI · Reusable sections and primitive widgets
frontend/src/components - Client state · Session, chat, language, profile, notifications
frontend/src/store - i18n · English/Hindi translations and language selection
frontend/src/locales - API client · Typed bridge from UI to backend endpoints
frontend/src/services
FastAPI Backend
API composition, domain routers, and service layer
- Backend app · Composition root mounting routers and static assets
backend/main.py - Auth domain · Login, signup, token/session handling
backend/routers/auth.py - Crop domain · Crop lifecycle and dashboard/catch-up data
backend/routers/crop.py - Disease domain · Image analysis and remediation guidance
backend/routers/disease.py - Irrigation domain · Water-use recommendations from crop, soil, and climate inputs
backend/routers/irrigation.py - Advisory APIs · Weather, chatbot, schemes, stores, and catch-up support
backend/routers - Service layer · Analysis logic, orchestration, and external integrations
backend/services - Data models · User and crop models plus Pydantic schemas
backend/models
ML Assets
Irrigation training and production artifacts
- Irrigation ML · Trained classifier/regressor and feature metadata
models/irrigation
Local Data
SQLite, uploads, static audio, and curated JSON data
- SQLite store · Runtime database and local file-backed assets
hal.db - Local assets · Uploads, static audio, and curated JSON knowledge
backend/data
Connections 21
- App shell → Feature pages: renders · Application shell composes the feature pages
- App shell → Shared UI: uses · Pages are built from shared UI sections
- App shell → Client state: reads/writes · Global client state is consumed across the app
- App shell → i18n: translates · Language selection and locale strings shape the UX
- Feature pages → API client: calls · Feature pages use the service layer for backend access
- Client state → API client: auth/chat · Stores coordinate session, chat, and profile-backed requests
- API client → Backend app: HTTP API · Frontend service layer is the intended bridge to FastAPI
- Backend app → Auth domain: mounts · Composition root registers auth routes
- Backend app → Crop domain: mounts · Composition root registers crop routes
- Backend app → Disease domain: mounts · Composition root registers disease routes
- Backend app → Irrigation domain: mounts · Composition root registers irrigation routes
- Backend app → Advisory APIs: mounts · Composition root registers weather/chat/schemes/stores/catch-up routes
- Auth domain → Service layer: uses · Auth helpers and token logic live in the service layer
- Auth domain → Data models: validates · User payloads and persistence schemas define the auth boundary
- Crop domain → Data models: persists · Crop records are modeled and validated here
- Disease domain → Service layer: analyzes · Disease router delegates to analysis and AI insight services
- Disease domain → Local assets: reads guidance · Curated remediation data supplements diagnosis
- Irrigation domain → Service layer: forecasts · Irrigation router calls forecasting and ML services
- Irrigation domain → Irrigation ML: loads models · Production inference uses serialized irrigation artifacts
- Service layer → Local assets: consumes data · Services read local JSON and audio/file assets as needed
- Service layer → SQLite store: stores/loads · Services and routers use SQLite-backed persistence