fredoware/fredobase
Composer 安装命令:
composer create-project fredoware/fredobase
包简介
A lightweight plain-PHP framework for database-backed CRUD APIs.
README 文档
README
FredoBase is a lightweight plain-PHP API micro framework by Fredoware for quickly creating database-backed CRUD APIs.
It is intentionally small, readable, and easy to copy for future Fredoware projects.
FredoBase gives you:
- one bootstrap file
- reusable request/response/database helpers
- model factory functions
- file-based API endpoints
- SQL migrations
- module generator
Structure
api/ Public API endpoint files
app/Core/ Core request, response, database, repository classes
app/Modules/ Controllers, repositories, and validators by module
app/Support/ Shared helpers, model factories, mail helper
database/ Schema and migration SQL files
docs/ Tutorials
routes/api.php Module route definitions
fredobase FredoBase CLI
.env.example Environment template
Install With Composer
After the package is published on Packagist, create an application with:
composer create-project fredoware/fredobase my-api
cd my-api
Composer installs the dependencies and runs php fredobase install. The
installer creates .env, generates a unique APP_KEY, and never overwrites an
existing environment file.
Before the package is on Packagist, it can be tested directly from GitHub:
composer create-project fredoware/fredobase my-api dev-main --repository='{"type":"vcs","url":"https://github.com/fredoware/fredobaseapi"}'
Manual Setup
- Install dependencies and prepare the project:
composer install php fredobase install
- Check your database settings in
.env:
DB_HOST=localhost DB_DATABASE=appbase.db DB_USERNAME=root DB_PASSWORD=
- Run migrations:
php fredobase migrate
- Test the health endpoint:
http://localhost/appbase-api/api/health.php
Expected response:
{
"status": "success",
"message": "FredoBase API is running."
}
CLI Commands
Show help:
php fredobase help
Prepare a new checkout (safe to run more than once):
php fredobase install
Create a CRUD module:
php fredobase make:module product
Run migrations:
php fredobase migrate
After adding a field to a module model, generate and apply its migration:
php fredobase make:migration product php fredobase migrate
The module generator creates:
app/Modules/Product/ProductController.php
app/Modules/Product/ProductModel.php
app/Modules/Product/ProductRepository.php
app/Modules/Product/ProductValidator.php
database/migrations/YYYY_MM_DD_HHMMSS_create_product_table.sql
It also registers REST routes inside routes/api.php.
Starter Endpoints
api/health.php- API and database health checkapi/authLogin.php- basic account loginapi/authLogout.php- revoke the current bearer tokenapi/index.php- dispatch routed module requests
Starter Tables
account- minimal user/account tableauth_token- hashed, expiring bearer tokenssample_item- generic CRUD example table
Creating A New Module
Read the full tutorial:
Quick version:
php fredobase make:module product php fredobase migrate
Then test:
GET http://localhost/appbase-api/api/products
GET http://localhost/appbase-api/api/products/1
POST http://localhost/appbase-api/api/products
PUT http://localhost/appbase-api/api/products/1
DELETE http://localhost/appbase-api/api/products/1
Write routes require a bearer token by default. Existing file-based endpoints remain supported for backward compatibility.
Authentication
Run migrations and create the first administrator:
php fredobase migrate php fredobase make:admin admin@example.com change-this-password Admin User
Login with a JSON POST request to api/authLogin.php. A successful response
contains a bearer token. Send it to protected endpoints with:
Authorization: Bearer YOUR_TOKEN
Protect an endpoint and access the authenticated account with:
$user = requireAuth();
Require one or more roles with:
$admin = requireRole('Admin'); $staff = requireRole(['Admin', 'Staff']);
Revoke the current token by sending an authenticated POST request to
api/authLogout.php. Token lifetime defaults to 24 hours and can be changed
with AUTH_TOKEN_TTL in .env.
GitHub Notes
Commit .env.example, but do not commit .env.
The .gitignore already excludes .env, logs, temporary files, and uploaded media.
fredobaseapi
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2026-07-14