承接 byjg/rest-reference-architecture 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

byjg/rest-reference-architecture

Composer 安装命令:

composer require byjg/rest-reference-architecture

包简介

Production-ready PHP REST API boilerplate that lets you focus on building your business logic, not the infrastructure.

README 文档

README

Sponsor Build Status Opensource ByJG GitHub source GitHub license GitHub release

Production-ready PHP REST API boilerplate that lets you focus on building your business logic, not the infrastructure.

Why Use This?

Every new REST API needs the same boilerplate: authentication, migrations, an ORM, OpenAPI docs, a test harness, and a DI container. Setting all of that up correctly takes days — and it's not the work your users care about.

This template does the wiring once, correctly, so you start on day one writing business logic instead of plumbing. And because it's a template you own — not a framework you depend on — you can change, remove, or replace any part of it without asking permission.

Quick Start

# Create your project
composer -sdev create-project byjg/rest-reference-architecture my-api ^6.1

# Start containers
cd my-api
docker compose up -d

# Run migrations
composer migrate -- --env=dev reset

# Your API is ready!
curl http://localhost:8080/sample/ping

📚 Complete Getting Started Guide →

Architecture Overview

mindmap
  (("Reference Architecture"))
    ("PSR Standards")
      ("WebRequests")
      ("Container & Dependency Injection")
      ("Cache")
    ("Authentication & Authorization")
    ("Decoupled Code")
    ("Database")
      ("ORM Integration")
      ("Migration")
    ("OpenAPI Integration")
      ("Routing")
      ("Rest Methods")
      ("Contract Testing")
      ("Documentation")
    ("Error Handling")
Loading

Key Features

  • 🚀 Code generator — one command scaffolds Model, Repository, Service, REST controller, and tests from any database table
  • 🏗️ Two patterns — choose Repository (DI + Service layer) or ActiveRecord per entity; mix them in the same project
  • 🔐 Auth out of the box — JWT login, token refresh, password reset, and role-based access control (RBAC) included
  • 📖 OpenAPI-first — routes are driven by openapi.json; Swagger UI, contract testing, and docs stay in sync automatically
  • 🗄️ Database migrations — versioned up/down SQL migrations with a one-command runner and ORM integration
  • 🧪 In-process testingFakeApiRequester runs the full API stack inside PHPUnit, no web server needed
  • 🐳 Docker ready — MySQL, PHP-FPM, and Nginx pre-configured; docker compose up -d and you're running
  • ⚙️ PSR standards — PSR-7 (HTTP messages), PSR-11 (container), PSR-6/16 (cache)
# Generate a complete CRUD API from a single table
composer codegen -- --env=dev --table=products all --save

Documentation

Getting Started

  1. Installation & Setup – Install the template, configure environments, and review prerequisites.
  2. Create Your First Table – Define your first migration and schema.
  3. Add Fields – Safely evolve existing tables.
  4. Create REST Endpoints – Generate REST handlers from your tables.
  5. Windows Setup – WSL/Windows-specific checklist.
  6. Unattended Setup – Automate installs for CI/CD pipelines.

Guides

  • REST Controllers – Define routes with PHP attributes; keep controllers thin.
  • Authentication – Configure JWT login flows and RBAC enforcement.
  • Database Migrations – Version and run schema migrations in every environment.
  • ORM – Use MicroORM for repository and ActiveRecord patterns.
  • Service Layer – Organize business logic, orchestration, and transaction boundaries.
  • Repository Patterns – Implement complex queries, UUID handling, and filtering helpers.
  • Template Customization – Tailor the generator templates to match your coding standards.
  • Testing – Unit, integration, and contract testing with FakeApiRequester.
  • JWT Authentication Advanced – Extend tokens with custom claims and refresh logic.
  • Error Handling – Map exceptions to HTTP responses and logging patterns.
  • Configuration – Layer configurations, secrets, and environment overrides.

Concepts

Reference

  • Code Generator – Automate models, repositories, services, controllers, and tests.
  • AttributesRequireAuthenticated, RequireRole, ValidateRequest, and custom attributes.
  • Traits – Timestamp and soft-delete helpers for models.
  • Scriptify – REPL, CLI runner, and service manager utilities.
  • Components – Full PHP component dependency graph.

Real-World Example

# 1. Create database table
cat > db/migrations/up/00002-create-products.sql << 'EOF'
CREATE TABLE products (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    price DECIMAL(10,2) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
EOF

# 2. Run migration
composer migrate -- --env=dev update

# 3. Generate all code
composer codegen -- --env=dev --table=products all --save

# 4. Generate the OpenAPI spec so routing is active
composer run openapi

# 5. Log in and capture the token
TOKEN=$(curl -s -X POST http://localhost:8080/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin@example.com","password":"!P4ssw0rdstr!"}' \
  | jq -r '.token')

# 6. Call your new endpoint
curl -s -H "Authorization: Bearer $TOKEN" http://localhost:8080/products | jq

You just created a complete CRUD API with:

  • ✅ Model with validation
  • ✅ Repository for data access
  • ✅ Service for business logic
  • ✅ REST controller with GET, POST, PUT endpoints
  • ✅ Functional tests
  • ✅ OpenAPI documentation
  • ✅ JWT authentication

Requirements

  • PHP 8.3+ (8.5 recommended)
  • Docker & Docker Compose (optional but recommended)
  • Composer
  • Git

Support & Community

Not a Framework

This is a template, not a framework. You own the code:

  • ✅ Full control over every file
  • ✅ No vendor lock-in
  • ✅ Customize anything you need
  • ✅ Remove what you don't need

License

This project is open source. See LICENSE for details.

Dependencies

📚 Complete Component Dependency Graph →

Open source ByJG

byjg/rest-reference-architecture 适用场景与选型建议

byjg/rest-reference-architecture 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 159 次下载、GitHub Stars 达 17, 最近一次更新时间为 2023 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 byjg/rest-reference-architecture 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 byjg/rest-reference-architecture 我们能提供哪些服务?
定制开发 / 二次开发

基于 byjg/rest-reference-architecture 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 159
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-09