# vasuantala049/milk-production-and-prediction-system architecture

> Architecture diagram of the GitHub repository vasuantala049/milk-production-and-prediction-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vasuantala049/milk-production-and-prediction-system
- Repository: https://github.com/vasuantala049/milk-production-and-prediction-system

## Overview

1. **Overall shape**
   - This is a full-stack dairy management platform with three main layers: a React/Vite frontend, a Spring Boot backend API, and infrastructure/deployment code for AWS + Kubernetes.
   - The core business flow is farm operations and milk commerce: manage farms/sheds/cattle, track milk production and inventory, and support customer buying/subscriptions.

2. **Frontend: role-based single-page app**
   - The frontend is a React SPA built with Vite and served behind Nginx.
   - It is organized around user roles and workflows: customer, worker, and owner dashboards, plus screens for login/register, forgot password, farm/cattle management, milk entry, subscriptions, orders, and profile management.
   - The UI also includes internationalization support for English and Gujarati, a barcode scanner component, and reusable UI primitives.

3. **Frontend-to-backend interaction**
   - The frontend talks to the backend through dedicated API clients for cattle, farm, order, and subscription flows.
   - Route protection is handled in the client, so authenticated navigation is a frontend concern, but authorization is ultimately enforced by the backend.

4. **Backend architecture: classic layered Spring Boot**
   - The backend follows a standard Controller → Service → Repository → Entity structure.
   - Controllers expose REST endpoints by domain area: auth, user, farm, shed, cattle, milk, buy milk, order, and subscription.
   - Services contain business rules; repositories wrap persistence; DTOs isolate API contracts from JPA entities.

5. **Core domain model**
   - The main entities are Farm, Shed, Cattle, MilkInventory, CattleMilkEntry, MilkAllocation, Orders, Subscription, User, and worker/invitation linkage objects.
   - The domain is built around operational relationships: farms contain sheds and cattle, cattle generate milk entries, milk is aggregated into inventory and allocated for sale, and orders/subscriptions consume that inventory.
   - Worker assignments and invitations indicate multi-tenant, role-scoped access to farm resources.

6. **Security and identity**
   - Authentication is JWT-based, with a custom user-details service and a JWT authentication filter in the request pipeline.
   - Password handling uses a bounded bcrypt encoder, and user roles are modeled explicitly in the domain.
   - Auth-related APIs support login, registration, forgot-password, and OTP/reset flows, which suggests email-driven account recovery.

7. **Persistence and runtime dependencies**
   - The backend uses a relational persistence layer via Spring Data repositories and JPA entities.
   - Redis is a first-class runtime dependency: there is dedicated Redis cache configuration plus a startup check, so the application expects Redis to be available and healthy.
   - There is also a database health controller, implying operational readiness/liveness checks are part of the backend surface.

8. **Payments and commerce workflows**
   - The buy-milk, order, and subscription modules are separate, but connected through shared inventory and payment request/response DTOs.
   - Razorpay-specific response DTOs indicate external payment-gateway integration for purchase and subscription checkout.
   - Orders and subscriptions have explicit status enums, which suggests stateful payment lifecycle handling.

9. **Operational support and cross-cutting concerns**
   - A global exception handler centralizes API error translation.
   - Mapper configuration suggests DTO/entity conversion is a formal concern rather than ad hoc mapping.
   - Email service implementation supports notification-style workflows such as OTP, password reset, and worker invitations.

10. **Deployment and platform**
   - The repo includes Kubernetes Helm charts for the application stack, with separate templates for backend, frontend, Redis, ingress, namespace, secrets, and autoscaling.
   - Nginx ingress is included as part of the platform layer, which means external traffic is routed into the cluster through ingress resources rather than direct pod exposure.
   - The frontend also has cert assets and an Nginx config, indicating HTTPS-aware static serving or reverse-proxy deployment.

