Production-grade crop simulation chatbot with DSSAT (Decision Support System for Agrotechnology Transfer) integration.
This project provides a complete solution for interacting with DSSAT simulation data through a modern chatbot interface. The system ingests DSSAT summary CSV files, stores metadata in PostgreSQL with PostGIS spatial support, and prepares embeddings for future LLM integration.
┌─────────────────────────────────────────────────────────────┐
│ Frontend (Next.js) │
├─────────────────────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Chat │ │ Input │ │ Output │ │ UI │ │
│ │ Interface│ │ Form │ │ Display │ │ Components│ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
↓ ↑
┌─────────────────────────────────────────────────────────────┐
│ Backend (FastAPI) │
├─────────────────────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ API │ │ Services │ │ Repos │ │ Models │ │
│ │ Routes │→ │ Layer │→ │ Layer │→ │ (ORM) │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
↓ ↓
┌──────────┐ ┌──────────┐
│PostgreSQL│ │ Qdrant │
│ + PostGIS│ │ │
└──────────┘ └──────────┘
DSSAT-RAG/
├── backend/ # FastAPI Python backend
│ ├── app/
│ │ ├── api/ # API endpoints
│ │ ├── core/ # Core configuration
│ │ ├── db/ # Database setup
│ │ ├── models/ # SQLAlchemy models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── repositories/# Repository pattern
│ │ ├── services/ # Service layer
│ │ ├── parsers/ # Data parsers
│ │ ├── mappers/ # Data mappers
│ │ └── utils/ # Utilities
│ ├── alembic/ # Database migrations
│ ├── requirements.txt
│ ├── Dockerfile
│ └── docker-compose.yml
├── frontend/ # Next.js frontend
│ ├── pages/
│ ├── components/
│ └── services/
├── n8n/ # n8n workflow files
├── qdrant_storage/ # Qdrant data storage
└── sample_files/ # Sample DSSAT files
- Async API: FastAPI with async support for high performance
- Spatial Database: PostgreSQL + PostGIS for location-based queries
- Repository Pattern: Clean separation of concerns
- Service Layer: Business logic separation
- Pydantic Models: Type validation and serialization
- Database Migrations: Alembic for schema management
DSSAT → summary.csv → Google Drive → n8n webhook → POST /api/v1/ingest → FastAPI
- UUID primary key
- Spatial data with PostGIS geometry
- Agricultural metadata (crop, cultivar, irrigation)
- Temporal data (planting/harvest dates)
- Foreign key to simulations
- Variable code, value, unit
- Python 3.10+
- Node.js 18+ (for frontend)
- PostgreSQL 14+ with PostGIS extension
- Docker and Docker Compose (optional)
cd backend
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your database credentials
# Run migrations
alembic upgrade head
# Start the application
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd frontend
# Install dependencies
npm install
# Start development server
npm run devdocker-compose up -dOnce the backend is running:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
GET /health/status- Health check endpointGET /- Root endpoint
-
POST /api/v1/ingest/- Ingest a DSSAT summary CSV file- Request:
multipart/form-datawithfilefield - Response: Simulation ID and status
- Request:
-
POST /api/v1/ingest/batch- Ingest multiple CSV files- Request:
multipart/form-datawithfilesfield - Response: List of results with simulation IDs
- Request:
| Column | Type | Description |
|---|---|---|
| simulation_id | UUID | Primary key |
| experiment_name | VARCHAR(255) | Experiment name |
| run_name | VARCHAR(255) | Run name |
| country | VARCHAR(100) | Country code |
| state | VARCHAR(100) | State/region |
| district | VARCHAR(100) | District |
| ecological_zone | VARCHAR(255) | Ecological zone |
| latitude | FLOAT | Latitude (WGS84) |
| longitude | FLOAT | Longitude (WGS84) |
| location | Geometry(Point,4326) | PostGIS geometry |
| geohash | VARCHAR(50) | Geohash representation |
| crop | VARCHAR(100) | Crop type |
| cultivar | VARCHAR(255) | Cultivar name |
| irrigation | VARCHAR(100) | Irrigation method |
| nitrogen_level | VARCHAR(100) | Nitrogen level |
| planting_stage | VARCHAR(100) | Planting stage |
| planting_date | DATE | Planting date |
| harvest_date | DATE | Harvest date |
| simulation_year | INT | Simulation year |
| harvest_area | FLOAT | Harvested area (ha) |
| Column | Type | Description |
|---|---|---|
| id | SERIAL | Primary key |
| simulation_id | UUID | Foreign key to simulations |
| variable_code | VARCHAR(100) | Variable code |
| value | FLOAT | Variable value |
| unit | VARCHAR(50) | Unit of measurement |
# Create new migration
alembic revision -m "migration message"
# Apply migrations
alembic upgrade head
# Downgrade migrations
alembic downgrade -1- Python: PEP 8 with type hints
- TypeScript/React: ESLint and Prettier
- LLM Integration: Chatbot functionality using LLMs
- Vector Database: Qdrant integration for embeddings
- CDE Support: Crop Data Exchange format support
- Advanced Spatial Queries: PostGIS spatial operations
- Real-time Processing: WebSocket support for real-time updates
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
- DSSAT team for the crop simulation models
- FastAPI community for the excellent web framework
- SQLAlchemy and Alembic communities for database tools