creativitykills / api-starter-kit
API starter kit for the Laravel framework
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.4
- laravel/fortify: ^1.29
- laravel/framework: ^12.26.2
- laravel/sanctum: ^4.2
- laravel/tinker: ^2.10.1
Requires (Dev)
- ekino/phpstan-banned-code: ^3.0
- fakerphp/faker: ^1.23
- friendsofphp/php-cs-fixer: ^3.86
- knuckleswtf/scribe: ^5.3
- larastan/larastan: ^3.6
- laravel/pail: ^1.2.2
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.6
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-mockery: ^2.0
- phpstan/phpstan-webmozart-assert: ^2.0
README
Minimal Laravel starter kit aimed at accelerating API development with authentication, and comprehensive documentation tooling built in.
Whats Inside?
โจ Authentication Ready
- Laravel Fortify as the backend for user management
- Create access token
- Refresh access token
- Revoke access token
- Laravel Sanctum integration for API token management with refresh token support
- Token-based authentication with configurable abilities and access levels
๐ Auto-Generated Documentation
- Scribe integration with custom extensions for enhanced API docs
- Improved Postman collection generation with pre-request script for automatic token generation for all endpoints
- Supports environment variables in API Documentation
- Structured response documentation with reusable classes (using Attributes)
- Structured API Documentation with groups & subgroups (using Attributes)
๐๏ธ Optional Action-based Architecture
- Action-based architecture for business logic
- DTOs for type-safe data transfer
๐งช Testing Foundation
- Pre-configured Pest testing setup, with existing tests for authentication
- PHPStan for static analysis
- PHP CS Fixer for code style
Quick Start
- Install using Laravel new command:
See https://laravel.com/docs/12.x/starter-kits#community-maintained-starter-kits
laravel new example-api --using=creativitykills/api-starter-kit
- Using Composer
composer create-project creativitykills/api-starter-kit
Your API documentation will be available at /docs
and your API endpoints will be ready for authentication and token management.
Default API Endpoints
- POST
/v1/auth/token/create
- User authentication and token issuance - POST
/v1/auth/token/refresh
- Refresh access tokens - POST
/v1/auth/token/revoke
- Revoke access tokens
Project Structure
The starter kit remains largely unchanged from the original Laravel application. However, here are some of the notable changes that have been made to the project.
Click to expand project structure
api-starter-kit/
โโโ app/
โ โโโ Actions/
โ โ โโโ Fortify/ # User management actions (Laravel Fortify)
โ โ โโโ Sanctum/ # API token management actions (Laravel Sanctum)
โ โ โโโ IssueAccessToken.php # This action can be used to issue API tokens
โ โโโ Contracts/ # Interface definitions
โ โ โโโ SupportsDocumentation.php # This interface is used to document API endpoints, usable in Requests & Actions
โ โโโ Data/
โ โ โโโ Enums/
โ โ โ โโโ Abilities.php # This enum is used to define the abilities of a user token
โ โ โ โโโ AccessLevel.php # This enum is used to define groups of abilities as access levels
โ โ โโโ IssueAccessTokenDto.php # This class is a simple DTO for holding the data needed to issue a new access token
โ โ โโโ IssuedAccessTokenDto.php # This class is a simple DTO for holding the data of an issued access token
โ โโโ Extensions/
โ โ โโโ Scribe/ # Here extend some parts of the Scribe package to allow for even better documentation
โ โ โโโ Concerns/
โ โ โ โโโ ExtendableAttributeNames.php
โ โ โโโ Config/
โ โ โ โโโ Defaults.php
โ โ โโโ Extracting/
โ โ โ โโโ Strategies/ # Extend the strategies to allow for custom responses and documentation groups
โ โ โ โโโ Metadata/
โ โ โ โ โโโ GetFromDocBlocks.php
โ โ โ โ โโโ GetFromMetadataAttributes.php
โ โ โ โ โโโ GetValidationRulesFromAction.php
โ โ โ โโโ Response/
โ โ โ โโโ UseResponseAttributes.php
โ โ โโโ Writing/ # Added support for generating even better Postman collections with pre-request scripts
โ โ โโโ Postman/
โ โ โ โโโ PostmanCollectionWriter.php
โ โ โ โโโ PostmanEndpointProcessor.php
โ โ โ โโโ Processors/ # Processors allow you even greater control over the Postman collection
โ โ โ โโโ CreateTokenEndpointProcessor.php
โ โ โ โโโ EndpointProcessor.php
โ โ โ โโโ RefreshTokenEndpointProcessor.php
โ โ โโโ Writer.php
โ โโโ Http/
โ โ โโโ [...]
โ โ โโโ Documentation/ # API documentation structure classes
โ โ โ โโโ Groups/ # API Documentation groups
โ โ โ โ โโโ AuthenticationGroup.php
โ โ โ โ โโโ GenericGroup.php
โ โ โ โ โโโ GenericSubgroup.php
โ โ โ โโโ Responses/ # API Response documentation classes
โ โ โ โโโ Authentication/
โ โ โ โ โโโ AccessTokenResponse.php # Response documentation for access tokens
โ โ โ โโโ BadRequestResponse.php
โ โ โ โโโ CreatedResponse.php
โ โ โ โโโ [...]
โ โ โ โโโ UnauthorizedResponse.php
โ โ โ โโโ UnprocessableEntityResponse.php
โ โ โโโ [...]
โ โโโ [...]
โโโ [...]