hyrule

module
v0.100.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT

README ΒΆ

PortuguΓͺs

hyrule

Go Reference codecov

A Go framework for building REST APIs on top of Mongo: describe a resource (schema, methods, lookups) and get full CRUD with validation, ETags, pagination and a transactional outbox β€” in Go, or with no Go at all, via YAML. Under the hood it keeps the HTTP contract of Eve (Python) (internal/evecompat), which is where the project migrated from.

πŸ“– Full documentation: https://gui-rondon.github.io/hyrule/ β€” a guided Learn path plus a complete Reference.

Quickstart: a resource with no Go

# resources.yaml
resources:
  - name: tags
    collection: tags
    additional_lookup: {field: slug, pattern: '^[\w-]+$'}
    resource_methods: [get, post]
    item_methods: [get, patch, put]
    schema:
      name: {type: string, required: true}
      slug: {type: string, required: true, unique: true}
      enabled: {type: boolean, default: true}
make env-up    # Mongo (27018), Pub/Sub (8085), Redis (6380)
echo '{"auth": {"enable": "false"}}' > config.json
RESOURCES_FILE=resources.yaml CONFIG_FILE=config.json \
  MONGO_CONNECTION_STRING='mongodb://localhost:27018/demo?directConnection=true' \
  PORT=8080 go run ./cmd/hyrule-serve
curl -X POST localhost:8080/tags -d '{"name":"Go","slug":"go"}'
curl localhost:8080/tags/go

That's cmd/hyrule-serve + internal/declarative β€” it covers the common case. A resource with its own logic (hooks, custom endpoints, conditional validation) stays a small Go binary with app.Main, like the 4 examples in examples/blog-apis/ β€” both paths register resources the same way and coexist in the same process. The Learn guide walks through building both kinds, step by step.

Documentation

The full docs are at https://gui-rondon.github.io/hyrule/:

