Skip to content

trafficinc/dbrelay-php

Repository files navigation

DBRelay

DBRelay turns a MySQL database into an instant REST API.

Run two commands:

dbrelay init
dbrelay serve

DBRelay inspects your schema, detects tables and relationships, generates CRUD endpoints, and serves them through a lightweight PHP runtime.

DBRelay Swagger UI dashboard

Why DBRelay?

Because building CRUD APIs is repetitive.

Every project starts with the same:

  • authentication
  • database setup
  • CRUD endpoints

DBRelay reads your MySQL schema and automatically generates:

  1. Routes
  2. Controllers
  3. Query handlers
  4. Relationship mappings

Features

  • Instant REST API from MySQL
  • Automatic schema detection
  • Relationship support (?include=)
  • Pagination & filtering
  • Zero configuration setup
  • Built-in CLI server
  • OpenAPI JSON generation
  • Swagger UI dashboard
  • Schema inspection command

Usage

Install dependencies:

composer install
  1. dbrelay init
  2. dbrelay serve
  3. Open http://localhost:8000

Example:

php apps/dbrelay-cli/bin/dbrelay init
php apps/dbrelay-cli/bin/dbrelay inspect
php apps/dbrelay-cli/bin/dbrelay serve

Open the API dashboard:

http://localhost:8000/docs

With the included demo:

cd examples/mysql-demo
docker compose up -d
cd ../..

php apps/dbrelay-cli/bin/dbrelay init \
  --no-interaction \
  --host=127.0.0.1 \
  --port=3306 \
  --database=shop_db \
  --username=dbrelay \
  --password=dbrelay

php apps/dbrelay-cli/bin/dbrelay serve

How it works

DBRelay reads your MySQL schema and automatically generates:

  1. Routes
  2. Controllers
  3. Query handlers
  4. Relationship mappings

Runtime flow:

HTTP Request
  -> ZeroCore Kernel
  -> Generated route
  -> CRUD controller
  -> DB engine query builder
  -> JSON response

Commands

dbrelay init       # Create .dbrelay/config.php
dbrelay inspect    # Print tables and relationships
dbrelay serve      # Start the generated API
dbrelay generate   # Generate OpenAPI docs and route cache

Docker And Scripts

Build the CLI image:

docker build -f docker/Dockerfile -t dbrelay .
docker run --rm dbrelay --help

Run DBRelay with the MySQL demo through Docker Compose:

docker compose -f docker/docker-compose.yml up --build

This starts MySQL, loads the sample schema, initializes DBRelay inside the app container, and serves the generated API on http://localhost:8000.

Local setup helper:

scripts/install.sh

Start the local development server after running dbrelay init:

scripts/dev-server.sh

Documentation

Monorepo Layout

  • apps/dbrelay-cli: user-facing CLI app
  • packages/zerocore: minimal PHP HTTP kernel
  • packages/db-engine: MySQL schema, relation, query, and endpoint engine
  • packages/openapi: OpenAPI documentation generator
  • examples/mysql-demo: runnable MySQL demo database
  • docs: architecture and project docs

Roadmap

  • MySQL support: v0.1
  • PostgreSQL support
  • JWT authentication
  • OpenAPI dashboard
  • Published Docker image
  • Plugin system

Releases

No releases published

Packages

 
 
 

Contributors

Languages