orebarranco/laravel-api-starter-kit
Composer 安装命令:
composer create-project orebarranco/laravel-api-starter-kit
包简介
Production-ready API-only starter kit for Laravel 13 with Sanctum auth, JSON:API responses, DTOs, Actions, and 100% test coverage.
README 文档
README
A production-ready, API-only starter built with Laravel 13 and PHP 8.4. Designed for scalable backends, mobile apps, SPAs, SaaS platforms, and microservices.
No frontend scaffolding. No Blade. Pure headless API.
Core Philosophy
- Thin controllers — business logic lives in Actions
- Typed DTOs hydrated from Form Requests via
toDto() - Strict typing throughout (
declare(strict_types=1),finalclasses) - JSON:API compliant responses
- Versioned APIs from day one
Features
- Token authentication via Laravel Sanctum
- Email verification with signed URLs
- Password reset via email
- Rate limiting (per IP and per user)
- API versioning (URI-based)
- Custom
readonlyDTOs (no external packages) - JSON:API resource objects via
JsonApiResource - Centralized exception handling
- Pest with 100% coverage enforced
- Static analysis via Larastan
- Automated refactoring with Rector
- Code formatting via Laravel Pint
Requirements
- PHP 8.4+
- Composer 2.x
- MySQL / PostgreSQL / SQLite
Quick Start
Via the Laravel installer (recommended):
laravel new myapp --using=orebarranco/laravel-api-starter-kit
Via Composer:
composer create-project orebarranco/laravel-api-starter-kit myapp
Via Git:
git clone https://github.com/orebarranco/laravel-api-starter-kit.git myapp
cd myapp
composer setup
composer test
Authentication
Protected routes require:
Authorization: Bearer {token}
| Endpoint | Method | Auth |
|---|---|---|
/api/v1/auth/register |
POST | — |
/api/v1/auth/login |
POST | — |
/api/v1/auth/logout |
POST | Bearer |
/api/v1/auth/me |
GET | Bearer |
/api/v1/auth/forgot-password |
POST | — |
/api/v1/auth/reset-password |
POST | — |
/api/v1/auth/email/verify/{id}/{hash} |
GET | Signed URL |
/api/v1/auth/email/resend |
POST | Bearer |
API Versioning
URI-based versioning. Each version is fully isolated:
app/Http/Controllers/Api/V1/
app/Http/Requests/Api/V1/
routes/api/v1.php
Response Format
All responses use Content-Type: application/vnd.api+json.
Success
{
"data": {
"id": "01kn38s0cv0edq25et3vyrxd7s",
"type": "users",
"attributes": { "name": "Carlos Méndez", "email": "carlos@example.com" }
},
"meta": { "request_id": "...", "version": "v1", "timestamp": "..." }
}
Error
{
"errors": [{
"status": "422",
"code": "VALIDATION_ERROR",
"title": "The given data was invalid.",
"detail": "The email field is required.",
"source": { "pointer": "/data/attributes/email" }
}],
"meta": { "request_id": "...", "version": "v1", "timestamp": "..." }
}
Project Structure
app/
├── Actions/ # Single-purpose use cases
├── DTOs/ # Immutable readonly DTOs
├── Exceptions/ # Typed exceptions + centralized handler
├── Http/
│ ├── Controllers/Api/ # Versioned, single-action controllers
│ ├── Middleware/ # ForceJsonResponse, EnsureEmailIsVerified
│ ├── Requests/Api/ # Validation + toDto()
│ └── Resources/Api/ # JSON:API resources
├── Models/
├── Providers/ # AppServiceProvider (rate limiting, email verification, password reset)
└── Traits/ # ApiResponse
routes/
├── api.php # Version grouping
└── api/v1.php
Action Pattern
Controllers delegate to single-purpose Action classes:
// Controller public function __invoke(RegisterRequest $request, RegisterUserAction $action): JsonResponse { $result = $action->execute($request->toDto()); return $this->success(new UserResource($result['user']), Response::HTTP_CREATED, [ 'token' => $result['token'], ]); } // Action public function execute(RegisterUserDTO $data): array { $user = User::query()->create([...]); event(new Registered($user)); return ['user' => $user, 'token' => $user->createToken('auth_token')->plainTextToken]; }
Rate Limiting
| Limiter | Routes | Limit |
|---|---|---|
auth |
register, login, forgot-password, reset-password, email verify | 5 req/min per IP |
api |
all authenticated endpoints | 120 req/min per user · 60 req/min per IP |
Email Verification
Sent automatically on registration via the Registered event.
GET /auth/email/verify/{id}/{hash} — no auth required (signed URL)
POST /auth/email/resend — requires Bearer token
Password Reset
POST /auth/forgot-password — sends reset link to email (no auth required)
POST /auth/reset-password — resets password and invalidates all tokens (no auth required)
The reset link points to FRONTEND_URL/reset-password?token=...&email=.... Configure FRONTEND_URL in your .env.
Middleware
force.json— enforcesAccept: application/vnd.api+jsonapi.version— setsX-API-Versionresponse headerverified— requires verified email →EMAIL_NOT_VERIFIED(403)
Testing
composer test # lint + static analysis + coverage composer test:unit # unit tests only
Powered by Pest 4 with 100% coverage enforced. Feature and unit tests for all controllers, actions, middleware, and exception handling.
Code Quality
composer lint # Rector + Pint
- PHPStan level max via Larastan
- Rector for automated refactoring
- Laravel Pint for code style
License
MIT License
orebarranco/laravel-api-starter-kit 适用场景与选型建议
orebarranco/laravel-api-starter-kit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「laravel」 「rest-api」 「JSON-API」 「starter-kit」 「sanctum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 orebarranco/laravel-api-starter-kit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 orebarranco/laravel-api-starter-kit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 orebarranco/laravel-api-starter-kit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provided middleware for generating of swagger-documentation file by run testing of restful API.
A PSR-7 compatible library for making CRUD API endpoints
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
Get wordpress nav menus and share the main site menus with the child sites.
A PHP nano framework for REST API's & Micro-Services
PHP client for the Jibit Identicator Project (KYC) API
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-14