Skip to content

itsbakr/SoilGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SoilGuard - Soil Health Monitoring & Agricultural ROI Platform

A comprehensive agricultural platform that combines satellite data analysis, weather monitoring, and market intelligence to help farmers optimize soil health and maximize ROI through data-driven decision making.

🌟 Features

Core Analysis

  • πŸ›°οΈ Satellite Data Analysis: Google Earth Engine integration for vegetation and soil health monitoring
  • 🌦️ Weather Intelligence: Real-time weather data with agricultural indices (GDD, drought risk, frost alerts)
  • πŸ“ˆ Market Analysis: Crop price monitoring and market sentiment analysis
  • πŸ€– AI-Powered Insights: Intelligent soil health assessment and crop recommendations using Gemini & Claude
  • πŸ“Š Comprehensive Dashboard: Interactive farm management with real-time analytics
  • πŸ”„ Real-time Updates: Automated monitoring with alert systems

πŸ†• Spatial Zone Analysis

  • πŸ—ΊοΈ Dynamic Grid System: Auto-generates analysis zones based on farm size
    • < 2 ha: 2Γ—2 grid (4 zones) using Sentinel-2 (10m resolution)
    • 2-10 ha: 3Γ—3 grid (9 zones) using Sentinel-2 (10m resolution)
    • 10-50 ha: 4Γ—4 grid (16 zones) using Landsat (30m resolution)
    • 50+ ha: 5Γ—5 grid (25 zones) using Landsat (30m resolution)
  • 🎯 Zone-Level Recommendations: AI agents provide specific actions for each problem zone
  • πŸ”₯ Interactive Health Map: Satellite imagery overlay with color-coded zones showing exactly WHERE problems are

πŸ†• Analysis History & Persistence

  • πŸ’Ύ Database Storage: All soil health and ROI analyses are saved to Supabase
  • πŸ“œ Analysis History: View and compare past analyses for trend tracking
  • πŸ” Historical Insights: Click any past analysis to view full details
  • πŸ“Š Trend Analysis: Track farm health improvements over time

πŸ› οΈ Tech Stack

Frontend:

  • Next.js 14 (App Router)
  • TypeScript
  • Tailwind CSS
  • React Components

Backend:

  • FastAPI (Python)
  • Supabase (Database & Auth)
  • Google Earth Engine API
  • OpenWeatherMap API
  • Various commodity price APIs

AI & Analysis:

  • Google Gemini API
  • Anthropic Claude API
  • Custom satellite data processing
  • Agricultural algorithms

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Python 3.11+
  • Git

1. Clone the Repository

git clone https://github.com/yourusername/larmms.git
cd larmms

2. Environment Setup

Copy the environment template and configure your API keys:

cp env.template .env
# Edit .env with your actual API keys (see API Setup section below)

3. Backend Setup

cd backend
pip install -r requirements.txt
uvicorn main:app --reload --host 0.0.0.0 --port 8000

4. Frontend Setup

cd frontend
npm install
npm run dev

5. Database Setup

# Run Supabase migrations
supabase db push

πŸ”‘ API Setup Guide

Required APIs

1. Supabase (Required)

Purpose: Database, Authentication, Real-time subscriptions

Setup Steps:

  1. Go to supabase.com
  2. Create a new project
  3. Go to Settings β†’ API
  4. Copy your Project URL and API keys

Environment Variables:

NEXT_PUBLIC_SUPABASE_URL=your_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key

Cost: Free tier (up to 50MB database, 100MB file storage)


Optional APIs (Graceful Fallbacks Available)

2. Google Earth Engine (Optional)

Purpose: Satellite imagery analysis for soil and vegetation monitoring

Setup Steps:

  1. Go to Google Cloud Console
  2. Create a new project
  3. Enable Earth Engine API
  4. Set up authentication:
    pip install earthengine-api
    earthengine authenticate

Environment Variables:

GOOGLE_CLOUD_PROJECT_ID=your_project_id

Cost: Free for research/non-commercial (25,000 API calls/day)

3. OpenWeatherMap (Optional)

Purpose: Weather data and agricultural forecasting

Setup Steps:

  1. Go to OpenWeatherMap
  2. Sign up for free account
  3. Generate API key

Environment Variables:

OPENWEATHERMAP_API_KEY=your_api_key

Cost: Free tier (1,000 calls/day), $40/month for 100k calls

4. Commodity Price APIs (Optional) - Multiple Free Tiers Available

4a. Alpha Vantage (RECOMMENDED)

  • Website: alphavantage.co
  • Cost: 25 requests/day FREE, then $49.99/month unlimited
  • Perfect for development and light production use
  • Variable: ALPHA_VANTAGE_API_KEY

