Extensions System
When auto-generated APIs aren't enough, extend Baasix with your own logic. Hooks intercept operations, custom endpoints add new routes, and scheduled tasks run in the background — all while keeping your code organized and maintainable.
Your Logic, Baasix Foundation
The auto-generated API covers 80% of use cases. Extensions let you build the other 20% without fighting the framework.
Baasix extensions follow a simple, consistent pattern. Hooks let you intercept operations before or after they happen — validate data, transform payloads, trigger side effects, or block operations. Custom endpoints give you full control over new routes with access to all Baasix services. Scheduled tasks run cron jobs for background processing. Everything is TypeScript-first with full access to the Baasix internals.
- Hooks: intercept create, read, update, delete operations
- Custom endpoints: add new routes with full request/response control
- Scheduled tasks: cron-based background jobs
- Full TypeScript support with typed context and services
- Hot reload in development — change code, see results
- Access to all Baasix services: database, auth, files, etc.
- Organize extensions in a clean folder structure
Extend Without Complexity
Adding custom logic should be simple, not require learning a new framework.
✓ With Baasix
- Drop files in extensions folder, auto-discovered
- Typed context gives access to services and data
- Works alongside auto-generated endpoints
- Hot reload sees changes instantly in dev
- CLI scaffolds extension boilerplate
✗ Traditional Approach
- Configure middleware chains and routers
- Manually inject dependencies and context
- Risk breaking auto-generated functionality
- Restart server for every code change
- Write all boilerplate from scratch
Extension Types
Hooks
Run custom code before or after CRUD operations. Validate input, transform data, send notifications, or block requests.
Custom Endpoints
Add new API routes with complete control. Complex queries, external integrations, or custom business logic.
Scheduled Tasks
Cron-based jobs for background processing. Send digest emails, clean up data, sync with external systems.
Event Listeners
React to system events like user registration, file uploads, or authentication. Decouple your logic.
Service Access
Extensions get typed access to database queries, auth, files, notifications, and all other Baasix services.
TypeScript Native
Full IntelliSense, compile-time checks, and auto-completion. Catch errors before they reach production.
What You Can Build
Extensions enable any custom functionality your application needs.
Custom Validation
Hooks that validate complex business rules. Check inventory before orders, verify user eligibility, enforce data integrity.
External Integrations
Custom endpoints that talk to Stripe, Twilio, SendGrid, or any third-party API. Process webhooks and sync data.
Background Processing
Scheduled tasks for report generation, data aggregation, cleanup jobs, and system maintenance.
Complex Queries
Custom endpoints for queries that need multiple collections, complex aggregations, or special formatting.
Extensions FAQ
Where do I put extension files?
Extensions live in the `extensions` folder of your project. Each extension is a folder with an `index.ts` that exports hooks, endpoints, or scheduled tasks. The CLI can scaffold the structure for you.
Can hooks modify the response?
Yes! Post-operation hooks can transform the response before it's sent to the client. Add computed fields, filter sensitive data, or restructure the output.
How do scheduled tasks handle failures?
Failed tasks are logged with error details. You can configure retry logic, error notifications, and dead-letter handling based on your needs.
Can I use npm packages in extensions?
Absolutely. Extensions are just TypeScript files — import any npm package you need. Database clients, API SDKs, utility libraries — all work seamlessly.
Ready to build faster?
Join developers who are shipping production-ready backends in hours, not weeks.