Learn a guided, step-by-step path through the framework, building up examples/blog-apis one concept at a time
Reference β†’ Store the Store interface: what it decouples (and what it doesn't yet)
Reference β†’ Outbox the transactional outbox, and the conditional primitive that fires an event straight from the write
Reference β†’ resources.yaml full reference of the resource YAML
Reference β†’ Dry run running in dry run: everything runs, the transaction always rolls back
Reference β†’ Testkit testing a resource (isolated Mongo, HTTP client, tokens)
Reference β†’ Architecture the services β†’ behaviors β†’ evecompat β†’ platform layering, and why it exists

Layout

internal/app/              shared bootstrap (app.Main / app.Build)
internal/behaviors/        reusable hooks: searchsync (ES), audit, events (outbox on write)
internal/evecompat/        the HTTP contract: Service (rules, no HTTP) + API (HTTP) + Store (storage interface)
internal/outbox/           transactional outbox, the Pub/Sub relay and the conditional primitive
internal/declarative/      loads a Resource/Schema from YAML (cmd/hyrule-serve)
internal/platform/         config, mongodb, auth, search, health, server, pubsub, redis
internal/testkit/          per-test isolated Mongo, ES recorder, tokens
cmd/hyrule-serve/          generic binary: registers the resources of a YAML, no domain Go
ci/                        ci/affected (picks the services a diff affects)
examples/blog-apis/        a real use of the framework (see that directory's README)
website/                  source of https://gui-rondon.github.io/hyrule/ (Docusaurus)

Development

Requires Go 1.27 and Docker.

make env-up               # generic infra: Mongo rs (27018), Pub/Sub (8085), Redis (6380)
make test                 # every test (uses the Mongo from env-up)
make unit                 # only the ones that need no external service
make cover                # coverage, fails below 85%
make build SERVICE=tags-api
make run SERVICE=tags-api  # :8081, auth disabled

To run the blog-apis example (which also needs Elasticsearch): see examples/blog-apis/README.md.

License

MIT β€” Β© 2026 Guilherme Rondon.

Directories ΒΆ

Path Synopsis
ci
affected command
Command affected prints the services whose binary changed between two commits, one per line, for the CI "detect services" job.
Command affected prints the services whose binary changed between two commits, one per line, for the CI "detect services" job.
cmd
hyrule-serve command
Command hyrule-serve registers the resources declared in a YAML file (internal/declarative) and serves them β€” no domain-specific Go code at all for the common case the loader covers.
Command hyrule-serve registers the resources declared in a YAML file (internal/declarative) and serves them β€” no domain-specific Go code at all for the common case the loader covers.
examples
blog-apis/services/authors-api command
Command authors-api is the simplest example of the blog-apis suite: a resource described entirely by its schema, with zero business-specific Go code β€” a candidate to become a plain YAML definition once the framework's declarative resource loader exists.
Command authors-api is the simplest example of the blog-apis suite: a resource described entirely by its schema, with zero business-specific Go code β€” a candidate to become a plain YAML definition once the framework's declarative resource loader exists.
blog-apis/services/categories-api command
Command categories-api demonstrates a hierarchical resource: a materialized path kept up to date on every write, and a custom GET /categories/tree endpoint built straight from the Store interface (no raw *mongo.Collection in sight).
Command categories-api demonstrates a hierarchical resource: a materialized path kept up to date on every write, and a custom GET /categories/tree endpoint built straight from the Store interface (no raw *mongo.Collection in sight).
blog-apis/services/posts-api command
Command posts-api is the richest example of the blog-apis suite: a resource with relations to authors-api/categories-api/tags-api, custom publish/schedule endpoints, outbox events, a Redis-backed scheduling index and Elasticsearch indexing.
Command posts-api is the richest example of the blog-apis suite: a resource with relations to authors-api/categories-api/tags-api, custom publish/schedule endpoints, outbox events, a Redis-backed scheduling index and Elasticsearch indexing.
blog-apis/services/tags-api command
Command tags-api is another zero-business-logic example: a resource with a Unique field and a slug lookup, nothing else.
Command tags-api is another zero-business-logic example: a resource with a Unique field and a slug lookup, nothing else.
internal
app
Package app is the bootstrap shared by the services: configuration, Mongo, authentication, the Eve API, /status and /healthcheck.
Package app is the bootstrap shared by the services: configuration, Mongo, authentication, the Eve API, /status and /healthcheck.
behaviors/audit
Package audit records who created and last changed a document: _created_user and _updated_user with the username of the request token (nil when authentication is disabled).
Package audit records who created and last changed a document: _created_user and _updated_user with the username of the request token (nil when authentication is disabled).
behaviors/events
Package events records outbox events in the transaction of a resource write (D-23).
Package events records outbox events in the transaction of a resource write (D-23).
behaviors/searchsync
Package searchsync keeps an Elasticsearch index in sync with a resource, as the resource_callbacks.py of the Eve APIs do: every write indexes the stored document (without _id) and a delete removes it.
Package searchsync keeps an Elasticsearch index in sync with a resource, as the resource_callbacks.py of the Eve APIs do: every write indexes the stored document (without _id) and a delete removes it.
declarative
Package declarative builds evecompat.Resource/Schema values from YAML, for the common case β€” a resource with no custom hooks or business logic (see internal/evecompat/service.go: settings-api, tags-api, authors-api in examples/blog-apis are entirely this shape already, hand-written).
Package declarative builds evecompat.Resource/Schema values from YAML, for the common case β€” a resource with no custom hooks or business logic (see internal/evecompat/service.go: settings-api, tags-api, authors-api in examples/blog-apis are entirely this shape already, hand-written).
domain/slug
Package slug is python-slugify's default slugify, used by the APIs and workers that turn tag names into {slug, name}.
Package slug is python-slugify's default slugify, used by the APIs and workers that turn tag names into {slug, name}.
evecompat
Package evecompat serves Mongo collections with the HTTP contract of Python Eve, so the gateways that call the Eve APIs keep working unchanged: where/sort/projection/page/max_results, the _items/_links/_meta envelope, If-Match/ETag, Eve's error envelope and Cerberus validation messages.
Package evecompat serves Mongo collections with the HTTP contract of Python Eve, so the gateways that call the Eve APIs keep working unchanged: where/sort/projection/page/max_results, the _items/_links/_meta envelope, If-Match/ETag, Eve's error envelope and Cerberus validation messages.
outbox
Package outbox implements the transactional outbox (D-10, D-23): a write stores its events in the outbox collection in the same Mongo transaction, and the Relay publishes them after the commit.
Package outbox implements the transactional outbox (D-10, D-23): a write stores its events in the outbox collection in the same Mongo transaction, and the Relay publishes them after the commit.
platform/auth
Package auth validates requests: an Azure AD token is tried first and, when the token isn't an Azure one (no kid, unknown kid), it falls back to a static RS256 key β€” for a secondary issuer, service-to-service tokens, or any other static key a deployment wants to trust alongside Azure AD.
Package auth validates requests: an Azure AD token is tried first and, when the token isn't an Azure one (no kid, unknown kid), it falls back to a static RS256 key β€” for a secondary issuer, service-to-service tokens, or any other static key a deployment wants to trust alongside Azure AD.
platform/config
Package config loads the service configuration from properties-api, the Spring Cloud Config Server that serves the config-files repository.
Package config loads the service configuration from properties-api, the Spring Cloud Config Server that serves the config-files repository.
platform/health
Package health serves /status and /healthcheck with the bodies of the Eve APIs (endpoints/status.py and eve-healthcheck), which monitoring and the Kubernetes probes already read.
Package health serves /status and /healthcheck with the bodies of the Eve APIs (endpoints/status.py and eve-healthcheck), which monitoring and the Kubernetes probes already read.
platform/lease
Package lease elects one active replica through a document in Mongo, as the outbox relay does: the holder renews the lease before it expires, and another replica takes it only after it expires or is released.
Package lease elects one active replica through a document in Mongo, as the outbox relay does: the holder renews the lease before it expires, and another replica takes it only after it expires or is released.
platform/metrics
Package metrics exposes the Prometheus metrics of an API at /metrics: the duration and the response size of every request by method, route and status, plus the Go runtime and the process.
Package metrics exposes the Prometheus metrics of an API at /metrics: the duration and the response size of every request by method, route and status, plus the Go runtime and the process.
platform/mongodb
Package mongodb connects to Mongo with the settings read by the Eve APIs.
Package mongodb connects to Mongo with the settings read by the Eve APIs.
platform/mongodb/mongotest
Package mongotest prepares the Mongo of the tests: a server started with --replSet but not initiated yet (a CI service container) is initiated as a single node replica set, and every caller waits until it has a primary.
Package mongotest prepares the Mongo of the tests: a server started with --replSet but not initiated yet (a CI service container) is initiated as a single node replica set, and every caller waits until it has a primary.
platform/pubsub
Package pubsub connects to Google Pub/Sub with the settings read from config.Config.
Package pubsub connects to Google Pub/Sub with the settings read from config.Config.
platform/redis
Package redis connects to Redis with the settings read from config.Config:
Package redis connects to Redis with the settings read from config.Config:
platform/search
Package search writes to Elasticsearch through its REST API (PUT/POST/DELETE /{index}/_doc|_update/{id}), which is what the Python client 7.x used by the Eve APIs and workers does, so no client library is needed.
Package search writes to Elasticsearch through its REST API (PUT/POST/DELETE /{index}/_doc|_update/{id}), which is what the Python client 7.x used by the Eve APIs and workers does, so no client library is needed.
platform/server
Package server holds the bootstrap shared by the services: logging, the HTTP server and graceful shutdown.
Package server holds the bootstrap shared by the services: logging, the HTTP server and graceful shutdown.
testkit
Package testkit has the helpers shared by the service tests: an isolated Mongo database, an Elasticsearch recorder, token signing and an HTTP client for handlers.
Package testkit has the helpers shared by the service tests: an isolated Mongo database, an Elasticsearch recorder, token signing and an HTTP client for handlers.

Jump to

Keyboard shortcuts

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