Skip to content

Latest commit

Β 

History

History
377 lines (276 loc) Β· 7.19 KB

File metadata and controls

377 lines (276 loc) Β· 7.19 KB

Setup Guide πŸ› οΈ

Complete step-by-step guide to set up KisanAI for development.


πŸ“‹ Prerequisites

Before starting, ensure you have:

  1. Node.js 18+ - Download

    node --version  # Should be v18.0.0 or higher
  2. npm 9+ - Download

    npm --version  # Should be 9.0.0 or higher
  3. Git - Download

    git --version
  4. A Code Editor - VS Code recommended

  5. MongoDB - Local or cloud instance


πŸš€ Quick Start (5 minutes)

1. Clone Repository

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

2. Install Dependencies

npm install

3. Setup Environment

cp .env.example .env.local
# Edit .env.local with your API keys

4. Start Development Server

npm run dev

5. Open Browser

Visit: http://localhost:3000


πŸ”‘ API Keys Setup

Get Required API Keys

1. Google Gemini API

# 1. Go to https://ai.google.dev/
# 2. Click "Get API Key"
# 3. Create new project
# 4. Copy API key
# 5. Add to .env.local:
NEXT_PUBLIC_GEMINI_API_KEY=your_key_here

2. ElevenLabs Voice API

# 1. Sign up at https://elevenlabs.io/
# 2. Go to Profile β†’ API Key
# 3. Copy API key
# 4. Add to .env.local:
ELEVENLABS_API_KEY=your_key_here

3. MongoDB Atlas

# 1. Create account at https://www.mongodb.com/cloud/atlas
# 2. Create cluster
# 3. Get connection string
# 4. Add to .env.local:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/kisanai

4. Weather API (Optional)

# 1. Sign up at https://openweathermap.org/
# 2. Get free API key
# 3. Add to .env.local:
WEATHER_API_KEY=your_key_here

πŸ“ Environment Variables

Create .env.local file:

# Database
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/kisanai

# Gemini AI
NEXT_PUBLIC_GEMINI_API_KEY=your_gemini_key
GEMINI_MODEL=gemini-pro-vision

# Voice API
ELEVENLABS_API_KEY=your_elevenlabs_key

# Weather API
WEATHER_API_KEY=your_weather_key

# App Config
NEXT_PUBLIC_APP_URL=http://localhost:3000
NODE_ENV=development

See .env.example for all options.


πŸ§ͺ Verify Installation

Run Tests

npm test

Expected output:

PASS  src/__tests__/components/Header.test.jsx
PASS  src/__tests__/pages/Home.test.jsx
...
Tests:       X passed, Y total

Run Linter

npm run lint

Expected: No errors

Build Project

npm run build

Expected: Build completes successfully


πŸ–₯️ Development Commands

Start Development Server

npm run dev
# Server runs on http://localhost:3000
# Auto-reloads on file changes

Run Tests

# Run all tests once
npm test

# Run in watch mode (re-run on changes)
npm run test:watch

# Generate coverage report
npm run test:coverage

Lint Code

npm run lint

Format Code

npm run format

Build for Production

npm run build

Start Production Server

npm start

πŸ“‚ Project Structure

KisanAI/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js pages
β”‚   β”‚   β”œβ”€β”€ page.jsx           # Home page
β”‚   β”‚   β”œβ”€β”€ layout.jsx         # Root layout
β”‚   β”‚   β”œβ”€β”€ api/              # API routes
β”‚   β”‚   β”œβ”€β”€ voice-assistant/  # Voice feature
β”‚   β”‚   β”œβ”€β”€ crop-analysis/    # Crop analysis
β”‚   β”‚   β”œβ”€β”€ weather/          # Weather feature
β”‚   β”‚   β”œβ”€β”€ market-prices/    # Market prices
β”‚   β”‚   └── schemes/          # Government schemes
β”‚   β”‚
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”‚   β”œβ”€β”€ ui/               # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ layout/           # Layout components
β”‚   β”‚   └── [features]/       # Feature components
β”‚   β”‚
β”‚   β”œβ”€β”€ hooks/                # Custom hooks
β”‚   β”‚   β”œβ”€β”€ useSpeechRecognition.js
β”‚   β”‚   β”œβ”€β”€ useSpeechSynthesis.js
β”‚   β”‚   └── [custom hooks]/
β”‚   β”‚
β”‚   β”œβ”€β”€ lib/                  # Utilities & libraries
β”‚   β”‚   β”œβ”€β”€ mongodb.ts       # Database
β”‚   β”‚   β”œβ”€β”€ geminiTranslate.ts # AI
β”‚   β”‚   └── [utilities]/
β”‚   β”‚
β”‚   β”œβ”€β”€ types/               # TypeScript types
β”‚   β”œβ”€β”€ contexts/            # React contexts
β”‚   β”œβ”€β”€ data/                # Static data
β”‚   └── __tests__/           # Tests
β”‚
β”œβ”€β”€ public/                   # Static files
β”œβ”€β”€ docs/                     # Documentation
β”œβ”€β”€ .github/                 # GitHub config
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ tailwind.config.js
β”œβ”€β”€ jest.config.js
└── next.config.js

πŸ”§ Configuration Files

TypeScript Config (tsconfig.json)

  • Strict mode enabled
  • Path aliases configured: @/* β†’ ./src/*
  • React JSX support

Tailwind CSS (tailwind.config.js)

  • Custom colors for farming theme
  • Responsive design
  • Dark mode support

Jest (jest.config.js)

  • React Testing Library
  • jsdom environment
  • Coverage collection

ESLint (eslint.config.mjs)

  • Next.js recommended rules
  • TypeScript support
  • Code quality checks

πŸ› Troubleshooting

Port 3000 Already in Use

# Kill process on port 3000
# macOS/Linux:
lsof -ti:3000 | xargs kill -9

# Windows:
netstat -ano | findstr :3000
taskkill /PID [PID] /F

# Or use different port:
npm run dev -- -p 3001

Module Not Found Errors

# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

MongoDB Connection Failed

# Check connection string in .env.local
# Verify MongoDB is running
# Test with MongoDB Compass

# If using local MongoDB:
mongod  # Start MongoDB server

# If using MongoDB Atlas:
# - Check IP whitelist
# - Verify username/password
# - Check connection string format

Gemini API Key Invalid

# Regenerate key at https://ai.google.dev/
# Ensure key is in .env.local
# Verify NEXT_PUBLIC_ prefix for client-side keys

Tests Failing

# Run tests with verbose output
npm test -- --verbose

# Run specific test file
npm test -- useSpeechRecognition.test.jsx

# Check for console errors
# Review test output for specific errors

πŸ“š Next Steps

  1. Read CONTRIBUTING.md - Learn contribution process
  2. Check ARCHITECTURE.md - Understand codebase
  3. Review CODING_STANDARDS.md - Code style
  4. Find Good First Issues - Start contributing

🀝 Need Help?


Ready to start developing? Create your first PR!