How kranthikiran885366/kisan-mitra-ai-farming-advisor works
Purpose and Runtime Topology
Kisan Mitra is a multilingual farming platform covering advisory, weather, market intelligence, government schemes, crop disease guidance, community interaction, consultations, and a crop marketplace. It has two application stacks: a Next.js App Router frontend/API surface and a separate Express/MongoDB backend. A legacy React client also exists and should be treated as a distinct/possibly transitional frontend.
• app/layout.tsx
• app/page.tsx
• server/server.js
• client/src/index.js
Primary User Experience Shell
The Next.js application is the main route-based UI. The root layout establishes shared application framing; dashboard and feature pages compose the farmer workflow. Shared navigation, provider wiring, notifications, and domain widgets support cross-page interaction.
• app/dashboard/page.tsx
• components/providers/Providers.tsx
• components/enhanced-sidebar.tsx
• components/BottomNavigation.tsx
Identity, Onboarding, and Access Boundary
Authentication includes signup and OTP issuance/verification through Next route handlers, while the Express backend separately exposes auth routes and JWT middleware. Frontend auth state is held in a React context; protected backend requests should cross the JWT boundary rather than directly trusting client state.
• app/api/auth/signup/route.ts
• app/api/auth/send-otp/route.ts
• app/api/auth/verify-otp/route.ts
• lib/contexts/AuthContext.tsx
• server/middleware/auth.js
• server/routes/auth.js
Advisory and AI Domain
Crop advice, disease expertise/scanning, and conversational assistance are major decision-support stages. Page-level UI calls typed client API modules; Express routes orchestrate domain logic, persistence, and AI integration. AI conversations and knowledge-base content have dedicated models, indicating the assistant is intended to retain or retrieve agricultural context.
• app/ai-assistant/page.tsx
• app/crop-advisor/page.tsx
• app/disease-expert/page.tsx
• lib/assistantApi.ts
• server/routes/assistant.js
• server/services/aiService.js
• server/models/AIConversation.js
Agricultural Information Services
Weather, mandi/market data, and scheme discovery are independently routed service domains. Their service layer is the external-integration boundary: configured weather and market credentials suggest OpenWeather and Agmarknet-style providers, while scheme data can be curated or sourced externally. The UI consumes these through feature API clients.
• app/weather/page.tsx
• app/market/page.tsx
• app/schemes/page.tsx
• lib/marketApi.ts
• lib/schemesApi.ts
• server/services/weatherService.js
• server/services/marketService.js
• server/services/schemeService.js
Community, Consultations, and Messaging
Farmer engagement is modeled as server-managed social and expert-interaction data: communities/posts, discussions, consultations/appointments, messages, ratings, and WhatsApp integration. This separates collaboration and support workflows from the informational advisory modules.
• app/community/page.tsx
• app/consultations/[id]/page.tsx
• app/messages/page.tsx
• server/routes/community.js
• server/routes/consultations.js
• server/routes/whatsapp.js
• server/models/CommunityPost.js
• server/models/Appointment.js
Marketplace Transaction Flow
The marketplace supports product discovery, farmer crop listings, carts, checkout, orders, and negotiation. The frontend route hierarchy represents browse-to-purchase/sell flows; the Express marketplace route owns transaction-facing operations and MongoDB models store the durable commercial entities.
• app/marketplace/page.tsx
• app/marketplace/product/[id]/page.tsx
• app/marketplace/cart/page.tsx
• app/marketplace/checkout/page.tsx
• server/routes/marketplace.js
• server/models/Cart.js
• server/models/Order.js
• server/models/CropListing.js
Persistence, Localization, and Operational Dependencies
MongoDB is the central persistence layer, accessed from Next via a Mongo helper and from Express through Mongoose-style models. Data can be initialized with server seed scripts. The current Next UI owns TypeScript localization context, while the legacy client has a separate i18n catalog; avoid conflating their state providers. Browser Web Speech capabilities support voice UX, and environment configuration supplies MongoDB/JWT plus optional external API keys.
• lib/mongodb.ts
• server/models/User.js
• server/scripts/seedAll.js
• lib/contexts/LanguageContext.tsx
• client/src/i18n/config.js
• .env.example
Main entry points: page.tsx Farmer dashboard · auth.js JWT auth boundary · assistant.js Assistant domain · mongodb.ts MongoDB
Components 21
Next.js application
Primary App Router UI and API surface.
- App shell · Shared layout, providers, and navigation frame.
app/layout.tsx - Farmer dashboard
app/dashboard/page.tsx - OTP signup API · Signup and OTP issuance/verification endpoints.
app/api/auth/signup/route.ts - Auth state
lib/contexts/AuthContext.tsx - AI and crop guidance · Assistant, crop-advisor, and disease-expert experiences.
app/ai-assistant/page.tsx - Assistant API client
lib/assistantApi.ts - Weather, market, schemes · Agricultural information feature pages.
app/weather/page.tsx - Market API client
lib/marketApi.ts - Community and support · Community, consultations, and messaging UI.
app/community/page.tsx - Marketplace flow · Browse, product, cart, and checkout flow.
app/marketplace/page.tsx - Language context · Current Next UI localization state.
lib/contexts/LanguageContext.tsx
Express backend
Separate domain API and orchestration runtime.
- Express server · Hosts authenticated domain routes.
server/server.js - JWT auth boundary · Protects backend requests independently of client state.
server/middleware/auth.js - Assistant domain · Orchestrates conversational agricultural AI.
server/routes/assistant.js - Information services · Weather, market, and scheme retrieval boundary.
server/services/weatherService.js - Engagement domain · Community, consultations, and WhatsApp workflows.
server/routes/community.js - Marketplace domain · Transaction-facing listing, cart, order, and negotiation operations.
server/routes/marketplace.js
Data and integrations
- MongoDB · Central durable data store.
lib/mongodb.ts - Agricultural providers · Weather, mandi data, schemes, and optional AI providers.
.env.example
Legacy client
Transitional React frontend with separate localization.
- Legacy React client · Separate client runtime and localization catalog.
client/src/index.js - Legacy i18n catalog
client/src/i18n/config.js
Connections 24
- App shell → Farmer dashboard: frames
- App shell → Auth state: provides
- App shell → Language context: provides
- Farmer dashboard → AI and crop guidance: links to
- Farmer dashboard → Weather, market, schemes: links to
- Farmer dashboard → Marketplace flow: links to
- Auth state → OTP signup API: signup and OTP
- OTP signup API → MongoDB: persists identity
- AI and crop guidance → Assistant API client: calls
- Assistant API client → Assistant domain: API requests
- Weather, market, schemes → Market API client: uses feature APIs
- Market API client → Information services: data requests
- Community and support → Engagement domain: API requests
- Marketplace flow → Marketplace domain: browse and checkout
- Express server → JWT auth boundary: applies
- JWT auth boundary → Assistant domain: authorizes
- JWT auth boundary → Engagement domain: authorizes
- JWT auth boundary → Marketplace domain: authorizes
- Assistant domain → MongoDB: conversations and knowledge
- Engagement domain → MongoDB: posts and appointments
- Marketplace domain → MongoDB: listings, carts, orders
- Information services → Agricultural providers: fetches data
- Assistant domain → Agricultural providers: AI integration
- Legacy React client → Legacy i18n catalog: uses