4b. Twelve Data (Best Free Tier)

  • Website: twelvedata.com/pricing
  • Cost: 800 requests/day FREE, excellent coverage
  • Variable: TWELVE_DATA_API_KEY

4c. Financial Modeling Prep

4d. Commodities API (Paid Only)

  • Website: commodities-api.com
  • Cost: 7-day free trial only, then $49.99/month minimum
  • Variable: COMMODITIES_API_KEY

5. AI APIs (Optional)

5a. Google Gemini

  • Website: Google AI Studio
  • Cost: Free tier (15 requests/minute), pay-per-use beyond
  • Variable: GOOGLE_GEMINI_API_KEY

5b. Anthropic Claude

5c. OpenAI

  • Website: platform.openai.com
  • Cost: Pay-per-use ($0.50-$20/million tokens depending on model)
  • Variable: OPENAI_API_KEY

πŸ’° Cost Breakdown

Free Tier (Recommended for Development)

  • Supabase: Free
  • Google Earth Engine: Free (research use)
  • OpenWeatherMap: Free (1k calls/day)
  • All other APIs: Demo data fallbacks
  • Total: $0/month

Production Tier (Recommended for Live Usage)

  • Supabase Pro: $25/month
  • OpenWeatherMap: $40/month (100k calls)
  • Alpha Vantage: $49.99/month OR use free tier (25 calls/day)
  • AI APIs: ~$10-50/month (depending on usage)
  • Total: ~$75-165/month (or ~$75/month with free commodity API tier)

πŸ—οΈ Project Structure

SoilGuard/
β”œβ”€β”€ frontend/                    # Next.js frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                # App router pages
β”‚   β”‚   β”‚   └── dashboard/      # Farm management pages
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Analysis/       # SoilHealthDisplay, ROIDisplay, AnalysisHistory, ZoneMapOverlay
β”‚   β”‚   β”‚   β”œβ”€β”€ Map/            # Interactive maps and location picker
β”‚   β”‚   β”‚   └── FarmerDashboard/# Health gauges, action cards, zone alerts
β”‚   β”‚   └── lib/                # API client, Supabase config, utilities
β”œβ”€β”€ backend/                    # FastAPI backend application
β”‚   β”œβ”€β”€ routers/
β”‚   β”‚   β”œβ”€β”€ analysis.py        # Soil health, ROI, zonal analysis endpoints + history
β”‚   β”‚   β”œβ”€β”€ farms.py           # Farm CRUD operations
β”‚   β”‚   └── auth.py            # Authentication endpoints
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ satellite_service.py    # Google Earth Engine integration
β”‚   β”‚   β”œβ”€β”€ spatial_grid.py         # πŸ†• Dynamic zone grid generation
β”‚   β”‚   β”œβ”€β”€ soil_health_agent.py    # AI soil analysis with zone recommendations
β”‚   β”‚   β”œβ”€β”€ roi_agent.py            # AI crop ROI analysis
β”‚   β”‚   └── ai_config.py            # Gemini + Claude configuration
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ database.py             # πŸ†• Supabase client for persistence
β”‚   β”‚   └── satellite_calculations.py
β”‚   └── requirements.txt
β”œβ”€β”€ supabase/
β”‚   └── migrations/
β”‚       β”œβ”€β”€ 001_initial_schema.sql      # Users, farms tables
β”‚       └── 002_analysis_tables.sql     # πŸ†• soil_health_analyses, roi_analyses tables
β”œβ”€β”€ backend/env.example         # Backend environment template
β”œβ”€β”€ frontend/env.example        # Frontend environment template
└── README.md

πŸ§ͺ Testing the Platform

1. Check Service Status

curl http://localhost:8000/health
curl http://localhost:8000/api/v1/analysis/status

2. Test Farm Creation

  1. Open http://localhost:3000
  2. Register/Login
  3. Add a new farm with pin drop location
  4. View satellite analysis

3. Test Analysis Pipeline

The platform automatically processes:

  • Satellite vegetation indices (NDVI, NDWI, SAVI, EVI, etc.)
  • Zone-based health scoring (dynamic grid based on farm size)
  • Weather risk assessment
  • Market price analysis
  • AI-powered recommendations with zone-specific actions

4. Test Analysis History

  1. Run a complete analysis on a farm
  2. Expand the "Analysis History" section on the farm page
  3. View past analyses and click to see full details
  4. Compare trends over time

πŸš€ Deployment

Frontend (Vercel)

# Deploy to Vercel
npm run build
vercel --prod

Backend (Railway/Fly.io)

# Deploy to Railway
railway login
railway init
railway up

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Built with ❀️ for sustainable agriculture and data-driven farming

About

Soil Health Monitoring & Agricultural ROI Platform with AI-powered analysis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors