https://github.com/timanthonyalexander/base-api
A production-ready KISS-first PHP 8.4+ framework for building REST APIs.
https://github.com/timanthonyalexander/base-api
api deepl framework i18n microframework migrations openai openapi orm php php-8 rest translations typescript
Last synced: 18 days ago
JSON representation
A production-ready KISS-first PHP 8.4+ framework for building REST APIs.
- Host: GitHub
- URL: https://github.com/timanthonyalexander/base-api
- Owner: TimAnthonyAlexander
- Created: 2025-09-09T21:22:35.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2026-02-02T19:46:22.000Z (about 1 month ago)
- Last Synced: 2026-02-03T10:23:14.748Z (about 1 month ago)
- Topics: api, deepl, framework, i18n, microframework, migrations, openai, openapi, orm, php, php-8, rest, translations, typescript
- Language: PHP
- Homepage: https://base-api.de
- Size: 4.42 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# BaseAPI
[](https://codespaces.new/TimAnthonyAlexander/base-api-template?quickstart=1)
A tiny, KISS-first PHP 8.4+ framework for building production-ready REST APIs.
BaseAPI gets out of your way and lets you build APIs in minutes, not hours. Define your models with typed properties, write minimal controllers, and let the framework handle migrations, validation, caching, and documentation automatically.
**[Read the Documentation](https://base-api.de)**
---
## Quick Start
```bash
composer create-project baseapi/baseapi-template my-api
cd my-api
php mason serve
```
Your API is now running at `http://localhost:7879`.
---
## How Fast Is It to Code?
### Define a Model
Typed properties become your database schema. Migrations are generated automatically.
```php
'index',
];
}
```
Run `./mason migrate:generate` and `./mason migrate:apply`. Done.
### Write a Controller
```php
validate([
'name' => 'required|string|min:3',
'price' => 'required|numeric|min:0',
]);
$product = new Product();
$product->name = $this->name;
$product->price = $this->price;
$product->save();
return JsonResponse::created($product->jsonSerialize());
}
}
```
### Add Routes
```php
get('/products', [ProductController::class]);
$router->post('/products', [
RateLimitMiddleware::class => ['limit' => '10/1m'],
ProductController::class,
]);
```
That's it. Your API is ready.
---
## Production-Ready from Day One
BaseAPI v1.0.0 is built for production with everything you need:
**Database & Migrations**
- MySQL, PostgreSQL, and SQLite support
- Automatic migration generation from model definitions
- Safe migration mode for production deployments
- Relationship support (belongsTo, hasMany)
**Performance & Caching**
- Sub-millisecond framework overhead with compiled route caching
- O(1) static route lookups via hash map dispatch
- Segment-based dynamic route matching with zero allocation
- File and Redis-based caching with tagged invalidation
- Query result caching
- Connection pooling
- Opcache-optimized route compilation
**Security**
- CORS middleware with configurable allowlists
- Rate limiting with multiple storage backends
- Input validation with 20+ built-in rules
- SQL injection protection via parameterized queries
- Session and API token authentication
**Developer Experience**
- Automatic OpenAPI specification generation
- TypeScript type generation for frontend integration
- Mason CLI for migrations, code generation, queue management, and route caching
- Route inspection and performance tools (`route:cache`, `route:list`, `route:clear`)
- Comprehensive validation with custom rules
- Built-in file upload handling with security checks
**Async Processing**
- Queue system with database and sync drivers
- Job retry logic with exponential backoff
- Worker management with memory and time limits
**Internationalization**
- Full i18n support with namespace organization
- Automatic translation via OpenAI or DeepL
- Token scanning and management CLI
**AI Integration**
- OpenAI Responses API wrapper with streaming support
- Function calling (tools) for AI-powered features
- Structured JSON output with schema validation
- Support for reasoning models (o-series)
**Deployment**
- Environment-based configuration
- Health check endpoints
- Docker-ready
- Supports traditional hosting, VPS, and cloud platforms
---
## Code Quality
BaseAPI maintains high standards with:
- PHPStan level 7 static analysis
- Comprehensive test suite across all implemented features
- Rector for PHP 8.4+ code modernization
- Pre-commit hooks for syntax, tests, and security
- Performance benchmarks: 1,350+ req/s, <1ms overhead, 0.8MB/request
---
## Documentation
Everything you need to know:
**[Full Documentation](https://base-api.de)**
Topics covered:
- Getting started guide
- Models, migrations, and relationships
- Controllers, routing, and validation
- Caching strategies and configuration
- Queue system and background jobs
- Authentication and authorization
- File storage and uploads
- Internationalization
- AI integration (OpenAI)
- Deployment guides
- API reference
---
## Requirements
- PHP 8.4+
- Composer
- MySQL 8.0+, PostgreSQL 13+, or SQLite 3.35+
- Redis 6.0+ (optional, for caching and queues)
---
## Contributing
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
---
## License
BaseAPI is open-source software licensed under the [MIT license](LICENSE).
---
## Links
- **[Documentation](https://base-api.de)** The full documentation for BaseAPI
- **[Template Repository](https://github.com/timanthonyalexander/base-api-template)** This is the project you start with when building your own API
- **[Hotel Comparison Project](https://hotel.timanthonyalexander.de)** This is a Hotel Comparison API + Frontend UI ontop of BaseAPI
- **[Webshop w/ Stripe Project](https://shop.timanthonyalexander.de)** This is a WebShop API + Frontend UI ontop of BaseAPI
- **[Flix Movies and Series Website](https://github.com/timanthonyalexander/base-api-flix)** This is a Netflix-like application with movies and series