App API
Core APIs for accessing your app instance, grouping routes under shared prefixes, and auto-loading route files from the filesystem.
On this page
What You'll Learn
How to access the app singleton from any file
Grouping routes under shared prefixes with nesting
Auto-loading route files from a directory
File conventions for route auto-loading
1
getApp() — App Singleton Accessor
Route files no longer need the app instance passed in. Any file can import and register routes directly using getApp(). This returns the singleton app instance created by createApp().
Using getApp()
typescript
Why use getApp()?
- • No need to thread the app instance through imports
- • Route files become self-contained and portable
- • Works anywhere after
createApp()has been called - • Pairs naturally with
app.loadRoutes()for auto-loading
2
app.group() — Route Grouping
Group routes under a shared prefix. Supports the full chainable API and nesting for clean, organized route definitions.
Basic Route Grouping
typescript
Nested Groups
typescript
Group Features
- • Shared prefix applied to all child routes
- • Full chainable API inside the group callback
- • Unlimited nesting depth
- • Middleware can be applied per-group or per-route
3
app.loadRoutes() — Auto-Load Route Files
Automatically imports route files from a directory. Top-level files are loaded directly. Subdirectories load only index.ts — other files like actions.ts or schemas.ts are ignored by the loader and pulled in by the index.
Usage
typescript
Directory Convention
text
Example Route File
typescript
Example Route Directory
typescript
Loading Rules
- • Top-level
.tsfiles are loaded directly - • Subdirectories only load
index.ts - • Supporting files (
actions.ts,schemas.ts) are imported by the index, not the loader - • Keeps route directories self-contained and organized