feat: Go backend scaffold with JWT auth, sensor API, ML inference, and rate limiting#7
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the TerraDetect backend from Python/Flask to Go (Gin), as part
of the broader Python → Go + Expo migration plan. The Python backend is
preserved in full on the
archive/python-backendbranch.What's changed
New: Go backend (
backend/)main.go— Gin router with all routes wired, CORS configuredconfig/— env var loading with startup validation (fails fast on missing vars)db/— MongoDB Atlas connection with compound index onsensor_dataand TTL index on token denylistmiddleware/— JWT auth middleware + IP-based rate limiting viaulule/limitermodels/—User,Device,SensorReadingstructs matching existing MongoDB schemahandlers/auth.go— Register, Login, Refresh, Logout with proper JWT access/refresh token flowhandlers/sensor.go— ESP32 ingest (POST /api/esp32), latest reading, paginated historyhandlers/device.go— Device ID registration checkhandlers/predict.go— Crop recommendation, suitability analysis, fertilizer suggestion (ported from Python)handlers/weather.go— Server-side WeatherAPI proxy (API key never reaches client)inference/onnx.go— ONNX runtime wrapper for crop and fertilizer modelsNew: ML export (
ml/)export_onnx.py— convertscrop-model.pklandfertilizer-model.pklto ONNXvalidate_onnx.py— verifies ONNX predictions match scikit-learn output before promotingcrop-model.onnx/fertilizer-model.onnx— exported model artifactsSecurity fixes (vs Python version)
script.jsVALID_DEVICE_IDSset removedAPI_KEY = "YOUR_SUPER_SECRET_KEY"placeholder route removedESP32 firmware (
sketches/)client.setInsecure()replaced withsetCACert(ROOT_CA)— ISRG Root X1 pinnedsecrets.hpattern introduced — API key, device ID, and backend URL out of.inosecrets.h.templatecomm