11. **Infrastructure as code and GitOps**
   - Terraform provisions the AWS environment; the README specifically calls out DB credentials as Terraform inputs, so infrastructure and application bootstrap are meant to be repeatable.
   - There are Argo CD and image updater manifests, which points to GitOps-based rollout of container images into Kubernetes.
   - CI files for GitHub Actions and Jenkins indicate automated build/test/package pipelines feed the deployment process.

12. **How data moves through the system**
   - Users interact with the SPA, which calls REST endpoints on the Spring Boot API.
   - The backend authenticates requests with JWT, reads/writes relational state through repositories, uses Redis for cache or fast access, and emits updates through payment/email flows when needed.
   - Deployed services run in Kubernetes behind ingress, with AWS-provisioned infrastructure underneath and image updates managed through CI/CD/GitOps.

Main entry points: [`helm/dairy-flow/templates/ingress.yml`](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/helm/dairy-flow/templates/ingress.yml) (Helm stack), [`frontend/src/App.jsx`](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/App.jsx) (SPA shell), [`backend/backend/src/main/java/com/example/backend/Controller/AuthController.java`](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Controller/AuthController.java) (REST API), [`backend/backend/src/main/java/com/example/backend/Service/impl/FarmServiceImpl.java`](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Service/impl/FarmServiceImpl.java) (Business services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["SPA shell<br/>react app<br/>[App.jsx]"]
  node_frontend_dashboards["Dashboards<br/>ui workflows<br/>[OwnerDashboard.jsx]"]
  node_frontend_auth["Auth screens<br/>ui auth<br/>[Login.jsx]"]
  node_frontend_api["API clients<br/>frontend api<br/>[client.js]"]
  node_frontend_i18n["i18n<br/>localization<br/>[i18n.js]"]
end

subgraph group_backend["Backend"]
  node_backend_app["API app<br/>spring boot"]
  node_backend_controllers["REST API<br/>controllers"]
  node_backend_services["Business services<br/>service layer"]
  node_backend_repos[("Repositories<br/>persistence")]
  node_backend_entities[("Domain model<br/>jpa entities<br/>[Farm.java]")]
  node_backend_security{{"Security<br/>jwt auth"}}
  node_backend_crosscutting["Cross-cutting<br/>config & errors"]
  node_backend_redis[("Redis<br/>cache/runtime")]
end

subgraph group_platform["Platform"]
  node_platform_helm["Helm stack<br/>kubernetes charts<br/>[ingress.yml]"]
  node_platform_nginx["Ingress"]
  node_platform_terraform["Terraform<br/>aws infra<br/>[main.tf]"]
end

subgraph group_delivery["Delivery"]
  node_delivery_github["GitHub Actions<br/>ci pipeline<br/>[backend.yml]"]
  node_delivery_jenkins["Jenkins<br/>ci pipeline"]
  node_delivery_argocd["Argo CD<br/>gitops rollout"]
end

node_frontend_app -->|"renders"| node_frontend_dashboards
node_frontend_app -->|"routes"| node_frontend_auth
node_frontend_app -->|"calls"| node_frontend_api
node_frontend_app -->|"localizes"| node_frontend_i18n
node_frontend_api -->|"REST"| node_backend_controllers
node_backend_app -->|"configures"| node_backend_security
node_backend_app -->|"hosts"| node_backend_controllers
node_backend_controllers -->|"delegates"| node_backend_services
node_backend_services -->|"persists"| node_backend_repos
node_backend_repos -->|"maps"| node_backend_entities
node_backend_services -->|"uses"| node_backend_entities
node_backend_security -->|"guards"| node_backend_controllers
node_backend_security -.->|"supports"| node_backend_crosscutting
node_backend_crosscutting -->|"checks"| node_backend_redis
node_backend_services -->|"caches"| node_backend_redis
node_backend_controllers -->|"errors"| node_backend_crosscutting
node_platform_helm -->|"includes"| node_platform_nginx
node_platform_helm -->|"deploys"| node_backend_app
node_platform_helm -->|"deploys"| node_frontend_app
node_platform_helm -->|"deploys"| node_backend_redis
node_platform_terraform -->|"provisions"| node_platform_helm
node_delivery_github -->|"builds"| node_backend_app
node_delivery_jenkins -.->|"delivers"| node_platform_helm
node_delivery_argocd -->|"syncs"| node_platform_helm

click node_frontend_app "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/App.jsx"
click node_frontend_dashboards "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/components/dashboard/OwnerDashboard.jsx"
click node_frontend_auth "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/components/Login.jsx"
click node_frontend_api "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/api/client.js"
click node_frontend_i18n "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/config/i18n.js"
click node_backend_app "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/BackendApplication.java"
click node_backend_controllers "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Controller/AuthController.java"
click node_backend_services "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Service/impl/FarmServiceImpl.java"
click node_backend_repos "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Repository/FarmRepository.java"
click node_backend_entities "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Entity/Farm.java"
click node_backend_security "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Security/SecurityConfig.java"
click node_backend_crosscutting "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Config/GlobalExceptionHandler.java"
click node_backend_redis "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Config/RedisCacheConfig.java"
click node_platform_helm "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/helm/dairy-flow/templates/ingress.yml"
click node_platform_nginx "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/helm/dairy-flow/nginx-ingress/templates/controller-deployment.yaml"
click node_platform_terraform "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/terraform/main.tf"
click node_delivery_github "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/.github/workflows/backend.yml"
click node_delivery_jenkins "https://github.com/vasuantala049/milk-production-and-prediction-system/tree/main/Jenkinsfile"
click node_delivery_argocd "https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/argocd/milk-img-updater.yml"

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_frontend_app,node_frontend_dashboards,node_frontend_auth,node_frontend_api,node_frontend_i18n toneBlue
class node_backend_app,node_backend_controllers,node_backend_services,node_backend_repos,node_backend_entities,node_backend_security,node_backend_crosscutting,node_backend_redis toneAmber
class node_platform_helm,node_platform_nginx,node_platform_terraform toneMint
class node_delivery_github,node_delivery_jenkins,node_delivery_argocd toneRose
```

## Components

### Frontend

React/Vite SPA with role-based dashboards and API clients

- [SPA shell](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/App.jsx): react app · Entry app and shared routing/layout for the dairy portal · `frontend/src/App.jsx`
- [Dashboards](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/components/dashboard/OwnerDashboard.jsx): ui workflows · Owner, worker, and customer dashboard screens and farm operations views · `frontend/src/components/dashboard/OwnerDashboard.jsx`
- [Auth screens](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/components/Login.jsx): ui auth · Login, registration, password reset, and protected navigation · `frontend/src/components/Login.jsx`
- [API clients](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/api/client.js): frontend api · Client layer for cattle, farm, order, subscription, and shared requests · `frontend/src/api/client.js`
- [i18n](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/frontend/src/config/i18n.js): localization · English/Gujarati translations and language switching · `frontend/src/config/i18n.js`

### Backend

Spring Boot API with layered domain and security stack

- [API app](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/BackendApplication.java): spring boot · Main backend application bootstrap and runtime wiring · `backend/backend/src/main/java/com/example/backend/BackendApplication.java`
- [REST API](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Controller/AuthController.java): controllers · Domain controllers for auth, farm, cattle, milk, orders, and subscriptions · `backend/backend/src/main/java/com/example/backend/Controller/AuthController.java`
- [Business services](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Service/impl/FarmServiceImpl.java): service layer · Core business rules for farm access, cattle, milk, buying, orders, and subscriptions · `backend/backend/src/main/java/com/example/backend/Service/impl/FarmServiceImpl.java`
- [Repositories](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Repository/FarmRepository.java): persistence · Spring Data repositories for relational persistence · `backend/backend/src/main/java/com/example/backend/Repository/FarmRepository.java`
- [Domain model](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Entity/Farm.java): jpa entities · Farms, sheds, cattle, milk inventory, orders, subscriptions, users, and worker linkage · `backend/backend/src/main/java/com/example/backend/Entity/Farm.java`
- [Security](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Security/SecurityConfig.java): jwt auth · JWT filter, token provider, user details service, and password encoding · `backend/backend/src/main/java/com/example/backend/Security/SecurityConfig.java`
- [Cross-cutting](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Config/GlobalExceptionHandler.java): config & errors · Exception handling, mapping config, cache config, and Redis startup checks · `backend/backend/src/main/java/com/example/backend/Config/GlobalExceptionHandler.java`
- [Redis](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/backend/backend/src/main/java/com/example/backend/Config/RedisCacheConfig.java): cache/runtime · Redis cache dependency and health/startup validation · `backend/backend/src/main/java/com/example/backend/Config/RedisCacheConfig.java`

### Platform

Kubernetes, GitOps, and cloud infrastructure

- [Helm stack](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/helm/dairy-flow/templates/ingress.yml): kubernetes charts · Application deployment charts for frontend, backend, Redis, ingress, secrets, and scaling · `helm/dairy-flow/templates/ingress.yml`
- [Ingress](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/helm/dairy-flow/nginx-ingress/templates/controller-deployment.yaml): nginx ingress · Nginx ingress controller and exposure layer for cluster traffic · `helm/dairy-flow/nginx-ingress/templates/controller-deployment.yaml`
- [Terraform](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/terraform/main.tf): aws infra · AWS environment provisioning and bootstrap inputs · `terraform/main.tf`

### Delivery

CI/CD and automation around builds and rollout

- [GitHub Actions](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/.github/workflows/backend.yml): ci pipeline · Automated backend workflow execution and build orchestration · `.github/workflows/backend.yml`
- [Jenkins](https://github.com/vasuantala049/milk-production-and-prediction-system/tree/main/Jenkinsfile): ci pipeline · Additional build and delivery automation · `Jenkinsfile`
- [Argo CD](https://github.com/vasuantala049/milk-production-and-prediction-system/blob/main/argocd/milk-img-updater.yml): gitops rollout · GitOps manifests and image updater configuration for deployment synchronization · `argocd/milk-img-updater.yml`

## Connections

- SPA shell → Dashboards: renders · SPA composes role-based operational views
- SPA shell → Auth screens: routes · Login and recovery flows are handled in the client
- SPA shell → API clients: calls · UI actions use dedicated API clients
- SPA shell → i18n: localizes · Language selection and translations are shared across screens
- API clients → REST API: REST · Frontend clients consume backend endpoints
- API app → Security: configures · Security pipeline is applied at application startup
- API app → REST API: hosts · Spring Boot exposes the REST surface
- REST API → Business services: delegates · Controllers hand off business logic to services
- Business services → Repositories: persists · Services load and save through repositories
- Repositories → Domain model: maps · Repositories operate on JPA entities
- Business services → Domain model: uses · Business rules are expressed over the domain model
- Security → REST API: guards · JWT authentication protects API access
- Security → Cross-cutting: supports · Security depends on shared configuration and error handling
- Cross-cutting → Redis: checks · Redis is validated during backend startup
- Business services → Redis: caches · Runtime access may use Redis-backed cache or fast state
- REST API → Cross-cutting: errors · Exceptions are translated into API responses centrally
- Helm stack → Ingress: includes · Application charts rely on ingress resources and Nginx exposure
- Helm stack → API app: deploys · Backend is packaged for Kubernetes deployment
- Helm stack → SPA shell: deploys · Frontend is packaged for Kubernetes deployment
- Helm stack → Redis: deploys · Redis is deployed as part of the application stack
- Terraform → Helm stack: provisions · Cloud infrastructure underpins the Kubernetes release
- GitHub Actions → API app: builds · GitHub Actions drives backend automation
- Jenkins → Helm stack: delivers · Jenkins supports packaging and rollout workflows
- Argo CD → Helm stack: syncs · Argo CD keeps cluster state aligned with git manifests
