api

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0

README

OpenMRP API

OpenMRP is a Go-based microservices platform using an API Gateway and domain-focused services coordinated via gRPC and RabbitMQ.

Architecture

  • API Gateway: Entry point for all public HTTP traffic.
  • Services: Coordinate business logic and manage transaction boundaries.
  • Mediators: Encapsulate reusable business logic steps.
  • Repositories: Handle data persistence.
  • Transport: Thin, stateless handlers for HTTP, gRPC, and RabbitMQ.

Development

Prerequisites

make install-tools installs everything else (buf, sqlc, goose, mockgen, gotestsum, vacuum, the protoc plugins, gosec, staticcheck, goimports) at the versions pinned in tools/tool-versions.

Setup
make install-tools  # Install dev dependencies
make setup          # Start minikube and the local databases (migrations + seed data)
make dev            # Spin up the environment with Tilt

make teardown reverses it: deletes minikube, nukes the local databases, and tears down the E2E stack.

Local Databases

make local-db spins up both databases in Docker containers, applies all migrations, and writes connection strings to .env automatically:

  • MySQL 8 on port 3306 — core-service (openmrp database)
  • PostgreSQL 16 on port 5432 — agent-service (openmrp_agents database)

Data is persisted in named Docker volumes so it survives container restarts. make local-db also seeds the core database with sample data (accounts, users, items, orders, etc.) via the SQL files in shared/db/seed/, and — when STRIPE_SECRET_KEY is set — creates a matching Stripe test subscription for the seeded account. Without that variable the Stripe step is skipped with a warning; run make seed-stripe later to add it.

# Re-seed core data (idempotent, safe to run multiple times)
make seed-core

# Seed with a specific plan (default: enterprise)
make seed-core ARGS="--plan starter"

# Seed the agent-service (PostgreSQL) database with e2e test data
# Migrations for it already ran as part of `make local-db`
make seed-agent-db

# Upload the seeded users' avatars to the user-photos S3 bucket
make seed-user-photos

# Connect directly
make local-db-cli   # MySQL CLI using DB_URL from .env
psql postgres://openmrp@localhost:5432/openmrp_agents

# Tear down containers (data preserved)
make local-db-down

# Tear down containers, clean up Stripe test resources, and delete all data (volumes)
# Run `make local-db` after to get clean databases with fresh migrations and seed data
make local-db-nuke
Using with the Dashboard

The dashboard API (Prisma) can connect to the same Docker MySQL instance. Add this to dashboard/apps/api/.env:

DATABASE_URL="mysql://root:Testing123!@localhost:3306/openmrp"
Using with Tilt / Kubernetes

Services running in minikube cannot reach localhost on the host machine. The K8s secret in infra/development/kubernetes/config/secrets.yaml uses host.minikube.internal to route traffic back to the host. These URIs match the Docker Compose databases started by make local-db:

Service URI
Core (MySQL) root:Testing123!@tcp(host.minikube.internal:3306)/openmrp
Agent (PostgreSQL) postgres://openmrp@host.minikube.internal:5432/openmrp_agents?sslmode=disable

The seed script hardcodes the Docker Compose connection details, so no .env configuration is needed — just run make local-db before make dev.

Agent endpoint-tools (optional)

Agents can invoke api-gateway endpoints flagged AgentTool: true (see make gen-agent-tools). This uses a dedicated internal api-gateway listener on port 8091, reached over the api-gateway-internal ClusterIP Service and gated by a shared token. The token is optional in dev: when it is absent the internal listener does not start and the endpoint-tools are simply unavailable (the rest of the agent works normally).

To enable it locally, add an internal-service-token secret to your infra/development/kubernetes/config/secrets.yaml:

apiVersion: v1
kind: Secret
metadata:
  name: internal-service-token
type: Opaque
stringData:
  token: "dev-internal-token" # any non-empty value in dev

Both api-gateway and agent-service already consume this secret (as INTERNAL_SERVICE_TOKEN) and the API_GATEWAY_INTERNAL_URL config value. In production the token is generated and delivered by Terraform in the private open-mrp/infra repo (production/terraform/internal_service_token.tf).

Common Commands

make help lists every target. make sqlc and make mocks take service arguments — either the full directory name (core-service) or its short alias (core, auth, notification, logging → platform-service, payment → billing-service, agent, api). With no argument they run against every service.

make sqlc [service]     # Generate database code from SQL queries
make proto              # Generate Go protobuf bindings
make mocks [service]    # Generate mock implementations
make generate           # Regenerate OpenAPI specs, Stainless configs, and agent tools
make test               # Run all tests
make e2e                # Bring up the E2E stack and run the E2E tests
make lint               # gosec + staticcheck + tx audit + committed-binary check
make fmt                # Format Go sources
Conventions

