A complete, production-ready Market Price Tracking system with backend API and Android frontend for agricultural market price monitoring.
- Live Data Integration: eNAM, AGMARKNET, Data.gov.in APIs
- Data Normalization: Unified format across different sources
- Caching: Redis + in-memory LRU cache
- Rate Limiting: Configurable delays between API calls
- Scheduled Refresh: Automatic updates every 24 hours
- Demo Mode: Fallback data when APIs unavailable
- Error Handling: Graceful degradation
- Market Dashboard: Two stacked dashboards (Government Subsidy + Price Tracking)
- TabLayout + ViewPager2: Buy/Sell sections
- Buy Section: Existing categories (pesticides, seeds, fertilizers) + product grid
- Sell Section: State/crop selection, price cards, charts, refresh functionality
- Material UI: Modern design with CardViews, chips, icons
- WorkManager: Background refresh every 24 hours
- Demo Mode: Works without backend connection
/
βββ backend/ # Node.js API server
β βββ src/
β β βββ connectors/ # API connectors (eNAM, AGMARKNET, Data.gov.in)
β β βββ data/ # Demo data and mappings
β β βββ routes/ # API endpoints
β β βββ services/ # Business logic
β β βββ utils/ # Utilities (cache, logger, scheduler)
β βββ tests/ # Unit tests
β βββ docker-compose.yml # Docker setup
β βββ README.md # Backend documentation
βββ app/ # Android application
β βββ src/main/
β β βββ java/ # Java source code
β β βββ res/ # XML layouts and resources
β βββ build.gradle.kts # Android build configuration
βββ README.md # This file
-
Install Dependencies
cd backend npm install -
Configure Environment
cp env.example .env # Edit .env with your API keys -
Run in Demo Mode
npm run dev # Server runs on http://localhost:3000
-
Open in Android Studio
- Import the project
- Sync Gradle files
- Build and run
-
Test the App
- Navigate to Market tab
- Switch between Buy/Sell tabs
- Test price tracking in Sell tab
GET /api/states- List all statesGET /api/states/:id/crops- Get crops for stateGET /api/prices/local?state_id=&crop_id=- Local market pricesGET /api/prices/government?crop_id=- Government MSPGET /api/prices/comparison?state_id=&crop_id=- Combined data
GET /api/demo- Demo data infoGET /api/demo/prices/local?state_id=&crop_id=- Demo local pricesGET /api/demo/prices/government?crop_id=- Demo government prices
MarketActivity- Main market page with TabLayout + ViewPager2ProductDetailActivity- Product details (existing)
BuyFragment- Product categories and gridSellFragment- Price tracking dashboard
MarketPriceService- API communicationWorkManager- Background refresh
ProductAdapter- Product gridCategoryAdapter- Category gridPriceHistoryAdapter- Price history chart
- Small card showing MSP info
- Subsidy information
- Quick reference data
- State selection dropdown
- Crop selection (state-dependent)
- Price display cards:
- Local market prices (min, modal, max)
- Government MSP
- Absolute & percentage differences
- Last updated timestamp
- Price history chart (7 days)
- Manual refresh button
- Auto-refresh every 24 hours
- CardViews with elevation
- Rounded corners
- Color-coded price changes
- Responsive layouts
- Modern typography
// Example connector usage
const enamConnector = require('./connectors/enamConnector');
const prices = await enamConnector.fetchPrices('Maharashtra', 'Tomato');// Example connector usage
const agmarkConnector = require('./connectors/agmarkConnector');
const prices = await agmarkConnector.fetchPrices('Maharashtra', 'Tomato');// Example connector usage
const datagovConnector = require('./connectors/datagovConnector');
const msp = await datagovConnector.fetchMSP('Tomato');cd backend
npm test# Get states
curl "http://localhost:3000/api/states"
# Get prices
curl "http://localhost:3000/api/prices/comparison?state_id=maharashtra&crop_id=tomato"- Unit tests for adapters and services
- Instrumentation tests for fragments
- UI tests for user interactions
cd backend
docker-compose up -dThis starts:
- Node.js API server
- Redis cache
- Scheduled price refresh
- Android App requests price data
- Backend API checks cache first
- If cache miss, calls external APIs (eNAM, AGMARKNET, Data.gov.in)
- Normalization layer converts to unified format
- Caching layer stores result
- Android App displays formatted data
- WorkManager refreshes data every 24 hours
- eNAM API key (https://enam.gov.in)
- AGMARKNET API key (https://agmarknet.gov.in)
- Data.gov.in API key (https://data.gov.in)
DEMO_MODE=true # Use demo data
REDIS_URL=redis://localhost:6379 # Redis connection
RATE_LIMIT_DELAY_MS=1000 # API rate limiting
CACHE_TTL_SECONDS=3600 # Cache TTL- Set
NODE_ENV=production - Configure Redis
- Add all API keys
- Use HTTPS
- Implement rate limiting
- Sign APK for release
- Configure ProGuard
- Add crash reporting
- Performance monitoring
- Health check endpoint
- API status monitoring
- Cache hit rates
- Error logging
- Crash reporting
- Performance metrics
- User analytics
- Network monitoring
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
MIT License - see LICENSE file for details.
-
API Keys Not Working
- Verify registration status
- Check key format
- Test with curl first
-
No Data Available
- Enable demo mode
- Check API endpoints
- Verify state/crop names
-
Android Build Issues
- Sync Gradle files
- Check dependencies
- Clean and rebuild
- Backend: Set
LOG_LEVEL=debug - Android: Enable debug logging
For questions or support, please open an issue in the repository.
Note: This is a complete, production-ready implementation with both backend and Android components. The system works out-of-the-box in demo mode and can be easily configured for live API integration.