A comprehensive system for extracting, managing, and serving agricultural crop data through multiple interfaces. Features PDF document processing with LLM-powered analysis, a web dashboard for data management, and a conversational API gateway for client applications.
ββββββββββββββββββββββββββ ββββββββββββββββββββββββββ ββββββββββββββββ
β Web Panel β β Chatbot API β β MongoDB β
β (Next.js) β β (FastAPI) β β (Docker) β
β Port: 3000 βββββΊβ Port: 8000 βββββΊβ Port 27017 β
ββββββββββ¬ββββββββββββββββ ββββββββββββββββββββββββββ ββββββββββββββββ
β child_process
βΌ
ββββββββββββββββββββββββββ
β finder_system β
β (Python Scripts) β
ββββββββββββββββββββββββββ
- finder_system/ - Python backend for PDF processing and LLM extraction
- web-panel/ - Next.js dashboard for managing the extraction pipeline
- chatbot/ - FastAPI RAG chatbot for crop information queries (gateway for frontends)
- docs/ - Source PDF documents
- Python 3.10+
- Node.js 18+
- Docker (for MongoDB in development)
- API keys for at least one LLM provider (Google, Anthropic, or OpenAI)
python -m venv venv
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
pip install -r requirements.txtcd web-panel
npm install# From project root
docker compose up -d# Root .env (for CLI usage)
GOOGLE_API_KEY=your_google_api_key_here
# web-panel/.env.local (for web panel)
MONGODB_URI=mongodb://localhost:27017/thesis_panelcd web-panel
npm run db:migrate
npm run db:seedcd web-panel
npm run devProcess a PDF directly from the command line:
python main.py ".\docs\FAO-Crop Soil Requirements.pdf"This will:
- Extract text from the PDF
- Process and chunk the text
- Extract agricultural information using AI
- Save results to JSON
- Crop names and scientific names
- Soil requirements (types, pH, drainage)
- Climate conditions (temperature, rainfall, humidity)
- Nutrient requirements (N, P, K, micronutrients)
- Planting information (season, method, spacing, duration)
- Pests and diseases with treatments
- Yield data
- Regional growing information
- Farming practice recommendations
Thesisv2/
βββ finder_system/ # Python extraction engine
β βββ llm_extractor/ # LLM adapters (Claude, Gemini, OpenAI)
β βββ web_scripts/ # Scripts called by web panel
β βββ ...
βββ web-panel/ # Next.js dashboard
β βββ app/ # Pages and API routes
β βββ components/ # UI components
β βββ lib/ # Types, DB models, hooks
β βββ lib/entities/ # Entity definitions (types + models)
β βββ services/ # Python runner, token rotation
β βββ scripts/ # Migrations and seed scripts
βββ chatbot/ # FastAPI chatbot (RAG-based)
β βββ api.py # FastAPI endpoints
β βββ crop_store.py # Crop data loading and search
β βββ rag_engine.py # RAG logic and LLM integration
βββ docs/ # Source PDF documents
βββ extracted/ # Extracted crop data (JSON)
βββ docker-compose.yml # Dev MongoDB container
βββ requirements.txt # Python dependencies
Ensure .env file exists with your provider's API key.
Check Docker is running: docker compose ps
Ensure virtual environment is activated and dependencies installed.
A lightweight FastAPI-based agricultural chatbot using Retrieval-Augmented Generation (RAG) for crop information and farming recommendations. This is the gateway for frontend applications to access crop data via a conversational interface.
βββββββββββββββββββ βββββββββββββββββββββ
β Frontend/ β β Chatbot API β
β Mobile App βββββΊβ (FastAPI) β
β β β Port: 8000 β
βββββββββββββββββββ ββββββββββ¬βββββββββββ
β
βΌ
βββββββββββββββββββββ
β MongoDB β
β (Crop Data) β
βββββββββββββββββββββ
# Run the chatbot API (from project root)
python -m uvicorn chatbot.api:app --reload
# Access API documentation
# Swagger UI: http://localhost:8000/docs
# ReDoc: http://localhost:8000/redoc# Root .env (for chatbot LLM usage and MongoDB connection)
ANTHROPIC_API_KEY=your_anthropic_api_key_here
# OR
GOOGLE_API_KEY=your_google_api_key_here
# MongoDB connection (required)
MONGODB_URI=mongodb://localhost:27017/thesis_panel
MONGODB_NAME=thesis_panel| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check (status, crops loaded, LLM available) |
POST |
/chat |
Chat with agricultural advisor |
GET |
/crops |
List all available crops |
GET |
/crops/{crop_name} |
Get detailed crop information |
POST |
/search |
Search crops by keyword |
GET |
/sources |
List source documents used |
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{
"message": "What are the best conditions for growing wheat?",
"top_k": 3,
"include_context": false
}'{
"answer": "Wheat thrives in temperate climates with moderate rainfall...",
"crops_used": ["Wheat"],
"context": null,
"llm_used": true
}The chatbot API requires extracted crop data to function. Ensure you have:
- Run the extraction pipeline via the web panel to generate crop data
- Extracted data in
extracted/directory as JSON files (auto-loaded on startup) - MongoDB available (same connection as web panel)
The API will:
- Load all crop data from extracted JSON files on startup
- Provide RAG-based responses using the extracted agricultural data
- Use your configured LLM (Claude, Gemini, or Ollama) to enhance responses with conversational AI
- Embedded, not separate: Since the chatbot API is small and only requires database access, it's included in this repository rather than as a separate service
- Complements web panel: Works alongside the web panel for data extraction and validation
- Production ready: Can be deployed independently or alongside the web panel
- CORS enabled: Configured to accept requests from any origin (configure for production)
For detailed API documentation, see API_DOCUMENTATION.md