Skip to content

Latest commit

 

History

History
183 lines (137 loc) · 6.51 KB

File metadata and controls

183 lines (137 loc) · 6.51 KB

RAKSHA Development Notes

Implementation Overview

This MVP was built in record time to demonstrate the RAKSHA concept: an AI-powered crop disease detection system that helps farmers protect their harvests.

Technology Choices

Backend

  • Node.js + Express: Lightweight, fast, and perfect for API services
  • TypeScript: Type safety prevents bugs and improves developer experience
  • Multer: Industry-standard library for handling file uploads
  • In-memory storage: No database needed for MVP, keeps it simple

Frontend

  • Next.js 15: Modern React framework with App Router for excellent performance
  • TypeScript: Consistent type safety across the stack
  • TailwindCSS: Rapid UI development with utility classes
  • Custom animations: Premium feel with CSS animations and gradients

Why Mock AI?

We implemented a mock AI service for several strategic reasons:

  1. Speed: Allows frontend/backend integration without waiting for AI model
  2. Determinism: Consistent results for testing and demo purposes
  3. Flexibility: Easy to swap for real AI later without changing the API contract
  4. Cost: No API credits needed during development

Tradeoffs Made

1. No Database

  • Why: For MVP, we don't need to store historical analyses
  • Trade-off: Can't track user history, trends, or build a knowledge base
  • Next step: Add PostgreSQL or MongoDB to store analyses for analytics

2. Mock AI Service

  • Why: Enables rapid development and testing
  • Trade-off: Not production-ready for actual disease detection
  • Next step: Integrate real AI (see options below)

3. No Authentication

  • Why: Simplifies MVP, reduces scope
  • Trade-off: Anyone can use the service, no user personalization
  • Next step: Add Firebase Auth or NextAuth.js for user management

4. No Image Storage

  • Why: Images processed in-memory only
  • Trade-off: Can't review past images or build training datasets
  • Next step: Store images in AWS S3 or Google Cloud Storage

5. Single Language Support

  • Why: English-only for MVP
  • Trade-off: May limit adoption in non-English speaking regions
  • Next step: Add i18n with translations for Hindi, Spanish, etc.

Next Steps for Production

Phase 1: AI Integration (High Priority)

Option 1: Use Existing API

  • PlantVillage API or similar service
  • Pros: Quick integration, maintained by experts
  • Cons: Ongoing costs, dependency on third party

Option 2: Train Custom Model

  • Use TensorFlow or PyTorch with PlantVillage dataset
  • Pros: Full control, no API costs
  • Cons: Requires ML expertise, GPU resources

Option 3: Cloud Vision AI

  • Google Cloud Vision with custom AutoML model
  • AWS Rekognition Custom Labels
  • Pros: Scalable, managed infrastructure
  • Cons: Ongoing costs, vendor lock-in

Recommended: Start with Option 1 for quick validation, then move to Option 2 for production scale.

Phase 2: Database & Analytics

  • Add PostgreSQL for storing analyses
  • Track accuracy metrics and user feedback
  • Build dashboard for farmers to see history
  • Generate insights (common diseases, seasonal trends)

Phase 3: Mobile App

  • React Native or Flutter app
  • Direct camera integration
  • Offline analysis capability (on-device model)
  • Push notifications for treatment reminders

Phase 4: Advanced Features

  • Multi-crop support (currently optimized for generic crops)
  • Regional disease patterns and alerts
  • Treatment effectiveness tracking
  • Community features (farmers helping farmers)
  • Integration with agricultural supply chains

Phase 5: Scale & Optimization

  • Add caching layer (Redis) for repeated queries
  • CDN for static assets
  • Horizontal scaling with load balancer
  • Rate limiting and API quotas
  • Monitoring and alerting (Datadog, New Relic)

Known Limitations

  1. Mock AI: Current responses are deterministic, not actual disease detection
  2. No validation: Backend doesn't validate if image actually contains a crop
  3. Single image: Can't analyze multiple images or video
  4. No geolocation: Could enhance recommendations based on local conditions
  5. Limited disease database: Only 6 diseases in mock data

Performance Considerations

  • Current: Memory-based, can handle ~100 concurrent requests
  • Bottleneck: Image processing and AI inference
  • Solution: Queue system (Bull/BullMQ) for async processing
  • Scaling: Deploy to AWS Lambda or Google Cloud Run for auto-scaling

Security Considerations

  • CORS: Configured for development, needs production URLs
  • File uploads: Limited to 10MB and image types only
  • No auth: Open to abuse in current form
  • Next steps:
    • Add rate limiting (express-rate-limit)
    • Implement API keys for production
    • Add user authentication
    • Scan uploaded images for malware

Deployment Recommendations

Backend

  • Quick: Railway, Render, or Heroku (1-click deploy)
  • Production: AWS ECS, Google Cloud Run, or DigitalOcean App Platform
  • Environment: Set NODE_ENV=production and configure CORS properly

Frontend

  • Recommended: Vercel (built by Next.js team, zero-config)
  • Alternatives: Netlify, AWS Amplify, Cloudflare Pages
  • Build: npm run build generates optimized static + SSR bundle

Full Stack

  • Docker: Included Dockerfiles can be used with docker-compose
  • Kubernetes: For enterprise scale with auto-scaling

Cost Estimates (Production)

Hosting (handling 10K requests/month):

  • Backend: $7-15/month (Render, Railway)
  • Frontend: $0 (Vercel free tier)
  • Database: $5-15/month (small PostgreSQL instance)

AI Service (varies widely):

  • PlantVillage API: ~$0.01-0.05 per image
  • Google Cloud Vision: ~$1.50 per 1000 images
  • Custom model: Hardware costs only

Total: ~$50-100/month for 10K analyses

Testing Recommendations

  1. Unit tests: Add Jest for backend service logic
  2. Integration tests: Test API endpoints with Supertest
  3. E2E tests: Playwright or Cypress for frontend flows
  4. Load testing: Artillery or k6 for performance benchmarking

Contributing Guidelines

If building on this:

  1. Keep the service abstraction clean (easy to swap AI)
  2. Maintain type safety across the stack
  3. Document API changes in docs/api.md
  4. Follow the existing code style
  5. Test with multiple crop images before deploying

Questions or Issues?

This MVP provides a strong foundation. The architecture is designed for easy extension and scaling. Focus on getting real AI integrated first, then iterate based on farmer feedback.


Built with ❤️ for farmers worldwide 🌱