AGENTS.md and the pattern docs in docs/patterns/ are the normative spec for this codebase — layering, API versioning, nullable fields, authorization, audit events, entity IDs, logging, comments. Read the doc for the layer you are changing before you write; where a doc and existing code disagree, the doc wins.

Development Process

1. Branching

Create a new branch from main for every feature or bug fix. Use descriptive names with the appropriate prefix:

# For new features
git checkout -b feature/your-feature-name

# For bug fixes
git checkout -b bug/your-bug-name
2. Committing

We use Conventional Commits to maintain a clean history and automate versioning. Every commit message must start with a prefix that indicates the type of change:

Prefix Type of Change Version Impact
fix: Bug fixes Patch (0.0.x)
feat: New features Minor (0.x.0)
feat!: Breaking changes Major (x.0.0)

Note: These prefixes are used by release-please to automatically calculate the next version number.

3. Deploying Changes
  1. Open a Pull Request: Once your work is complete, open a PR against the main branch.
  2. Merge: After review and approval, merge your PR.
  3. Release PR: release-please will automatically create or update a "Release PR" that aggregates all pending changes and updates the changelog.
  4. Production Release: When ready to deploy, merge the "Release PR" into main. This triggers the final release process and deployment to production.

Production infrastructure — Terraform, the production Kubernetes manifests, and the deploy script — lives in the private open-mrp/infra repo. This repo builds service images and pushes them to ECR; it then asks open-mrp/infra to roll them out and waits for the result, so nothing here holds a credential that can reach the cluster.

Two consequences worth knowing:

  • Infrastructure changes ship separately. Terraform no longer runs inside this pipeline. When a release needs new infrastructure, merge and apply it in open-mrp/infra first, then cut the release here.
  • Manifest-only changes deploy from open-mrp/infra. Editing a Deployment or the shared ConfigMap is a push to that repo, not a release here.

infra/development/ stays in this repo — it is what make dev runs against, and it holds no production identifiers.

4. Notes
  • minikube might need refreshed, try minikube delete and minikube start

Security

Found a vulnerability? Email security@augno.com rather than opening an issue — see SECURITY.md for scope and what to include.

Every sk_test_, mrp_sk_test_, whsec_ and JWT in this repository is fabricated sample or fixture data. If you find one that resolves against a real service, that is a genuine finding.

License

Apache 2.0. "OpenMRP" and "Augno", with their logos and wordmarks, are trademarks of Augno, Inc. Section 6 of the license grants no trademark rights — see TRADEMARKS.md.

Directories

