How ceowsc/namma_sandhai works
Purpose and Deployable Surfaces
This is a multi-client agricultural marketplace and decision-support system: farmer, customer, merchant, district-market, and administrator workflows cover catalog/order operations, supply-demand visibility, communities, pricing, harvest planning, and communications.
Primary entry points:
• Node/Express API: backend/server.js
• Flutter cross-platform app: frontend/lib/main.dart
• React/Vite public marketplace portal: landing_page/src/main.jsx
• React/Vite operations console: admin_panel/src/main.jsx
Backend API and Persistence Boundary
The backend is the central integration boundary, with route modules exposing domain APIs and middleware enforcing authenticated access. Environment and database setup are separated from route/controller logic.
Key paths:
• backend/server.js
• backend/config/database.js
• backend/middleware/auth.js
• database/schema.sql
The relational schema, seed SQL, migration scripts, and backend maintenance scripts indicate an application-managed SQL database. API consumers include the Flutter app and both React applications.
Marketplace Transaction Domain
Product discovery, carts, wishlists, inventory, requirements, offers/LOIs, and order fulfillment are distinct API domains. Customer and business clients present role-specific flows over these shared backend resources.
Key paths:
• backend/routes/products.js
• backend/routes/cart.js
• backend/routes/orders.js
• backend/routes/inventory.js
• backend/routes/loi.js
Client flow generally progresses from catalog/search to cart or requirement/offer creation, then checkout/order management. Merchant and farmer interfaces add inventory, selling, wholesale, and LOI workflows.
Agricultural Intelligence Pipeline
The platform combines deterministic agricultural calculations with AI-assisted recommendations and external market/weather inputs. Harvest planning is a primary decision-support workflow, exposed through APIs and dedicated farmer screens.
Key paths:
• backend/routes/harvestPlan.js
• backend/services/aiHarvestPlanner.js
• backend/services/harvestCalculator.js
• backend/services/aiPricePredictor.js
• backend/services/mandiService.js
• backend/services/weatherService.js
Inputs such as crop, location, agronomy, market prices, and weather feed forecast/planning services. The mobile planner UI is centered at frontend/lib/features/farmer/features/harvest_planner_screen.dart; deterministic client-side preview widgets coexist with server-side planning logic.
Market, Demand, and Geographic Operations
Demand, mandi prices, supply-demand mapping, delivery routes, and district-level monitoring form a geographic market-intelligence subsystem. Tamil Nadu administrative and district geospatial data are packaged for map visualization.
Key paths:
• backend/routes/demand.js
• backend/routes/mandiPrices.js
• backend/routes/map.js
• backend/routes/deliveryRoutes.js
• admin_panel/src/components/SupplyDemandMap.jsx
• admin_panel/public/tn_districts.geojson
District officer screens in frontend/lib/features/market/district_officer/ and admin analytics pages consume this operational layer for price verification, stock intelligence, and supply-demand oversight.
Identity, Roles, and Client State
Authentication is server-mediated, while each client organizes its own UI state and role routing. Flutter uses provider-oriented state modules; React portals use local stores/components and protected routes.
Key paths:
• backend/routes/auth.js
• backend/services/authService.js
• frontend/lib/providers/auth_provider.dart
• landing_page/src/components/ProtectedRoute.jsx
• landing_page/src/store/useAuthStore.js
Role-specific application shells separate customer, farmer, merchant, admin, and district workflows rather than treating the system as a single generic storefront.
Communications and External Integrations
Notification, email, WhatsApp, uploads, Firebase, Google indexing, maps, and Gemini-backed AI are explicit integration boundaries. Batch utilities suggest bulk outbound communications rather than only synchronous request handling.
Key paths:
• backend/routes/notifications.js
• backend/routes/emailManager.js
• backend/routes/whatsapp.js
• backend/services/geminiService.js
• backend/utils/firebaseUtils.js
• backend/utils/emailBatcher.js
The Flutter client also includes HTTP, socket, location, map, and notification service boundaries under frontend/lib/services/, keeping device/platform integrations outside screen components.
Main entry points: server.js Express API · aiHarvestPlanner.js AI harvest planner · demand.js Market operations APIs · harvestPlan.js Harvest planning API
Components 19
Client surfaces
- Flutter role-based app · Farmer, customer, merchant, and district workflows.
frontend/lib/main.dart - Harvest planner UI · Farmer planning flow with local previews.
frontend/lib/features/farmer/features/harvest_planner_screen.dart - Public marketplace portal
landing_page/src/main.jsx - Portal auth state
landing_page/src/components/ProtectedRoute.jsx - Operations console
admin_panel/src/main.jsx
Backend API
- Express API · Central API for all clients and domain routes.
backend/server.js - Authentication and roles · Server-mediated authentication and access control.
backend/routes/auth.js - Auth middleware
backend/middleware/auth.js - Application SQL database · Schema-managed transactional data store.
database/schema.sql
Marketplace
- Commerce APIs · Catalog, carts, orders, inventory, and LOI workflows.
backend/routes/orders.js
Decision support
- Harvest planning API
backend/routes/harvestPlan.js - AI harvest planner · Combines agronomy and forecast inputs into plans.
backend/services/aiHarvestPlanner.js - Harvest calculator
backend/services/harvestCalculator.js - Price and weather inputs · Mandi market and weather data inform recommendations.
backend/services/mandiService.js
Market operations
- Supply-demand map · Renders district-level operational visibility.
admin_panel/src/components/SupplyDemandMap.jsx - Market operations APIs · Demand, mandi pricing, maps, and delivery routing.
backend/routes/demand.js - Tamil Nadu district geography
admin_panel/public/tn_districts.geojson
Integrations
- Communications API · Notification, email, and WhatsApp delivery endpoints.
backend/routes/notifications.js - External platform services · AI, Firebase, email, WhatsApp, maps, and device services.
backend/services/geminiService.js
Connections 22
- Flutter role-based app → Express API: API calls
- Harvest planner UI → Harvest planning API: planning requests
- Public marketplace portal → Portal auth state: guards role flows
- Public marketplace portal → Express API: API calls
- Operations console → Express API: API calls
- Operations console → Supply-demand map: renders
- Supply-demand map → Tamil Nadu district geography: district boundaries
- Express API → Authentication and roles: mounts
- Express API → Auth middleware: enforces access
- Express API → Commerce APIs: mounts
- Express API → Harvest planning API: mounts
- Express API → Market operations APIs: mounts
- Express API → Communications API: mounts
- Authentication and roles → Application SQL database: identities and roles
- Commerce APIs → Application SQL database: transactions
- Market operations APIs → Application SQL database: market and demand data
- Harvest planning API → AI harvest planner: generates plans
- AI harvest planner → Harvest calculator: deterministic calculations
- AI harvest planner → Price and weather inputs: market and weather inputs
- AI harvest planner → External platform services: AI recommendations
- Market operations APIs → Price and weather inputs: mandi prices
- Communications API → External platform services: outbound delivery