Skip to content

Commit b9c091b

Browse files
committed
docs: add comprehensive auto-discovery configuration documentation
- Add Auto-Discovery Defaults section to Module Defaults - Add dedicated Auto-Discovery Configuration section - Document all configuration options with detailed tables - Include practical examples for different loading strategies - Add environment variable documentation - Cover development features (hot reloading, custom patterns) - Include production optimization examples - Maintain backward compatibility documentation
1 parent 892f90f commit b9c091b

1 file changed

Lines changed: 179 additions & 0 deletions

File tree

docs/CONFIGURATION_REFERENCE.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This document provides a comprehensive reference for all configuration options a
99
- [Service Discovery](#service-discovery)
1010
- [Database Configuration](#database-configuration)
1111
- [Module Defaults](#module-defaults)
12+
- [Auto-Discovery Configuration](#auto-discovery-configuration)
1213
- [Logging Configuration](#logging-configuration)
1314
- [Security Configuration](#security-configuration)
1415
- [External Services](#external-services)
@@ -252,6 +253,31 @@ Configure default behaviors for modules.
252253
| `stripUnknown` | `boolean` | `true` | Strip unknown properties from validated data |
253254
| `abortEarly` | `boolean` | `false` | Stop validation on first error |
254255

256+
#### Auto-Discovery Defaults
257+
258+
| Property | Type | Default | Description |
259+
|----------|------|---------|-------------|
260+
| `enabled` | `boolean` | `true` | Enable automatic module discovery |
261+
| `paths` | `string[]` | `['./modules', './src/modules']` | Directories to search for modules |
262+
| `patterns` | `string[]` | `['**/*.module.{ts,js}', '**/index.{ts,js}', '**/*.config.{ts,js}']` | File patterns to match |
263+
| `recursive` | `boolean` | `true` | Search directories recursively |
264+
| `loadingStrategy` | `'eager' \| 'lazy' \| 'conditional'` | `'eager'` | Module loading strategy |
265+
| `watchForChanges` | `boolean` | `false` | Enable file watching for hot reloading (development) |
266+
| `ignorePatterns` | `string[]` | `['**/*.test.{ts,js}', '**/*.spec.{ts,js}', '**/node_modules/**']` | Patterns to ignore during discovery |
267+
| `loadOrder` | `'alphabetical' \| 'dependency' \| 'custom'` | `'dependency'` | Module loading order strategy |
268+
| `failOnError` | `boolean` | `false` | Throw error if module discovery fails |
269+
| `maxDepth` | `number` | `5` | Maximum directory depth to search |
270+
271+
**Loading Strategies:**
272+
- **`eager`**: Load all modules immediately during app startup
273+
- **`lazy`**: Load modules on first request to their routes
274+
- **`conditional`**: Load modules based on environment or feature flags
275+
276+
**Load Order Strategies:**
277+
- **`alphabetical`**: Load modules in alphabetical order by name
278+
- **`dependency`**: Analyze and resolve module dependencies using topological sort
279+
- **`custom`**: Use custom order specified in module configurations
280+
255281
#### Example
256282

257283
```javascript
@@ -273,6 +299,17 @@ Configure default behaviors for modules.
273299
enabled: true,
274300
stripUnknown: false,
275301
abortEarly: true
302+
},
303+
autoDiscovery: {
304+
enabled: true,
305+
paths: ['./modules', './src/modules', './app/modules'],
306+
patterns: ['**/*.module.{ts,js}', '**/index.{ts,js}'],
307+
loadingStrategy: 'eager',
308+
watchForChanges: false, // Set to true in development
309+
ignorePatterns: ['**/*.test.{ts,js}', '**/node_modules/**'],
310+
loadOrder: 'dependency',
311+
failOnError: false,
312+
maxDepth: 5
276313
}
277314
}
278315
}
@@ -288,6 +325,148 @@ Configure default behaviors for modules.
288325
- `DEFAULT_RATE_LIMIT_REQUESTS` or `MORO_RATE_LIMIT_REQUESTS`
289326
- `DEFAULT_RATE_LIMIT_WINDOW` or `MORO_RATE_LIMIT_WINDOW`
290327
- `VALIDATION_ENABLED` or `MORO_VALIDATION_ENABLED`
328+
- `AUTO_DISCOVERY_ENABLED` or `MORO_AUTO_DISCOVERY_ENABLED`
329+
- `AUTO_DISCOVERY_PATHS` or `MORO_AUTO_DISCOVERY_PATHS` (comma-separated)
330+
- `AUTO_DISCOVERY_PATTERNS` or `MORO_AUTO_DISCOVERY_PATTERNS` (comma-separated)
331+
- `AUTO_DISCOVERY_LOADING_STRATEGY` or `MORO_AUTO_DISCOVERY_LOADING_STRATEGY`
332+
- `AUTO_DISCOVERY_WATCH_FOR_CHANGES` or `MORO_AUTO_DISCOVERY_WATCH_FOR_CHANGES`
333+
- `AUTO_DISCOVERY_LOAD_ORDER` or `MORO_AUTO_DISCOVERY_LOAD_ORDER`
334+
- `AUTO_DISCOVERY_FAIL_ON_ERROR` or `MORO_AUTO_DISCOVERY_FAIL_ON_ERROR`
335+
- `AUTO_DISCOVERY_MAX_DEPTH` or `MORO_AUTO_DISCOVERY_MAX_DEPTH`
336+
337+
## Auto-Discovery Configuration
338+
339+
MoroJS includes a powerful auto-discovery system that automatically finds and loads modules from your filesystem. This system supports multiple loading strategies, dependency resolution, and hot reloading for development.
340+
341+
### Basic Usage
342+
343+
```javascript
344+
// Simple auto-discovery
345+
const app = createApp({
346+
autoDiscover: true // Use defaults
347+
});
348+
349+
// Advanced configuration
350+
const app = createApp({
351+
autoDiscover: {
352+
enabled: true,
353+
paths: ['./modules', './src/modules'],
354+
loadingStrategy: 'lazy',
355+
watchForChanges: true // Development only
356+
}
357+
});
358+
```
359+
360+
### Legacy Compatibility
361+
362+
```javascript
363+
// Legacy modulesPath (still supported)
364+
const app = createApp({
365+
modulesPath: './modules' // Equivalent to autoDiscover.paths: ['./modules']
366+
});
367+
```
368+
369+
### Loading Strategies
370+
371+
#### Eager Loading (Default)
372+
All modules are loaded immediately during application startup.
373+
374+
```javascript
375+
{
376+
autoDiscover: {
377+
loadingStrategy: 'eager'
378+
}
379+
}
380+
```
381+
382+
#### Lazy Loading
383+
Modules are loaded on first request to their routes.
384+
385+
```javascript
386+
{
387+
autoDiscover: {
388+
loadingStrategy: 'lazy'
389+
}
390+
}
391+
```
392+
393+
#### Conditional Loading
394+
Modules are loaded based on environment or feature flags.
395+
396+
```javascript
397+
{
398+
autoDiscover: {
399+
loadingStrategy: 'conditional'
400+
}
401+
}
402+
```
403+
404+
### Development Features
405+
406+
#### Hot Reloading
407+
Enable file watching for automatic module reloading during development:
408+
409+
```javascript
410+
{
411+
autoDiscover: {
412+
watchForChanges: process.env.NODE_ENV === 'development',
413+
loadingStrategy: 'eager'
414+
}
415+
}
416+
```
417+
418+
#### Custom Patterns
419+
Configure custom file patterns for different project structures:
420+
421+
```javascript
422+
{
423+
autoDiscover: {
424+
patterns: [
425+
'**/*.module.{ts,js}',
426+
'**/modules/*.{ts,js}',
427+
'**/*-module.{ts,js}'
428+
],
429+
ignorePatterns: [
430+
'**/*.test.{ts,js}',
431+
'**/*.spec.{ts,js}',
432+
'**/node_modules/**',
433+
'**/dist/**'
434+
]
435+
}
436+
}
437+
```
438+
439+
### Dependency Resolution
440+
441+
The auto-discovery system can automatically resolve and order module dependencies:
442+
443+
```javascript
444+
{
445+
autoDiscover: {
446+
loadOrder: 'dependency', // Automatic topological sort
447+
failOnError: false // Graceful degradation
448+
}
449+
}
450+
```
451+
452+
### Production Configuration
453+
454+
Optimized settings for production environments:
455+
456+
```javascript
457+
{
458+
autoDiscover: {
459+
enabled: true,
460+
paths: ['./dist/modules'],
461+
patterns: ['**/*.module.js'],
462+
loadingStrategy: 'eager',
463+
watchForChanges: false,
464+
loadOrder: 'dependency',
465+
failOnError: true,
466+
maxDepth: 3
467+
}
468+
}
469+
```
291470

292471
## Logging Configuration
293472

0 commit comments

Comments
 (0)