Path Synopsis
cmd
backfill-customer-role command
Command backfill-customer-role provisions the global "Customer" role in the database and assigns it to customer-portal account users.
Command backfill-customer-role provisions the global "Customer" role in the database and assigns it to customer-portal account users.
dedupe-inventory-allocations command
Command dedupe-inventory-allocations removes duplicate inventory allocation rows written by replayed production-step scans, and returns the receipts they falsely closed out to `available`.
Command dedupe-inventory-allocations removes duplicate inventory allocation rows written by replayed production-step scans, and returns the receipts they falsely closed out to `available`.
genid command
print-version command
internal
services
agent-service/internal/domain/mock/client
Package clientmock is a generated GoMock package.
Package clientmock is a generated GoMock package.
agent-service/internal/domain/mock/factory
Package factorymock is a generated GoMock package.
Package factorymock is a generated GoMock package.
agent-service/internal/domain/mock/mediator
Package mediatormock is a generated GoMock package.
Package mediatormock is a generated GoMock package.
agent-service/internal/domain/mock/repository
Package repositorymock is a generated GoMock package.
Package repositorymock is a generated GoMock package.
agent-service/internal/domain/mock/service
Package servicemock is a generated GoMock package.
Package servicemock is a generated GoMock package.
agent-service/internal/infrastructure/httpgateway
Package httpgateway provides an HTTP client that invokes api-gateway endpoints over the gateway's trusted internal listener on behalf of an agent identity.
Package httpgateway provides an HTTP client that invokes api-gateway endpoints over the gateway's trusted internal listener on behalf of an agent identity.
api-gateway/cmd command
api-gateway/endpoints/portal-domains
Package portaldomainep implements the customer portal custom-domain management endpoints, backed by the core-service CorePortalDomainService gRPC client.
Package portaldomainep implements the customer portal custom-domain management endpoints, backed by the core-service CorePortalDomainService gRPC client.
api-gateway/endpoints/portal-registration-sessions
Package portalregsessionep implements the buyer customer-portal registration-session endpoints, backed by the core-service CoreService gRPC client.
Package portalregsessionep implements the buyer customer-portal registration-session endpoints, backed by the core-service CoreService gRPC client.
api-gateway/internal/chatmap
Package chatmap converts notification-service chat proto messages into gateway API resources.
Package chatmap converts notification-service chat proto messages into gateway API resources.
api-gateway/internal/domain/mock/publisher
Package publishermock is a generated GoMock package.
Package publishermock is a generated GoMock package.
api-gateway/internal/resourceloaders
Package resourceloaders holds the gRPC-backed loaders used by the api-gateway resourcekit include resolver.
Package resourceloaders holds the gRPC-backed loaders used by the api-gateway resourcekit include resolver.
api-gateway/internal/resourceregistry
Package resourceregistry contains the init()-time resourcekit.Definition registrations for every resource the api-gateway resolves includes against.
Package resourceregistry contains the init()-time resourcekit.Definition registrations for every resource the api-gateway resolves includes against.
api-gateway/internal/versiontransforms
Package versiontransforms registers the version.Transformer chain that the api-gateway uses to keep older API versions working.
Package versiontransforms registers the version.Transformer chain that the api-gateway uses to keep older API versions working.
api-gateway/pkg/resource
! Note: this will be refactored in the future - okay to leave as is.
! Note: this will be refactored in the future - okay to leave as is.
api-gateway/pkg/resourcekit
Package resourcekit is the canonical registry for API resources.
Package resourcekit is the canonical registry for API resources.
auth-service/internal/domain/mock/client
Package clientmock is a generated GoMock package.
Package clientmock is a generated GoMock package.
auth-service/internal/domain/mock/factory
Package factorymock is a generated GoMock package.
Package factorymock is a generated GoMock package.
auth-service/internal/domain/mock/mediator
Package mediatormock is a generated GoMock package.
Package mediatormock is a generated GoMock package.
auth-service/internal/domain/mock/publisher
Package publishermock is a generated GoMock package.
Package publishermock is a generated GoMock package.
auth-service/internal/domain/mock/repository
Package repositorymock is a generated GoMock package.
Package repositorymock is a generated GoMock package.
auth-service/internal/domain/mock/service
Package servicemock is a generated GoMock package.
Package servicemock is a generated GoMock package.
billing-service/internal/domain/mock/client
Package clientmock is a generated GoMock package.
Package clientmock is a generated GoMock package.
billing-service/internal/domain/mock/factory
Package factorymock is a generated GoMock package.
Package factorymock is a generated GoMock package.
billing-service/internal/domain/mock/mediator
Package mediatormock is a generated GoMock package.
Package mediatormock is a generated GoMock package.
billing-service/internal/domain/mock/repository
Package repositorymock is a generated GoMock package.
Package repositorymock is a generated GoMock package.
billing-service/internal/domain/mock/service
Package servicemock is a generated GoMock package.
Package servicemock is a generated GoMock package.
core-service/cmd/backfill-operating-calendars command
Command backfill-operating-calendars gives existing accounts the shipping and receiving calendars new accounts are provisioned with.
Command backfill-operating-calendars gives existing accounts the shipping and receiving calendars new accounts are provisioned with.
core-service/internal/calendarseed
Package calendarseed gives a new account the operating calendars a ship-by commitment is resolved against.
Package calendarseed gives a new account the operating calendars a ship-by commitment is resolved against.
core-service/internal/domain/mock/client
Package clientmock is a generated GoMock package.
Package clientmock is a generated GoMock package.
core-service/internal/domain/mock/factory
Package factorymock is a generated GoMock package.
Package factorymock is a generated GoMock package.
core-service/internal/domain/mock/mediator
Package mediatormock is a generated GoMock package.
Package mediatormock is a generated GoMock package.
core-service/internal/domain/mock/publisher
Package publishermock is a generated GoMock package.
Package publishermock is a generated GoMock package.
core-service/internal/domain/mock/repository
Package repositorymock is a generated GoMock package.
Package repositorymock is a generated GoMock package.
core-service/internal/domain/mock/service
Package servicemock is a generated GoMock package.
Package servicemock is a generated GoMock package.
core-service/internal/forecast
Package forecast holds OpenMRP's standard monthly demand forecaster.
Package forecast holds OpenMRP's standard monthly demand forecaster.
core-service/internal/hubspotsync
Package hubspotsync orchestrates pushing OpenMRP sales orders to HubSpot as Closed-Won deals, upserting the associated company and contact along the way.
Package hubspotsync orchestrates pushing OpenMRP sales orders to HubSpot as Closed-Won deals, upserting the associated company and contact along the way.
core-service/internal/infrastructure/hubspot
Package hubspot implements a thin HTTP client over the HubSpot CRM v3/v4 API, scoped to the company/contact/deal operations the sales-order sync needs.
Package hubspot implements a thin HTTP client over the HubSpot CRM v3/v4 API, scoped to the company/contact/deal operations the sales-order sync needs.
core-service/internal/infrastructure/vercel
Package vercel implements the portal domain provider on top of the Vercel Domains API.
Package vercel implements the portal domain provider on top of the Vercel Domains API.
core-service/internal/scheduling
Package scheduling is the production schedule solver.
Package scheduling is the production schedule solver.
core-service/internal/stripesync
Package stripesync reconciles OpenMRP customers with their counterparts in a merchant's connected Stripe account.
Package stripesync reconciles OpenMRP customers with their counterparts in a merchant's connected Stripe account.
notification-service/internal/domain/mock/factory
Package factorymock is a generated GoMock package.
Package factorymock is a generated GoMock package.
notification-service/internal/domain/mock/repository
Package repositorymock is a generated GoMock package.
Package repositorymock is a generated GoMock package.
notification-service/internal/domain/mock/service
Package servicemock is a generated GoMock package.
Package servicemock is a generated GoMock package.
notification-service/internal/ratelimit
Package ratelimit provides a small in-memory token-bucket limiter used to throttle abusive messaging actors (message send, conversation creation).
Package ratelimit provides a small in-memory token-bucket limiter used to throttle abusive messaging actors (message send, conversation creation).
notification-service/internal/reaper
Package reaper holds the background retention worker for the messaging substrate.
Package reaper holds the background retention worker for the messaging substrate.
notification-service/internal/scheduler
Package scheduler holds the background worker that delivers due scheduled messages.
Package scheduler holds the background worker that delivers due scheduled messages.
platform-service/internal/domain/mock/factory
Package factorymock is a generated GoMock package.
Package factorymock is a generated GoMock package.
platform-service/internal/domain/mock/repository
Package repositorymock is a generated GoMock package.
Package repositorymock is a generated GoMock package.
platform-service/internal/domain/mock/service
Package servicemock is a generated GoMock package.
Package servicemock is a generated GoMock package.
shared
appnav
Package appnav exposes the dashboard's page catalog to the API — which pages the app has, and which API object type each record detail page shows.
Package appnav exposes the dashboard's page catalog to the API — which pages the app has, and which API object type each record detail page shows.
cloud/sqs
Package sqs is a thin wrapper over the AWS SQS SDK for the consumers that poll a queue (currently the inbound-email bridge).
Package sqs is a thin wrapper over the AWS SQS SDK for the consumers that poll a queue (currently the inbound-email bridge).
db
env
errors
Package apierror defines the structured error types used across all services.
Package apierror defines the structured error types used across all services.
excel
Package excel builds spreadsheet workbooks from a declarative description of columns and rows, with no knowledge of any domain type.
Package excel builds spreadsheet workbooks from a declarative description of columns and rows, with no knowledge of any domain type.
id
lease
Package lease provides a distributed single-holder lease primitive backed by a SQL table.
Package lease provides a distributed single-holder lease primitive backed by a SQL table.
logging
Package logging provides structured logging utilities for gRPC services.
Package logging provides structured logging utilities for gRPC services.
messaging
Package messaging provides rabbitMQ integration, outbox/inbox patterns, and background workers for reliable asynchronous communication between microservices.
Package messaging provides rabbitMQ integration, outbox/inbox patterns, and background workers for reliable asynchronous communication between microservices.
retry
Package retry provides configurable retry logic with exponential backoff and jitter.
Package retry provides configurable retry logic with exponential backoff and jitter.
rpc
safeconv
Package safeconv provides safe integer conversion functions that clamp values at the target type's boundaries instead of silently overflowing.
Package safeconv provides safe integer conversion functions that clamp values at the target type's boundaries instead of silently overflowing.
sanitize
Package sanitize provides utilities for masking sensitive string values (API keys, tokens, secrets) in log output, error messages, and user-facing responses.
Package sanitize provides utilities for masking sensitive string values (API keys, tokens, secrets) in log output, error messages, and user-facing responses.
timeutil
Package timeutil provides helpers for parsing timestamp strings used throughout the platform's data layer.
Package timeutil provides helpers for parsing timestamp strings used throughout the platform's data layer.
tracing
Package tracing provides OpenTelemetry tracing initialization and helpers for all microservices.
Package tracing provides OpenTelemetry tracing initialization and helpers for all microservices.
validate
Package validate provides request-level input validation for the platform.
Package validate provides request-level input validation for the platform.
tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL