Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Software/.env
node_modules

secrets.h
sketches/secrets.h

.env
.vscode
12 changes: 12 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# backend/.env — local development only
# Copy this to .env and fill in values. Never commit .env.

MONGO_URI=mongodb+srv://<user>:<password>@<cluster>.mongodb.net/terradetect
DB_NAME=terradetect
SECRET_KEY=generate-with-openssl-rand-hex-32
WEATHER_API_KEY=your-weatherapi-com-key
PORT=8080

# Paths to ONNX model files (relative to backend/ directory)
CROP_MODEL_PATH=../ml/crop-model.onnx
FERTILIZER_MODEL_PATH=../ml/fertilizer-model.onnx
4 changes: 4 additions & 0 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Config struct {
SecretKey string
WeatherAPIKey string
Port string
CropModelPath string
FertilizerModelPath string
}

func Load() *Config {
Expand All @@ -24,6 +26,8 @@ func Load() *Config {
SecretKey: mustGet("SECRET_KEY"),
WeatherAPIKey: mustGet("WEATHER_API_KEY"),
Port: getOrDefault("PORT", "8080"),
CropModelPath: getOrDefault("CROP_MODEL_PATH", "../ml/crop-model.onnx"),
FertilizerModelPath: getOrDefault("FERTILIZER_MODEL_PATH", "../ml/fertilizer-model.onnx"),
}

return cfg
Expand Down
16 changes: 12 additions & 4 deletions backend/db/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ func Connect(uri, dbName string) (*Database, error) {
TokenDenyList: d.Collection("token_deny_list"),
}

database.SensorData.Indexes().CreateOne(ctx, mongo.IndexModel{
Keys: bson.D{{Key: "device_id", Value: 1}, {Key: "timestamp", Value: -1}},
_, _ = database.SensorData.Indexes().CreateOne(ctx, mongo.IndexModel{
Keys: bson.D{
{Key: "device_id", Value: 1},
{Key: "timestamp", Value: -1},
},
})

ttl := int32(0)
database.TokenDenyList.Indexes().CreateOne(ctx, mongo.IndexModel{
Keys: bson.D{{Key: "expires_at", Value: 1}},
_, _ = database.TokenDenyList.Indexes().CreateOne(ctx, mongo.IndexModel{
Keys: bson.D{{Key: "expires_at", Value: 1}},
Options: &options.IndexOptions{ExpireAfterSeconds: &ttl},
})

_, _ = database.Users.Indexes().CreateOne(ctx, mongo.IndexModel{
Keys: bson.D{{Key: "username", Value: 1}},
Options: options.Index().SetUnique(true),
})

return database, nil
}
4 changes: 3 additions & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ module github.com/gagan-devv/terradetect/backend
go 1.26.1

require (
github.com/gin-contrib/cors v1.7.6
github.com/gin-gonic/gin v1.12.0
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/joho/godotenv v1.5.1
github.com/ulule/limiter/v3 v3.11.2
github.com/yalue/onnxruntime_go v1.27.0
go.mongodb.org/mongo-driver v1.17.9
golang.org/x/crypto v0.49.0
)

require (
Expand Down Expand Up @@ -43,7 +46,6 @@ require (
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
golang.org/x/arch v0.22.0 // indirect
golang.org/x/crypto v0.49.0 // indirect
golang.org/x/net v0.51.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.42.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
github.com/gin-contrib/cors v1.7.6 h1:3gQ8GMzs1Ylpf70y8bMw4fVpycXIeX1ZemuSQIsnQQY=
github.com/gin-contrib/cors v1.7.6/go.mod h1:Ulcl+xN4jel9t1Ry8vqph23a60FwH9xVLd+3ykmTjOk=
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
Expand Down Expand Up @@ -86,6 +88,8 @@ github.com/xdg-go/scram v1.2.0 h1:bYKF2AEwG5rqd1BumT4gAnvwU/M9nBp2pTSxeZw7Wvs=
github.com/xdg-go/scram v1.2.0/go.mod h1:3dlrS0iBaWKYVt2ZfA4cj48umJZ+cAEbR6/SjLA88I8=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/yalue/onnxruntime_go v1.27.0 h1:c1YSgDNtpf0WGtxj3YeRIb8VC5LmM1J+Ve3uHdteC1U=
github.com/yalue/onnxruntime_go v1.27.0/go.mod h1:b4X26A8pekNb1ACJ58wAXgNKeUCGEAQ9dmACut9Sm/4=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
Loading
Loading