Skip to content

Inventory management API for agriculture

License

Notifications You must be signed in to change notification settings

open-farms/inventory

Repository files navigation

Inventory 📦

An inventory service for managing farming vehicles, equipment, and resources.

logo

What is this?

  • A REST API for managing farm inventory via HTTP requests
  • A gRPC Service for managing farm inventory via RPC requests
  • A CLI for managing farm inventory

The inventory service enables users to keep track of farm inventory across multiple IoT devices, servers, applications, or databases. This service provides a foundational interface for inventory management and interaction.

Structure

/cmd/inventory # http api server
/cmd/inventoryctl # cli tool for service administration
/ent # database models, migrations, and drivers
/ent/schemas # editable database models
/internal/settings # settings package to read in application configs

Quickstart ⚡

Deploy on Railway

You can either install inventory directly with go, build the project from source, or download a binary from the latest release

Docker Compose

# Start the database and API via docker-compose
docker-compose up

# List the vehicles
http :8000/v1/vehicles

Install with go install

# Install the server
go install github.com/open-farms/inventory/cmd/inventory@latest

# Install the admin cli
go install github.com/open-farms/inventory/cmd/inventoryctl@latest

Configuration ⚙️

Configure the application with the following environment variables

# HTTP Settings
INVENTORY_HTTP_ADDR # default:"0.0.0.0:8000"
INVENTORY_HTTP_TIMEOUT # default:"5s"
INVENTORY_HTTP_AUTH_ENABLED # default:"false"
INVENTORY_HTTP_AUTH_TOKEN # default:"inventory" - use "token:inventory" if basic auth enabled with default token

# GRPC Settings
INVENTORY_GRPC_ADDR # default:"0.0.0.0:9000"
INVENTORY_GRPC_TIMEOUT # default:"5s"

# Storage Settings
INVENTORY_STORAGE_DRIVER # default:"postgres"
INVENTORY_STORAGE_URI # default:"" - Automatically configured if deploying to railway
INVENTORY_STORAGE_MIGRATE # default:true
INVENTORY_STORAGE_DEBUG # default:true

Start the service 🏃

Start the service directly with the binary or run it containerized with Docker.

# Run the inventory service
inventory
# Build the docker image
docker build -t <your-docker-image-name> .

# Run the docker image, exposing the service
docker run --rm -v ./config:/data/config -p 8000:8000 <your-docker-image-name>

Manage the inventory database with the inventoryctl CLI

# Start the postgres database
docker-compose up

# Run the inventoryctl cli to perform database migrations
inventoryctl --help
inventoryctl migrate

Generate code and build from source 🏗️

Generate the service code, openapi spec, and build from source

make init
make generate
make test
make build

Services

View the openapi specification

View the protobuf schemas and services