A robust, scalable API for crop disease detection, powered by AI and built with NestJS.
A robust and scalable NestJS server for the Agrinix crop disease detection application. This server processes crop leaf images through advanced AI models to detect diseases and provide comprehensive agricultural insights to help farmers protect their crops.
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Mobile App โ โ Agrinix โ โ External โ
โ (Client) โโโโโบโ Server โโโโโบโ Services โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ PostgreSQL โ โ Roboflow โ
โ Database โ โ AI Models โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Redis Cache โ โ DeepSeek AI โ
โ & Sessions โ โ Analysis โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Before you begin, ensure you have the following installed:
git clone https://github.com/techpepson/agrinix-server.git
cd agrinix-server
npm install
Create a .env file in the root directory:
cp .env.example .env
Fill in the required environment variables:
# Database Configuration
DATABASE_URL="postgresql://username:password@localhost:5432/agrinix_db"
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
REDIS_USER=default
# JWT Configuration
JWT_SECRET=your_jwt_secret_key
JWT_SECRET_OR_KEY=your_jwt_secondary_key
# Email Configuration
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Roboflow Configuration
ROBOFLOW_PRIVATE_API_KEY=your_roboflow_private_key
ROBOFLOW_PUBLISHABLE_API_KEY=your_roboflow_publishable_key
ROBOFLOW_ENDPOINT=https://serverless.roboflow.com/infer/workflows/agrinix/agrinix-workflow-3
# OpenRouter Configuration
OPENROUTER_API_KEY=your_openrouter_api_key
# Application Configuration
PORT=3000
SERVER_BASE_URL=http://localhost:3000
AGRINIX_LOGO_URL=https://your-domain.com/logo.jpg
CREATE DATABASE agrinix_db;
npx prisma migrate dev
npx prisma generate
redis-server
# Development mode with hot reload
npm run start:dev
# Production mode
npm run start:prod
# Debug mode
npm run start:debug
The server will be available at http://localhost:8000
POST /api/auth/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "securepassword123"
}
POST /auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "securepassword123"
}
POST /api/crops/roboflow-detect-disease
Authorization: Bearer <jwt_token>
Content-Type: multipart/form-data
{
"image": <file>
}
{
"success": true,
"data": {
"diseaseClass": "healthy",
"confidence": 0.95,
"description": "Detailed disease description",
"causes": ["Environmental factors", "Pathogen presence"],
"symptoms": ["Leaf spots", "Wilting"],
"prevention": ["Proper spacing", "Fungicide application"],
"treatment": ["Remove infected plants", "Apply treatment"]
}
}
POST /api/community/messages
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"messageTitle": "Help with tomato disease",
"messageBody": "I found spots on my tomato leaves...",
"messageImage": "optional_image_url"
}
GET /api/community/messages
Authorization: Bearer <jwt_token>
src/
โโโ auth/ # Authentication module
โโโ crops/ # Crop disease detection
โโโ community/ # Community features
โโโ notifications/ # Notification system
โโโ processors/ # Background job processors
โโโ helpers/ # Utility services
โโโ config/ # Configuration management
โโโ guards/ # Authentication guards
โโโ dto/ # Data transfer objects
โโโ prisma/ # Database service
# Development
npm run start:dev # Start development server
npm run start:debug # Start with debug mode
# Production
npm run build # Build the application
npm run start:prod # Start production server
# Testing
npm run test # Run unit tests
npm run test:watch # Run tests in watch mode
npm run test:e2e # Run end-to-end tests
npm run test:cov # Run tests with coverage
# Code Quality
npm run lint # Run ESLint
npm run format # Format code with Prettier
# Database
npx prisma migrate dev # Run database migrations
npx prisma generate # Generate Prisma client
npx prisma studio # Open Prisma Studio
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | โ |
REDIS_HOST |
Redis server host | โ |
REDIS_PORT |
Redis server port | โ |
JWT_SECRET |
JWT signing secret | โ |
EMAIL_USER |
SMTP email username | โ |
EMAIL_PASS |
SMTP email password | โ |
CLOUDINARY_CLOUD_NAME |
Cloudinary cloud name | โ |
CLOUDINARY_API_KEY |
Cloudinary API key | โ |
CLOUDINARY_API_SECRET |
Cloudinary API secret | โ |
ROBOFLOW_PRIVATE_API_KEY |
Roboflow private API key | โ |
OPENROUTER_API_KEY |
OpenRouter API key | โ |
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:cov
test/
โโโ app.e2e-spec.ts # End-to-end tests
โโโ jest-e2e.json # Jest E2E configuration
# Build the application
npm run build
# Start production server
npm run start:prod
Create a Dockerfile:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
The application uses NestJS built-in logging with different levels:
error - Error messageswarn - Warning messageslog - General informationdebug - Debug informationgit checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Made with โค๏ธ for farmers and agricultural communities