Ruby on Rails microservice scaffold with:
- REST JSON API (
GET /entities,POST /entities) - GraphQL (
POST /graphql) query + mutation - Kafka producer + consumer using Protobuf payloads
- PostgreSQL persistence
- Tests at interface/service level
- Ruby
3.2.3 - Bundler
2.5+ - PostgreSQL (local) or Docker
- Kafka broker (local) or Docker (compose includes Redpanda)
bundle installSet env vars:
export POSTGRES_HOST=localhost
export POSTGRES_DB=ror_starter_development
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export KAFKA_BROKERS=localhost:9092
export KAFKA_TOPIC=entity-events
export KAFKA_GROUP_ID=ror-starter-groupPrepare DB:
bundle exec rails db:prepareRun API server:
bundle exec rails serverRun Kafka consumer (separate terminal):
bundle exec rails kafka:consumedocker compose up --buildThis starts:
apponhttp://localhost:3000db(PostgreSQL)kafka(Redpanda, Kafka-compatible)
curl http://localhost:3000/entitiescurl -X POST http://localhost:3000/entities \
-H "Content-Type: application/json" \
-d '{"entity":{"name":"Sample","description":"Created via REST"}}'curl -X POST http://localhost:3000/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ entities { id name description } }"}'curl -X POST http://localhost:3000/graphql \
-H "Content-Type: application/json" \
-d '{"query":"mutation { createEntity(input: { name: \"Sample\", description: \"Created via GraphQL\" }) { status } }"}'- REST/GraphQL write endpoints publish Protobuf bytes to Kafka.
- Consumer reads Kafka messages.
- Consumer decodes Protobuf and writes
Entityrecords to PostgreSQL. - REST/GraphQL read endpoints query PostgreSQL via Active Record.
- Convention over configuration: Rails autoloads classes by path (
app/services/...). - Active Record:
Entity < ApplicationRecordmaps directly toentitiestable. - Strong Parameters: controller whitelists accepted fields with
permit. - Routing DSL:
resources :entitiescreates RESTful route helpers. - Rake task integration:
rails kafka:consumewires background consumer behavior.
Run all tests:
bundle exec rails testIncluded tests cover:
- REST interface behavior
- GraphQL interface behavior
- Kafka consumer payload-to-database behavior
- basic model validation