Spaces:
Running
Running
Add 1 files
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AgriChain | Smart Farming 4.0</title><script src="https://cdn.tailwindcss.com"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"><script src="https://cdn.jsdelivr.net/npm/chart.js"></script><script src="https://cdn.jsdelivr.net/npm/apexcharts"></script><style>@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');:root {--primary: #10b981;--secondary: #3b82f6;--dark: #1f2937;--light: #f9fafb;}body {font-family: 'Poppins', sans-serif;background-color: #f8fafc;}.dashboard-card {transition: all 0.3s ease;border-left: 4px solid var(--primary);}.dashboard-card:hover {transform: translateY(-5px);box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);}.iot-node {animation: pulse 2s infinite;}@keyframes pulse {0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }}.blockchain-block {border-top: 3px solid var(--primary);transition: all 0.3s ease;}.blockchain-block:hover {transform: scale(1.02);box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);}.ai-prediction-card {background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);}.sensor-grid {display: grid;grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));gap: 1rem;}.protocol-badge {font-size: 0.7rem;padding: 0.2rem 0.5rem;border-radius: 1rem;}</style></head><body><div class="min-h-screen bg-gray-50"><!-- Navigation --><nav class="bg-white shadow-sm"><div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"><div class="flex justify-between h-16"><div class="flex items-center"><div class="flex-shrink-0 flex items-center"><i class="fas fa-leaf text-emerald-500 text-2xl mr-2"></i><span class="text-xl font-bold text-gray-800">AgriChain</span></div><div class="hidden sm:ml-6 sm:flex sm:space-x-8"><a href="#" class="border-emerald-500 text-gray-900 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Dashboard</a><a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">IoT Network</a><a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">AI Predictions</a><a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Blockchain</a><a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Settings</a></div></div><div class="hidden sm:ml-6 sm:flex sm:items-center"><div class="relative"><div class="flex space-x-4"><button class="bg-white p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 relative"><i class="fas fa-network-wired h-6 w-6"></i><span class="absolute -top-1 -right-1 h-3 w-3 rounded-full bg-green-500 animate-ping"></span><span class="absolute -top-1 -right-1 h-3 w-3 rounded-full bg-green-500"></span></button><button class="bg-white p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 relative"><i class="fas fa-bell h-6 w-6"></i><span class="absolute -top-1 -right-1 h-4 w-4 rounded-full bg-red-500 text-white text-xs flex items-center justify-center">3</span></button><div class="ml-3 relative"><div><button type="button" class="flex text-sm rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500" id="user-menu-button"><img class="h-8 w-8 rounded-full" src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt=""></button></div></div></div></div></div><div class="-mr-2 flex items-center sm:hidden"><button type="button" class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-emerald-500" id="mobile-menu-button"><i class="fas fa-bars"></i></button></div></div></div><!-- Mobile menu --><div class="sm:hidden hidden" id="mobile-menu"><div class="pt-2 pb-3 space-y-1"><a href="#" class="bg-emerald-50 border-emerald-500 text-emerald-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Dashboard</a><a href="#" class="border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">IoT Network</a><a href="#" class="border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">AI Predictions</a><a href="#" class="border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Blockchain</a><a href="#" class="border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700 block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Settings</a></div><div class="pt-4 pb-3 border-t border-gray-200"><div class="flex items-center px-4"><div class="flex-shrink-0"><img class="h-10 w-10 rounded-full" src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt=""></div><div class="ml-3"><div class="text-base font-medium text-gray-800">John Farmer</div><div class="text-sm font-medium text-gray-500">john@example.com</div></div><button class="ml-auto bg-white flex-shrink-0 p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 relative"><i class="fas fa-bell h-6 w-6"></i><span class="absolute -top-1 -right-1 h-4 w-4 rounded-full bg-red-500 text-white text-xs flex items-center justify-center">3</span></button></div></div></div></nav><!-- Main Content --><main class="py-6 px-4 sm:px-6 lg:px-8"><!-- Header --><div class="mb-6 flex justify-between items-center"><div><h1 class="text-2xl font-bold text-gray-900">Smart Farming 4.0 Dashboard</h1><p class="mt-1 text-sm text-gray-500">Eco-efficient IoT networks with AI predictions and blockchain security</p></div><div class="flex space-x-3"><button class="px-4 py-2 bg-emerald-600 text-white text-sm font-medium rounded-md hover:bg-emerald-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 flex items-center"><i class="fas fa-sync-alt mr-2"></i> Refresh Data</button><button class="px-4 py-2 bg-white border border-gray-300 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 flex items-center"><i class="fas fa-download mr-2"></i> Export</button></div></div><!-- Farm Overview --><div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-6"><!-- IoT Network Status --><div class="bg-white rounded-lg shadow p-6"><div class="flex justify-between items-center mb-4"><h2 class="text-lg font-medium text-gray-900">IoT Network Status</h2><span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full flex items-center"><span class="w-2 h-2 rounded-full bg-green-500 mr-1"></span> All Systems Operational</span></div><div class="grid grid-cols-3 gap-4"><div class="text-center"><div class="mx-auto h-16 w-16 rounded-full bg-green-100 flex items-center justify-center mb-2"><i class="fas fa-satellite-dish text-green-600 text-xl"></i></div><p class="text-sm text-gray-500">Nodes Online</p><p class="text-xl font-semibold text-gray-900">24/24</p></div><div class="text-center"><div class="mx-auto h-16 w-16 rounded-full bg-blue-100 flex items-center justify-center mb-2"><i class="fas fa-battery-three-quarters text-blue-600 text-xl"></i></div><p class="text-sm text-gray-500">Avg. Battery</p><p class="text-xl font-semibold text-gray-900">78%</p></div><div class="text-center"><div class="mx-auto h-16 w-16 rounded-full bg-purple-100 flex items-center justify-center mb-2"><i class="fas fa-signal text-purple-600 text-xl"></i></div><p class="text-sm text-gray-500">Signal Strength</p><p class="text-xl font-semibold text-gray-900">92%</p></div></div><div class="mt-4"><div class="flex justify-between items-center mb-1"><span class="text-sm font-medium text-gray-500">Data Transmission</span><span class="text-xs font-medium text-emerald-600">Eco Protocol v2.1</span></div><div class="w-full bg-gray-200 rounded-full h-2"><div class="bg-emerald-500 h-2 rounded-full" style="width: 92%"></div></div><div class="flex justify-between text-xs text-gray-500 mt-1"><span>0.5 KB/day</span><span>Optimal</span><span>5 KB/day</span></div></div></div><!-- Blockchain Security --><div class="bg-white rounded-lg shadow p-6"><div class="flex justify-between items-center mb-4"><h2 class="text-lg font-medium text-gray-900">Blockchain Security</h2><span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full flex items-center"><i class="fas fa-lock mr-1"></i> Secure</span></div><div class="grid grid-cols-3 gap-4"><div class="text-center"><div class="mx-auto h-16 w-16 rounded-full bg-yellow-100 flex items-center justify-center mb-2"><i class="fas fa-cube text-yellow-600 text-xl"></i></div><p class="text-sm text-gray-500">Blocks</p><p class="text-xl font-semibold text-gray-900">4,892</p></div><div class="text-center"><div class="mx-auto h-16 w-16 rounded-full bg-indigo-100 flex items-center justify-center mb-2"><i class="fas fa-link text-indigo-600 text-xl"></i></div><p class="text-sm text-gray-500">Last Hash</p><p class="text-xs font-mono text-gray-900 truncate">a3f8e2...</p></div><div class="text-center"><div class="mx-auto h-16 w-16 rounded-full bg-red-100 flex items-center justify-center mb-2"><i class="fas fa-shield-alt text-red-600 text-xl"></i></div><p class="text-sm text-gray-500">Integrity</p><p class="text-xl font-semibold text-gray-900">100%</p></div></div><div class="mt-4"><div class="flex justify-between items-center mb-1"><span class="text-sm font-medium text-gray-500">Data Encryption</span><span class="text-xs font-medium text-emerald-600">AES-256</span></div><div class="w-full bg-gray-200 rounded-full h-2"><div class="bg-emerald-500 h-2 rounded-full" style="width: 100%"></div></div></div></div><!-- AI Predictions --><div class="bg-white rounded-lg shadow p-6 ai-prediction-card"><div class="flex justify-between items-center mb-4"><h2 class="text-lg font-medium text-gray-900">AI Predictions</h2><span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full flex items-center"><i class="fas fa-brain mr-1"></i> Active</span></div><div class="space-y-3"><div class="flex items-center"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-green-100 flex items-center justify-center mr-3"><i class="fas fa-tint text-green-600"></i></div><div class="flex-1 min-w-0"><p class="text-sm font-medium text-gray-900 truncate">Next Irrigation</p><p class="text-sm text-gray-500">Field A in 8 hours</p></div><div class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">92% accuracy</div></div><div class="flex items-center"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-yellow-100 flex items-center justify-center mr-3"><i class="fas fa-bug text-yellow-600"></i></div><div class="flex-1 min-w-0"><p class="text-sm font-medium text-gray-900 truncate">Pest Risk</p><p class="text-sm text-gray-500">Low (15%) in Field B</p></div><div class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">87% accuracy</div></div><div class="flex items-center"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center mr-3"><i class="fas fa-seedling text-purple-600"></i></div><div class="flex-1 min-w-0"><p class="text-sm font-medium text-gray-900 truncate">Harvest Yield</p><p class="text-sm text-gray-500">+12% expected</p></div><div class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">85% accuracy</div></div></div></div></div><!-- Detailed Sections --><div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6"><!-- IoT Network Map --><div class="bg-white rounded-lg shadow p-6"><div class="flex justify-between items-center mb-4"><h2 class="text-lg font-medium text-gray-900">IoT Network Map</h2><div class="flex space-x-2"><span class="protocol-badge bg-green-100 text-green-800">LoRaWAN</span><span class="protocol-badge bg-blue-100 text-blue-800">Zigbee</span><span class="protocol-badge bg-purple-100 text-purple-800">NB-IoT</span></div></div><div class="relative h-64 bg-gray-100 rounded-lg overflow-hidden mb-4"><!-- Simulated farm map with IoT nodes --><div class="absolute inset-0 bg-gradient-to-br from-green-50 to-blue-50"><!-- Fields --><div class="absolute top-10 left-10 w-24 h-32 bg-green-100 border-2 border-green-300 rounded-lg"></div><div class="absolute top-16 left-40 w-32 h-24 bg-green-100 border-2 border-green-300 rounded-lg"></div><div class="absolute bottom-16 right-20 w-28 h-20 bg-green-100 border-2 border-green-300 rounded-lg"></div><!-- IoT Nodes --><div class="iot-node absolute top-20 left-20 h-6 w-6 rounded-full bg-emerald-500 flex items-center justify-center text-white"><i class="fas fa-water text-xs"></i></div><div class="iot-node absolute top-24 left-60 h-6 w-6 rounded-full bg-blue-500 flex items-center justify-center text-white"><i class="fas fa-temperature-high text-xs"></i></div><div class="iot-node absolute bottom-24 right-32 h-6 w-6 rounded-full bg-purple-500 flex items-center justify-center text-white"><i class="fas fa-wind text-xs"></i></div><div class="iot-node absolute bottom-32 left-32 h-6 w-6 rounded-full bg-yellow-500 flex items-center justify-center text-white"><i class="fas fa-lightbulb text-xs"></i></div><!-- Gateway --><div class="absolute top-8 right-8 h-10 w-10 rounded-full bg-indigo-600 flex items-center justify-center text-white"><i class="fas fa-wifi"></i></div></div></div><div class="grid grid-cols-2 md:grid-cols-4 gap-2"><div class="text-center"><span class="inline-block h-3 w-3 rounded-full bg-emerald-500"></span><span class="ml-1 text-xs text-gray-600">Moisture</span></div><div class="text-center"><span class="inline-block h-3 w-3 rounded-full bg-blue-500"></span><span class="ml-1 text-xs text-gray-600">Temperature</span></div><div class="text-center"><span class="inline-block h-3 w-3 rounded-full bg-purple-500"></span><span class="ml-1 text-xs text-gray-600">Humidity</span></div><div class="text-center"><span class="inline-block h-3 w-3 rounded-full bg-yellow-500"></span><span class="ml-1 text-xs text-gray-600">Light</span></div></div><div class="mt-4"><div class="flex justify-between items-center"><span class="text-sm font-medium text-gray-600">Network Protocols Efficiency</span><span class="text-xs text-emerald-600">Eco Mode Active</span></div><div class="mt-2 space-y-2"><div><div class="flex justify-between text-xs text-gray-500 mb-1"><span>LoRaWAN</span><span>0.8 KB/day</span></div><div class="w-full bg-gray-200 rounded-full h-2"><div class="bg-green-500 h-2 rounded-full" style="width: 90%"></div></div></div><div><div class="flex justify-between text-xs text-gray-500 mb-1"><span>Zigbee</span><span>1.2 KB/day</span></div><div class="w-full bg-gray-200 rounded-full h-2"><div class="bg-blue-500 h-2 rounded-full" style="width: 85%"></div></div></div><div><div class="flex justify-between text-xs text-gray-500 mb-1"><span>NB-IoT</span><span>0.5 KB/day</span></div><div class="w-full bg-gray-200 rounded-full h-2"><div class="bg-purple-500 h-2 rounded-full" style="width: 95%"></div></div></div></div></div></div><!-- AI Prediction Analysis --><div class="bg-white rounded-lg shadow p-6"><div class="flex justify-between items-center mb-4"><h2 class="text-lg font-medium text-gray-900">AI Prediction Analysis</h2><div class="flex items-center"><span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full mr-2">Model v3.2</span><button class="text-emerald-600 hover:text-emerald-800"><i class="fas fa-cog"></i></button></div></div><div class="mb-4"><div id="aiChart" class="h-48"></div></div><div class="space-y-3"><div class="flex items-start"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-red-100 flex items-center justify-center mr-3 mt-1"><i class="fas fa-exclamation-triangle text-red-600"></i></div><div><p class="text-sm font-medium text-gray-900">Disease Detection</p><p class="text-sm text-gray-500">Early blight detected in 3 tomato plants with 89% confidence. Recommended treatment: Copper fungicide spray.</p></div></div><div class="flex items-start"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center mr-3 mt-1"><i class="fas fa-tint text-blue-600"></i></div><div><p class="text-sm font-medium text-gray-900">Water Optimization</p><p class="text-sm text-gray-500">AI recommends reducing irrigation in Field B by 15% based on soil moisture forecasts.</p></div></div><div class="flex items-start"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-yellow-100 flex items-center justify-center mr-3 mt-1"><i class="fas fa-calendar-alt text-yellow-600"></i></div><div><p class="text-sm font-medium text-gray-900">Harvest Timing</p><p class="text-sm text-gray-500">Optimal harvest window predicted between July 15-18 for maximum yield and quality.</p></div></div></div></div></div><!-- Blockchain Data Integrity --><div class="bg-white rounded-lg shadow overflow-hidden mb-6"><div class="px-6 py-4 border-b border-gray-200"><div class="flex justify-between items-center"><h2 class="text-lg font-medium text-gray-900">Blockchain Data Integrity</h2><button class="px-3 py-1 text-xs bg-emerald-100 text-emerald-700 rounded-full flex items-center"><i class="fas fa-plus mr-1"></i> New Block</button></div></div><div class="divide-y divide-gray-200"><div class="p-4 hover:bg-gray-50 blockchain-block"><div class="flex items-center"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3"><i class="fas fa-cube text-indigo-600"></i></div><div class="flex-1 min-w-0"><p class="text-sm font-medium text-gray-900 truncate">Block #4892</p><div class="flex items-center text-xs text-gray-500"><span class="truncate mr-2">Hash: a3f8e2d4b5c71f9e8a0b6d5c4f3e2a1b</span><span class="flex-shrink-0">2 mins ago</span></div></div><div class="ml-4 flex-shrink-0"><div class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Validated</div></div></div><div class="mt-2 ml-13 grid grid-cols-3 gap-2 text-xs"><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Data Type</p><p class="font-medium">Soil Moisture</p></div><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Field</p><p class="font-medium">A</p></div><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Value</p><p class="font-medium">68%</p></div></div></div><div class="p-4 hover:bg-gray-50 blockchain-block"><div class="flex items-center"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3"><i class="fas fa-cube text-indigo-600"></i></div><div class="flex-1 min-w-0"><p class="text-sm font-medium text-gray-900 truncate">Block #4891</p><div class="flex items-center text-xs text-gray-500"><span class="truncate mr-2">Hash: b5c71f9e8a0b6d5c4f3e2a1ba3f8e2d</span><span class="flex-shrink-0">15 mins ago</span></div></div><div class="ml-4 flex-shrink-0"><div class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Validated</div></div></div><div class="mt-2 ml-13 grid grid-cols-3 gap-2 text-xs"><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Data Type</p><p class="font-medium">Temperature</p></div><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Field</p><p class="font-medium">B</p></div><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Value</p><p class="font-medium">24.5°C</p></div></div></div><div class="p-4 hover:bg-gray-50 blockchain-block"><div class="flex items-center"><div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3"><i class="fas fa-cube text-indigo-600"></i></div><div class="flex-1 min-w-0"><p class="text-sm font-medium text-gray-900 truncate">Block #4890</p><div class="flex items-center text-xs text-gray-500"><span class="truncate mr-2">Hash: d4b5c71f9e8a0b6d5c4f3e2a1ba3f8e</span><span class="flex-shrink-0">32 mins ago</span></div></div><div class="ml-4 flex-shrink-0"><div class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Validated</div></div></div><div class="mt-2 ml-13 grid grid-cols-3 gap-2 text-xs"><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Data Type</p><p class="font-medium">Pest Alert</p></div><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Field</p><p class="font-medium">C</p></div><div class="bg-gray-100 p-1 rounded"><p class="text-gray-500">Value</p><p class="font-medium">Corn Borer</p></div></div></div></div><div class="px-6 py-3 bg-gray-50 text-right"><button class="text-sm font-medium text-emerald-600 hover:text-emerald-500">View all blocks</button></div></div><!-- Real-time Sensor Data --><div class="bg-white rounded-lg shadow p-6 mb-6"><div class="flex justify-between items-center mb-4"><h2 class="text-lg font-medium text-gray-900">Real-time Sensor Data</h2><div class="flex items-center"><span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full mr-2">Live</span><span class="text-xs text-gray-500">Updated: <span id="updateTime">Just now</span></span></div></div><div class="sensor-grid"><div class="bg-gray-50 p-3 rounded-lg"><div class="flex justify-between items-start"><div><p class="text-xs text-gray-500">Soil Moisture</p><p class="text-xl font-semibold"><span id="soilMoisture">72</span>%</p></div><div class="h-8 w-8 rounded-full bg-green-100 flex items-center justify-center"><i class="fas fa-tint text-green-600 text-sm"></i></div></div><div class="mt-2"><div class="w-full bg-gray-200 rounded-full h-1"><div class="bg-green-500 h-1 rounded-full" style="width: 72%"></div></div></div></div><div class="bg-gray-50 p-3 rounded-lg"><div class="flex justify-between items-start"><div><p class="text-xs text-gray-500">Temperature</p><p class="text-xl font-semibold"><span id="temperature">24.5</span>°C</p></div><div class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center"><i class="fas fa-temperature-high text-blue-600 text-sm"></i></div></div><div class="mt-2"><div class="w-full bg-gray-200 rounded-full h-1"><div class="bg-blue-500 h-1 rounded-full" style="width: 65%"></div></div></div></div><div class="bg-gray-50 p-3 rounded-lg"><div class="flex justify-between items-start"><div><p class="text-xs text-gray-500">Humidity</p><p class="text-xl font-semibold"><span id="humidity">65</span>%</p></div><div class="h-8 w-8 rounded-full bg-purple-100 flex items-center justify-center"><i class="fas fa-wind text-purple-600 text-sm"></i></div></div><div class="mt-2"><div class="w-full bg-gray-200 rounded-full h-1"><div class="bg-purple-500 h-1 rounded-full" style="width: 65%"></div></div></div></div><div class="bg-gray-50 p-3 rounded-lg"><div class="flex justify-between items-start"><div><p class="text-xs text-gray-500">Light Intensity</p><p class="text-xl font-semibold"><span id="lightIntensity">850</span> lux</p></div><div class="h-8 w-8 rounded-full bg-yellow-100 flex items-center justify-center"><i class="fas fa-sun text-yellow-600 text-sm"></i></div></div><div class="mt-2"><div class="w-full bg-gray-200 rounded-full h-1"><div class="bg-yellow-500 h-1 rounded-full" style="width: 75%"></div></div></div></div><div class="bg-gray-50 p-3 rounded-lg"><div class="flex justify-between items-start"><div><p class="text-xs text-gray-500">pH Level</p><p class="text-xl font-semibold"><span id="phLevel">6.8</span></p></div><div class="h-8 w-8 rounded-full bg-pink-100 flex items-center justify-center"><i class="fas fa-flask text-pink-600 text-sm"></i></div></div><div class="mt-2"><div class="w-full bg-gray-200 rounded-full h-1"><div class="bg-pink-500 h-1 rounded-full" style="width: 80%"></div></div></div></div><div class="bg-gray-50 p-3 rounded-lg"><div class="flex justify-between items-start"><div><p class="text-xs text-gray-500">CO2 Level</p><p class="text-xl font-semibold"><span id="co2Level">420</span> ppm</p></div><div class="h-8 w-8 rounded-full bg-indigo-100 flex items-center justify-center"><i class="fas fa-cloud text-indigo-600 text-sm"></i></div></div><div class="mt-2"><div class="w-full bg-gray-200 rounded-full h-1"><div class="bg-indigo-500 h-1 rounded-full" style="width: 55%"></div></div></div></div></div></div><!-- Cloud Integration --><div class="bg-white rounded-lg shadow p-6"><div class="flex justify-between items-center mb-4"><h2 class="text-lg font-medium text-gray-900">Cloud Platform Integration</h2><div class="flex space-x-2"><span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">AWS IoT</span><span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Azure</span><span class="text-xs bg-red-100 text-red-800 px-2 py-1 rounded-full">Google Cloud</span></div></div><div class="grid grid-cols-1 md:grid-cols-3 gap-4"><div class="bg-gray-50 p-4 rounded-lg"><div class="flex items-center mb-3"><div class="h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center mr-3"><i class="fab fa-aws text-blue-600"></i></div><div><p class="font-medium">AWS IoT Core</p><p class="text-xs text-gray-500">Connected</p></div></div><div class="text-xs space-y-2"><div class="flex justify-between"><span>Messages</span><span class="font-medium">1,248/day</span></div><div class="flex justify-between"><span>Storage</span><span class="font-medium">2.8 GB</span></div><div class="flex justify-between"><span>Rules Processed</span><span class="font-medium">56</span></div></div></div><div class="bg-gray-50 p-4 rounded-lg"><div class="flex items-center mb-3"><div class="h-10 w-10 rounded-full bg-green-100 flex items-center justify-center mr-3"><i class="fas fa-database text-green-600"></i></div><div><p class="font-medium">Azure Data Lake</p><p class="text-xs text-gray-500">Syncing</p></div></div><div class="text-xs space-y-2"><div class="flex justify-between"><span>Data Stored</span><span class="font-medium">4.2 TB</span></div><div class="flex justify-between"><span>Last Sync</span><span class="font-medium">2 mins ago</span></div><div class="flex justify-between"><span>Analytics Jobs</span><span class="font-medium">12 active</span></div></div></div><div class="bg-gray-50 p-4 rounded-lg"><div class="flex items-center mb-3"><div class="h-10 w-10 rounded-full bg-red-100 flex items-center justify-center mr-3"><i class="fab fa-google text-red-600"></i></div><div><p class="font-medium">BigQuery</p><p class="text-xs text-gray-500">Processing</p></div></div><div class="text-xs space-y-2"><div class="flex justify-between"><span>Queries</span><span class="font-medium">84/day</span></div><div class="flex justify-between"><span>ML Models</span><span class="font-medium">3 active</span></div><div class="flex justify-between"><span>Storage</span><span class="font-medium">1.5 TB</span></div></div></div></div><div class="mt-4 pt-4 border-t border-gray-200"><div class="flex justify-between items-center"><p class="text-sm text-gray-600">Data interoperability across platforms with unified schema</p><button class="text-sm font-medium text-emerald-600 hover:text-emerald-500">View integration details</button></div></div></div></main></div><script>// Mobile menu toggleconst mobileMenuButton = document.getElementById('mobile-menu-button');const mobileMenu = document.getElementById('mobile-menu');mobileMenuButton.addEventListener('click', () => {mobileMenu.classList.toggle('hidden');});// Initialize AI Prediction Chartconst aiChartOptions = {series: [{name: 'Irrigation Prediction',data: [30, 40, 35, 50, 49, 60, 70, 91, 125]}, {name: 'Actual Usage',data: [35, 38, 33, 48, 52, 58, 65, 89, 120]}],chart: {height: '100%',type: 'line',toolbar: {show: false}},colors: ['#10B981', '#3B82F6'],dataLabels: {enabled: false},stroke: {curve: 'smooth',width: [3, 3]},xaxis: {categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'],},tooltip: {y: {formatter: function (val) {return val + " liters"}}},legend: {position: 'top'}};const aiChart = new ApexCharts(document.querySelector("#aiChart"), aiChartOptions);aiChart.render();// Simulate real-time data updatesfunction updateSensorData() {const now = new Date();document.getElementById('updateTime').textContent = now.toLocaleTimeString();// Update sensor values randomly for demo purposesconst sensors = {soilMoisture: { min: 65, max: 75, unit: '%' },temperature: { min: 22, max: 26, unit: '°C', decimals: 1 },humidity: { min: 60, max: 70, unit: '%' },lightIntensity: { min: 800, max: 900, unit: ' lux' },phLevel: { min: 6.5, max: 7.0, unit: '', decimals: 1 },co2Level: { min: 400, max: 450, unit: ' ppm' }};for (const [id, config] of Object.entries(sensors)) {const element = document.getElementById(id);const value = (Math.random() * (config.max - config.min) + config.min).toFixed(config.decimals || 0);element.textContent = value;// Update progress barconst progress = ((value - config.min) / (config.max - config.min)) * 100;const progressBar = element.closest('.bg-gray-50').querySelector('.bg-gray-200 div');progressBar.style.width = `${progress}%`;}}// Initial updateupdateSensorData();// Update every 5 secondssetInterval(updateSensorData, 5000);// Simulate blockchain updatesfunction addNewBlock() {const blocksContainer = document.querySelector('.blockchain-block').parentNode;const firstBlock = blocksContainer.firstElementChild;const newBlock = firstBlock.cloneNode(true);// Update block dataconst blockNumber = newBlock.querySelector('.text-gray-900');const blockHash = newBlock.querySelector('.text-gray-500 span');const timeAgo = newBlock.querySelector('.text-gray-500 span:last-child');const dataType = newBlock.querySelector('.grid div:nth-child(1) p:last-child');const field = newBlock.querySelector('.grid div:nth-child(2) p:last-child');const value = newBlock.querySelector('.grid div:nth-child(3) p:last-child');const blockNum = parseInt(blockNumber.textContent.match(/\d+/)[0]) + 1;blockNumber.textContent = `Block #${blockNum}`;// Generate random hashconst hash = Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10);blockHash.textContent = `Hash: ${hash}...`;timeAgo.textContent = 'Just now';// Random dataconst dataTypes = ['Soil Moisture', 'Temperature', 'Humidity', 'Light', 'pH Level', 'CO2 Level'];const fields = ['A', 'B', 'C', 'Greenhouse'];const values = {'Soil Moisture': { unit: '%', min: 60, max: 75 },'Temperature': { unit: '°C', min: 20, max: 28 },'Humidity': { unit: '%', min: 55, max: 75 },'Light': { unit: ' lux', min: 750, max: 900 },'pH Level': { unit: '', min: 6.5, max: 7.0, decimals: 1 },'CO2 Level': { unit: ' ppm', min: 400, max: 450 }};const randomType = dataTypes[Math.floor(Math.random() * dataTypes.length)];const randomField = fields[Math.floor(Math.random() * fields.length)];const randomValue = (Math.random() * (values[randomType].max - values[randomType].min) + values[randomType].min).toFixed(values[randomType].decimals || 0);dataType.textContent = randomType;field.textContent = randomField;value.textContent = randomValue + values[randomType].unit;// Insert at the topblocksContainer.insertBefore(newBlock, firstBlock);// Remove last block if more than 3if (blocksContainer.children.length > 3) {blocksContainer.removeChild(blocksContainer.lastElementChild);}}// Add new block every 30 secondssetInterval(addNewBlock, 30000);</script><p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Abder004/smartfarming" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869<!DOCTYPE html><html><head><title>AgriChain Backend Documentation</title><script src="https://cdn.tailwindcss.com"></script><style>pre {background-color: #f8f8f8;border-radius: 5px;padding: 15px;overflow-x: auto;}.endpoint {border-left: 4px solid #10b981;padding-left: 1rem;margin-bottom: 2rem;}</style></head><body class="bg-gray-50 p-8"><div class="max-w-6xl mx-auto bg-white rounded-lg shadow-lg p-8"><div class="flex items-center mb-8"><i class="fas fa-leaf text-emerald-500 text-3xl mr-3"></i><h1 class="text-3xl font-bold text-gray-800">AgriChain Backend API</h1></div><div class="mb-8"><h2 class="text-xl font-semibold text-gray-800 mb-4">System Overview</h2><p class="text-gray-600 mb-4">The AgriChain backend provides RESTful APIs for the smart farming dashboard, handling IoT device data,blockchain transactions, AI predictions, and user management.</p><div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"><div class="bg-emerald-50 p-4 rounded-lg"><h3 class="font-medium text-emerald-800 mb-2">Tech Stack</h3><ul class="text-sm text-gray-700 space-y-1"><li>Node.js v18+</li><li>Express.js</li><li>MongoDB (with Mongoose)</li><li>JWT Authentication</li><li>Web3.js for blockchain</li><li>TensorFlow.js for AI</li></ul></div><div class="bg-blue-50 p-4 rounded-lg"><h3 class="font-medium text-blue-800 mb-2">Key Features</h3><ul class="text-sm text-gray-700 space-y-1"><li>Real-time IoT data processing</li><li>Blockchain data integrity</li><li>AI prediction models</li><li>User authentication</li><li>Cloud integration</li></ul></div><div class="bg-purple-50 p-4 rounded-lg"><h3 class="font-medium text-purple-800 mb-2">Deployment</h3><ul class="text-sm text-gray-700 space-y-1"><li>Docker containerization</li><li>Kubernetes for orchestration</li><li>AWS ECS/EKS</li><li>CI/CD with GitHub Actions</li></ul></div></div></div><div class="mb-8"><h2 class="text-xl font-semibold text-gray-800 mb-4">Installation</h2><pre><code class="language-bash"># Clone the repositorygit clone https://github.com/agrichain/backend.gitcd backend# Install dependenciesnpm install# Set up environment variablescp .env.example .env# Edit .env with your configuration# Start the development servernpm run dev# For productionnpm run buildnpm start</code></pre></div><div class="mb-8"><h2 class="text-xl font-semibold text-gray-800 mb-4">API Endpoints</h2><div class="endpoint"><h3 class="text-lg font-medium text-gray-800 mb-2">Authentication</h3><div class="mb-4"><span class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span><span class="ml-2 font-mono">/api/auth/register</span></div><pre><code class="language-javascript">// Request Body{"name": "John Farmer","email": "john@example.com","password": "securepassword123","farmName": "Green Valley Farms"}// Response{"success": true,"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...","user": {"id": "507f1f77bcf86cd799439011","name": "John Farmer","email": "john@example.com","farmName": "Green Valley Farms"}}</code></pre><div class="mb-4 mt-6"><span class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span><span class="ml-2 font-mono">/api/auth/login</span></div><pre><code class="language-javascript">// Request Body{"email": "john@example.com","password": "securepassword123"}// Response (same structure as register)</code></pre></div><div class="endpoint"><h3 class="text-lg font-medium text-gray-800 mb-2">IoT Device Management</h3><div class="mb-4"><span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span><span class="ml-2 font-mono">/api/iot/devices</span></div><pre><code class="language-javascript">// Response{"success": true,"devices": [{"id": "60d5ec9cfb9d8b3a48fe9a12","name": "Soil Moisture Sensor - Field A","type": "moisture","status": "online","batteryLevel": 78,"signalStrength": 92,"lastReading": {"value": 72,"timestamp": "2023-06-15T08:30:45.000Z"},"location": {"field": "A","coordinates": [34.0522, -118.2437]}},// ... more devices]}</code></pre><div class="mb-4 mt-6"><span class="bg-yellow-100 text-yellow-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span><span class="ml-2 font-mono">/api/iot/data</span><span class="text-sm text-gray-500 ml-2">(for IoT devices to send data)</span></div><pre><code class="language-javascript">// Request Body{"deviceId": "60d5ec9cfb9d8b3a48fe9a12","secretKey": "device-secret-key","readings": [{"type": "moisture","value": 72,"timestamp": "2023-06-15T08:30:45.000Z"}]}// Response{"success": true,"message": "Data received and stored","blockchainHash": "a3f8e2d4b5c71f9e8a0b6d5c4f3e2a1b"}</code></pre></div><div class="endpoint"><h3 class="text-lg font-medium text-gray-800 mb-2">Blockchain</h3><div class="mb-4"><span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span><span class="ml-2 font-mono">/api/blockchain/blocks</span></div><pre><code class="language-javascript">// Response{"success": true,"blocks": [{"index": 4892,"timestamp": "2023-06-15T08:30:45.000Z","data": {"deviceId": "60d5ec9cfb9d8b3a48fe9a12","readingType": "moisture","value": 72,"field": "A"},"previousHash": "b5c71f9e8a0b6d5c4f3e2a1ba3f8e2d","hash": "a3f8e2d4b5c71f9e8a0b6d5c4f3e2a1b"},// ... more blocks]}</code></pre><div class="mb-4 mt-6"><span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span><span class="ml-2 font-mono">/api/blockchain/validate</span></div><pre><code class="language-javascript">// Response{"success": true,"valid": true,"invalidBlocks": [],"message": "Blockchain integrity verified"}</code></pre></div><div class="endpoint"><h3 class="text-lg font-medium text-gray-800 mb-2">AI Predictions</h3><div class="mb-4"><span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span><span class="ml-2 font-mono">/api/ai/predictions</span></div><pre><code class="language-javascript">// Response{"success": true,"predictions": [{"type": "irrigation","field": "A","prediction": "Next irrigation in 8 hours","confidence": 0.92,"recommendation": "Delay watering until evening to reduce evaporation"},{"type": "pest","field": "B","prediction": "Low pest risk (15%)","confidence": 0.87,"recommendation": "Monitor for corn borer, no treatment needed yet"},{"type": "harvest","field": "C","prediction": "Optimal harvest window: July 15-18","confidence": 0.85,"recommendation": "Prepare workforce and storage for peak yield"}]}</code></pre><div class="mb-4 mt-6"><span class="bg-yellow-100 text-yellow-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span><span class="ml-2 font-mono">/api/ai/train</span><span class="text-sm text-gray-500 ml-2">(Admin only - retrain models)</span></div><pre><code class="language-javascript">// Response{"success": true,"message": "AI models retrained successfully","newAccuracy": {"irrigation": 0.93,"pest": 0.88,"harvest": 0.86}}</code></pre></div><div class="endpoint"><h3 class="text-lg font-medium text-gray-800 mb-2">Cloud Integration</h3><div class="mb-4"><span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span><span class="ml-2 font-mono">/api/cloud/status</span></div><pre><code class="language-javascript">// Response{"success": true,"services": [{"provider": "AWS IoT","status": "connected","metrics": {"messages": 1248,"storage": 2.8,"rulesProcessed": 56}},{"provider": "Azure Data Lake","status": "syncing","metrics": {"dataStored": 4.2,"lastSync": "2023-06-15T08:28:12.000Z","analyticsJobs": 12}},{"provider": "Google BigQuery","status": "processing","metrics": {"queries": 84,"mlModels": 3,"storage": 1.5}}]}</code></pre></div></div><div class="mb-8"><h2 class="text-xl font-semibold text-gray-800 mb-4">Database Schema</h2><div class="grid grid-cols-1 md:grid-cols-2 gap-4"><div class="bg-gray-50 p-4 rounded-lg"><h3 class="font-medium text-gray-800 mb-2">User</h3><pre><code class="language-javascript">{name: String,email: { type: String, unique: true },password: String,farmName: String,role: { type: String, enum: ['user', 'admin'], default: 'user' },createdAt: { type: Date, default: Date.now }}</code></pre></div><div class="bg-gray-50 p-4 rounded-lg"><h3 class="font-medium text-gray-800 mb-2">Device</h3><pre><code class="language-javascript">{name: String,type: { type: String, enum: ['moisture', 'temperature', 'humidity', 'light', 'ph', 'co2'] },status: { type: String, enum: ['online', 'offline', 'maintenance'] },batteryLevel: Number,signalStrength: Number,secretKey: String, // For authenticationuserId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },location: {field: String,coordinates: [Number] // [longitude, latitude]}}</code></pre></div><div class="bg-gray-50 p-4 rounded-lg"><h3 class="font-medium text-gray-800 mb-2">Reading</h3><pre><code class="language-javascript">{deviceId: { type: mongoose.Schema.Types.ObjectId, ref: 'Device' },type: String,value: Number,timestamp: { type: Date, default: Date.now },field: String,blockchainHash: String}</code></pre></div><div class="bg-gray-50 p-4 rounded-lg"><h3 class="font-medium text-gray-800 mb-2">Block</h3><pre><code class="language-javascript">{index: Number,timestamp: { type: Date, default: Date.now },data: {deviceId: { type: mongoose.Schema.Types.ObjectId, ref: 'Device' },readingType: String,value: Number,field: String},previousHash: String,hash: String}</code></pre></div><div class="bg-gray-50 p-4 rounded-lg"><h3 class="font-medium text-gray-800 mb-2">Prediction</h3><pre><code class="language-javascript">{type: { type: String, enum: ['irrigation', 'pest', 'harvest'] },field: String,prediction: String,confidence: Number,recommendation: String,userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },createdAt: { type: Date, default: Date.now }}</code></pre></div><div class="bg-gray-50 p-4 rounded-lg"><h3 class="font-medium text-gray-800 mb-2">CloudService</h3><pre><code class="language-javascript">{provider: { type: String, enum: ['aws', 'azure', 'google'] },status: String,metrics: {messages: Number,storage: Number,rulesProcessed: Number,// ... other metrics},lastSync: Date,userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }}</code></pre></div></div></div><div class="mb-8"><h2 class="text-xl font-semibold text-gray-800 mb-4">Example Server Code</h2><div class="mb-6"><h3 class="font-medium text-gray-800 mb-2">app.js (Main Server File)</h3><pre><code class="language-javascript">require('dotenv').config();const express = require('express');const mongoose = require('mongoose');const cors = require('cors');const helmet = require('helmet');const rateLimit = require('express-rate-limit');const { Web3 } = require('web3');const tf = require('@tensorflow/tfjs-node');const app = express();// Database connectionmongoose.connect(process.env.MONGODB_URI, {useNewUrlParser: true,useUnifiedTopology: true}).then(() => console.log('Connected to MongoDB')).catch(err => console.error('MongoDB connection error:', err));// Middlewareapp.use(cors());app.use(helmet());app.use(express.json());// Rate limitingconst limiter = rateLimit({windowMs: 15 * 60 * 1000, // 15 minutesmax: 100 // limit each IP to 100 requests per windowMs});app.use(limiter);// Blockchain setupconst web3 = new Web3(process.env.BLOCKCHAIN_NODE_URL);const contract = new web3.eth.Contract(JSON.parse(process.env.CONTRACT_ABI),process.env.CONTRACT_ADDRESS);// Routesapp.use('/api/auth', require('./routes/auth'));app.use('/api/iot', require('./routes/iot'));app.use('/api/blockchain', require('./routes/blockchain'));app.use('/api/ai', require('./routes/ai'));app.use('/api/cloud', require('./routes/cloud'));// Error handlingapp.use((err, req, res, next) => {console.error(err.stack);res.status(500).json({success: false,message: 'Internal server error'});});const PORT = process.env.PORT || 5000;app.listen(PORT, () => {console.log(`Server running on port ${PORT}`);});module.exports = app;</code></pre></div><div class="mb-6"><h3 class="font-medium text-gray-800 mb-2">routes/iot.js (Example Route)</h3><pre><code class="language-javascript">const express = require('express');const router = express.Router();const auth = require('../middleware/auth');const Device = require('../models/Device');const Reading = require('../models/Reading');const { addBlock } = require('../utils/blockchain');// @route GET api/iot/devices// @desc Get all user's IoT devices// @access Privaterouter.get('/devices', auth, async (req, res) => {try {const devices = await Device.find({ userId: req.user.id });// Get latest readings for each deviceconst devicesWithReadings = await Promise.all(devices.map(async device => {const latestReading = await Reading.findOne({ deviceId: device._id }).sort({ timestamp: -1 }).limit(1);return {...device.toObject(),lastReading: latestReading || null};}));res.json({ success: true, devices: devicesWithReadings });} catch (err) {console.error(err.message);res.status(500).json({ success: false, message: 'Server error' });}});// @route POST api/iot/data// @desc Receive data from IoT device// @access Private (using device secret key)router.post('/data', async (req, res) => {const { deviceId, secretKey, readings } = req.body;try {// Verify deviceconst device = await Device.findOne({ _id: deviceId, secretKey });if (!device) {return res.status(401).json({success: false,message: 'Invalid device credentials'});}// Save readingsconst savedReadings = await Promise.all(readings.map(async reading => {const newReading = new Reading({deviceId,type: reading.type,value: reading.value,timestamp: reading.timestamp || Date.now(),field: device.location.field});// Add to blockchainconst blockData = {deviceId,readingType: reading.type,value: reading.value,field: device.location.field};const hash = await addBlock(blockData);newReading.blockchainHash = hash;return await newReading.save();}));// Update device status and battery if providedif (readings[0].batteryLevel) {device.batteryLevel = readings[0].batteryLevel;await device.save();}res.json({success: true,message: 'Data received and stored',blockchainHash: savedReadings[0].blockchainHash});} catch (err) {console.error(err.message);res.status(500).json({ success: false, message: 'Server error' });}});module.exports = router;</code></pre></div><div class="mb-6"><h3 class="font-medium text-gray-800 mb-2">utils/blockchain.js</h3><pre><code class="language-javascript">const Block = require('../models/Block');const crypto = require('crypto');// Simple blockchain implementation (in production would use Ethereum or similar)class Blockchain {constructor() {this.chain = [];this.initializeChain();}async initializeChain() {// Load existing chain from databaseconst blocks = await Block.find().sort({ index: 1 });this.chain = blocks;// If no blocks, create genesis blockif (this.chain.length === 0) {await this.createGenesisBlock();}}async createGenesisBlock() {const genesisBlock = new Block({index: 0,timestamp: Date.now(),data: { message: "Genesis block" },previousHash: "0",hash: this.calculateHash(0, "0", Date.now(), { message: "Genesis block" })});await genesisBlock.save();this.chain.push(genesisBlock);}calculateHash(index, previousHash, timestamp, data) {return crypto.createHash('sha256').update(index + previousHash + timestamp + JSON.stringify(data)).digest('hex');}async addBlock(data) {const previousBlock = this.chain[this.chain.length - 1];const newIndex = previousBlock.index + 1;const newTimestamp = Date.now();const newHash = this.calculateHash(newIndex, previousBlock.hash, newTimestamp, data);const newBlock = new Block({index: newIndex,timestamp: newTimestamp,data,previousHash: previousBlock.hash,hash: newHash});await newBlock.save();this.chain.push(newBlock);return newHash;}async validateChain() {for (let i = 1; i < this.chain.length; i++) {const currentBlock = this.chain[i];const previousBlock = this.chain[i - 1];// Check hashif (currentBlock.hash !== this.calculateHash(currentBlock.index,currentBlock.previousHash,currentBlock.timestamp,currentBlock.data)) {return false;}// Check previous hashif (currentBlock.previousHash !== previousBlock.hash) {return false;}}return true;}}const blockchain = new Blockchain();// Public functionsconst addBlock = async (data) => {return await blockchain.addBlock(data);};const validateChain = async () => {return await blockchain.validateChain();};const getBlocks = async () => {return blockchain.chain;};module.exports = {addBlock,validateChain,getBlocks};</code></pre></div></div><div class="mb-8"><h2 class="text-xl font-semibold text-gray-800 mb-4">Deployment</h2><div class="mb-6"><h3 class="font-medium text-gray-800 mb-2">Dockerfile</h3><pre><code class="language-dockerfile"># Use official Node.js imageFROM node:18-alpine# Create app directoryWORKDIR /usr/src/app# Install app dependenciesCOPY package*.json ./RUN npm install# Bundle app sourceCOPY . .# Build the appRUN npm run build# Expose the app portEXPOSE 5000# Start the appCMD ["npm", "start"]</code></pre></div><div class="mb-6"><h3 class="font-medium text-gray-800 mb-2">docker-compose.yml</h3><pre><code class="language-yaml">version: '3.8'services:app:build: .ports:- "5000:5000"environment:- NODE_ENV=production- MONGODB_URI=mongodb://mongo:27017/agrichain- JWT_SECRET=your_jwt_secretdepends_on:- mongorestart: unless-stoppedmongo:image: mongo:6.0ports:- "27017:27017"volumes:- mongodb_data:/data/dbenvironment:- MONGO_INITDB_ROOT_USERNAME=root- MONGO_INITDB_ROOT_PASSWORD=examplevolumes:mongodb_data:</code></pre></div><div class="mb-6"><h3 class="font-medium text-gray-800 mb-2">Kubernetes Deployment</h3><pre><code class="language-yaml">apiVersion: apps/v1kind: Deploymentmetadata:name: agrichain-backendspec:replicas: 3selector:matchLabels:app: agrichain-backendtemplate:metadata:labels:app: agrichain-backendspec:containers:- name: appimage: your-registry/agrichain-backend:latestports:- containerPort: 5000env:- name: NODE_ENVvalue: production- name: MONGODB_URIvalue: "mongodb://agrichain-mongo:27017/agrichain"- name: JWT_SECRETvalueFrom:secretKeyRef:name: agrichain-secretskey: jwt-secret- name: mongoimage: mongo:6.0ports:- containerPort: 27017env:- name: MONGO_INITDB_ROOT_USERNAMEvalueFrom:secretKeyRef:name: agrichain-secretskey: mongo-root-username- name: MONGO_INITDB_ROOT_PASSWORDvalueFrom:secretKeyRef:name: agrichain-secretskey: mongo-root-passwordvolumeMounts:- name: mongodb-datamountPath: /data/dbvolumes:- name: mongodb-datapersistentVolumeClaim:claimName: mongodb-pvc---apiVersion: v1kind: Servicemetadata:name: agrichain-servicespec:selector:app: agrichain-backendports:- protocol: TCPport: 80targetPort: 5000type: LoadBalancer</code></pre></div></div><div class="bg-emerald-50 p-4 rounded-lg"><h2 class="text-lg font-medium text-emerald-800 mb-2">Next Steps</h2><ul class="list-disc pl-5 text-gray-700 space-y-1"><li>Set up CI/CD pipeline with GitHub Actions</li><li>Configure monitoring with Prometheus and Grafana</li><li>Implement WebSocket for real-time updates to frontend</li><li>Add more AI models for different crop types</li><li>Integrate with weather APIs for enhanced predictions</li></ul></div></div><p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Abder004/smartfarming" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body></html>
index.html+813-843