Server
Enfyra Server Documentation This documentation covers the Enfyra server architecture, APIs, and development guides. It's organized to help you find information quickly, whether you're learning the basics or looking up specific details. New to Enfyra? Start with the Installation G
Enfyra Server Documentation
This documentation covers the Enfyra server architecture, APIs, and development guides. It's organized to help you find information quickly, whether you're learning the basics or looking up specific details.
New to Enfyra? Start with the Installation Guide to set up your backend and frontend.
Quick Navigation
Getting Started
- Repository Methods - Complete guide to database operations (find, create, update, delete)
- Context Object ($ctx) - All available properties and methods in the context
- API Lifecycle - How requests flow through the system
Core Concepts
- Hooks and Handlers - Creating preHooks, postHooks, and custom handlers
- Guards - Declarative route protection (IP blocking, rate limiting)
- Query Filtering - MongoDB-like filtering operators and examples
- Error Handling - Throwing errors and handling exceptions
Security & Access Control
- Field Permissions - Per-column and per-relation access control (isPublished baseline + rules)
- Guards - Declarative route protection (IP blocking, rate limiting)
Advanced Topics
- WebSocket Guide - Real-time WebSocket communication
- Cache Operations - Distributed caching and locking
- File Handling - File uploads and management
- Cluster Architecture - Multi-instance coordination
- Runtime Redis Admin - Available in the admin app Runtime Monitor Redis tab; shows current-app Redis categories, user-cache allocation, and editable
$cachekeys - Schema migration preview - Confirmed
table_definitionPATCH, hash, relation removal warnings
Finding What You Need
"I want to query data from a table"
See Repository Methods - find()
"I need to create a new record"
See Repository Methods - create()
"I want to update a record"
See Repository Methods - update()
"I need to delete a record"
See Repository Methods - delete()
"What properties are available in $ctx?"
"How do I access request body and params?"
See Context Reference - Request Data
"How do I use repositories in my code?"
See Context Reference - Repositories
"What helper functions are available?"
See Context Reference - Helpers & Cache
"How does the request lifecycle work?"
See API Lifecycle
"How do hooks execute in order?"
See API Lifecycle - Execution Order
"I want to validate data before saving"
See Hooks and Handlers - preHooks
"I need to modify response data"
See Hooks and Handlers - postHooks
"I want to write custom business logic"
See Hooks and Handlers - Custom Handlers
"How do I filter data with complex conditions?"
See Query Filtering
"How do I throw errors properly?"
See Error Handling
"I want to control who can see specific columns"
"I want to protect my API from abuse"
See Guards for declarative route protection, or Context Reference - Helpers & Cache for code-based rate limiting
"I need to use Redis cache"
See Cache Operations
"I want to upload files"
See File Handling
"I need real-time WebSocket communication"
See WebSocket Guide
"How do repositories work?"
"What methods does repository have?"
See Repository Methods - Complete list of find, create, update, delete methods
Documentation Structure
All documentation is organized step-by-step, with clear examples and explanations. Each document focuses on a specific topic and includes:
- Overview - What the topic is about
- Step-by-step guides - How to use it
- Examples - Real code examples
- Reference - Complete API reference
- Common patterns - Best practices and tips
Repository Methods Overview
The repository is the main way to interact with your database tables. Each table you create automatically gets a repository accessible through $ctx.$repos.tableName.
Available Methods:
- find() - Query records with filtering, sorting, and pagination
- create() - Create new records
- update() - Update existing records by ID
- delete() - Delete records by ID
All methods return data in a consistent format: { data: [...], meta: {...} }
See Repository Methods Guide for complete details.
Context Object Overview
The $ctx (context) object is available in all hooks and handlers. It provides access to:
- Request Data:
$ctx.$body,$ctx.$params,$ctx.$query,$ctx.$user - Repositories:
$ctx.$repos.tableNamefor database operations - Helpers:
$ctx.$helpersfor JWT, bcrypt, file operations - Cache:
$ctx.$cachefor Redis operations - Logging:
$ctx.$logs()for adding logs to responses - Error Handling:
$ctx.$throw['400']()for throwing errors
See Context Reference for complete details.
API Lifecycle Overview
Every API request follows this flow:
- Route Detection - System matches request to route definition
- Pre-Auth Guards - IP blocking, global rate limiting
- Context Setup - Creates
$ctxwith repositories and helpers - Authentication - JWT verification and role check
- Post-Auth Guards - User-specific rate limiting
- preHooks Execution - Runs all matching preHooks sequentially
- Handler Execution - Custom handler or default CRUD operation
- postHooks Execution - Runs all matching postHooks sequentially
- Response - Returns processed data
The same $ctx object flows through all phases, so modifications in preHooks are visible to handlers and postHooks.
See API Lifecycle for complete details.
Learning Path
New to Enfyra Server? Follow this step-by-step path:
- Repository Methods - Start here! Learn how to query, create, update, and delete records
- Context Reference - Understand all available properties and methods in
$ctx - API Lifecycle - Learn how requests flow through the system
- Hooks and Handlers - Customize API behavior with hooks and handlers
- Guards - Protect routes with IP blocking and rate limiting
- Query Filtering - Master filtering and querying data
- Error Handling - Handle errors properly
Advanced topics: - Cache Operations - Distributed caching and locking - File Handling - File uploads and management - Cluster Architecture - Multi-instance coordination
Next Steps
- Start with Repository Methods to learn database operations
- Read Context Reference to understand available properties
- Check API Lifecycle to see how everything fits together
- Explore Hooks and Handlers for customization
For specific questions, use the Quick Navigation section above to jump directly to relevant documentation.