|
| 1 | +# ColdBox Framework Development Guide |
| 2 | + |
| 3 | +## Architecture Overview |
| 4 | + |
| 5 | +ColdBox is an HMVC (Hierarchical Model-View-Controller) framework designed for two languages: BoxLang (which the ColdBox team owns and directs) and CFML. ColdBox provides four main subsystems: |
| 6 | + |
| 7 | +- **ColdBox MVC**: Core framework in `/system/web/` - handles routing, events, interceptions, and request lifecycle |
| 8 | +- **WireBox DI**: Dependency injection container in `/system/ioc/` - manages object creation, injection and aop |
| 9 | +- **CacheBox**: Caching framework in `/system/cache/` - provides multi-provider caching abstraction and it's own caching engine |
| 10 | +- **LogBox**: Logging framework in `/system/logging/` - structured logging with multiple appenders |
| 11 | + |
| 12 | +## JavaScript Coding Standards |
| 13 | + |
| 14 | +### Spacing and Formatting |
| 15 | +- **Always add spaces inside parentheses**: Use `if ( condition )` not `if (condition)` |
| 16 | +- **Function parameters**: Use `functionName( param1, param2 )` with spaces |
| 17 | +- **Array/Object access**: Use `array[ index ]` and `object[ key ]` with spaces |
| 18 | +- **Method calls**: Use `obj.method( param )` with spaces in parentheses |
| 19 | +- **Template literals**: Use spaces in template expressions `${ variable }` |
| 20 | +- **Arrow functions**: Use `array.filter( item => condition )` with spaces |
| 21 | +- **Operators**: Always space around operators `a === b`, `x + y`, `result = value` |
| 22 | + |
| 23 | +### Structure and Organization |
| 24 | +- Use consistent indentation (tabs preferred to match CFML style) |
| 25 | +- Group related methods together |
| 26 | +- Add proper JSDoc comments for all functions |
| 27 | +- Use descriptive variable names |
| 28 | +- Separate logical sections with blank lines for readability |
| 29 | + |
| 30 | +### Examples |
| 31 | +```javascript |
| 32 | +// Good - ColdBox JavaScript Style |
| 33 | +if ( condition && anotherCondition ) { |
| 34 | + const result = someFunction( param1, param2 ); |
| 35 | + array.forEach( item => { |
| 36 | + processItem( item ); |
| 37 | + } ); |
| 38 | +} |
| 39 | + |
| 40 | +// Bad - Inconsistent spacing |
| 41 | +if (condition&&anotherCondition) { |
| 42 | + const result = someFunction(param1,param2); |
| 43 | + array.forEach(item => { |
| 44 | + processItem(item); |
| 45 | + }); |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## Key Components |
| 50 | + |
| 51 | +- **Bootstrap.cfc**: Framework initialization and application lifecycle management |
| 52 | +- **Controller.cfc**: Central dispatcher that processes events and manages services |
| 53 | +- **Settings.cfc**: Default configuration values and conventions (handlers, views, layouts, models) |
| 54 | +- **EventHandler.cfc/RestHandler.cfc**: Base classes for request handlers with dependency injection |
| 55 | +- **RequestContext**: Event object containing RC/PRC scopes, routing info, and rendering methods |
| 56 | +- **WireBox.cfc**: Dependency injection container for managing service creation and injection |
| 57 | +- **CacheBox.cfc**: Caching container for managing cache providers and entries |
| 58 | +- **LogBox.cfc**: Logging container for managing loggers, appenders, and log entries |
| 59 | +- **BugReport.cfm**: Error reporting template showing framework state, routing info, and scopes |
| 60 | +- **ModuleConfig.cfc**: Module configuration for routes, models, and interceptors |
| 61 | + |
| 62 | +## Key Web Application Services |
| 63 | + |
| 64 | +The ColdBox framework includes several core services in `/system/web/services/` that manage different aspects of the application lifecycle: |
| 65 | + |
| 66 | +- **BaseService.cfc**: Base helper class providing common functionality for all ColdBox services |
| 67 | +- **HandlerService.cfc**: Manages event handling, handler caching, event caching, and handler execution lifecycle |
| 68 | +- **InterceptorService.cfc**: Manages interception points, interceptor registration, and announcement of framework events |
| 69 | +- **LoaderService.cfc**: Responsible for loading and configuring a ColdBox application with all its services during startup |
| 70 | +- **ModuleService.cfc**: Oversees HMVC module management including registration, activation, and CF mapping management |
| 71 | +- **RequestService.cfc**: Handles request context preparation, FORM/URL processing, and flash scope management |
| 72 | +- **RoutingService.cfc**: Manages URL routing, route registration, and request-to-handler mapping via the Router component |
| 73 | +- **SchedulerService.cfc**: Manages application schedulers in an HMVC fashion for background task execution |
| 74 | + |
| 75 | +## Development Workflows |
| 76 | + |
| 77 | +### Testing |
| 78 | + |
| 79 | +```bash |
| 80 | +# Run specific test suites |
| 81 | +box run-script tests:integration |
| 82 | +box run-script tests:cachebox |
| 83 | +box run-script tests:wirebox |
| 84 | +box run-script tests:logbox |
| 85 | + |
| 86 | +# Start test servers for different engines |
| 87 | +box run-script start:boxlang # BoxLang engine (preferred) |
| 88 | +box run-script start:lucee # Lucee CFML engine |
| 89 | +box run-script start:2023 # Adobe ColdFusion 2023 |
| 90 | +``` |
| 91 | + |
| 92 | +### Building & Formatting |
| 93 | + |
| 94 | +```bash |
| 95 | +box run-script build # Build without docs |
| 96 | +box run-script format # Format all CFC files |
| 97 | +box run-script format:check # Check formatting compliance |
| 98 | +``` |
| 99 | + |
| 100 | +## Framework Conventions |
| 101 | + |
| 102 | +- **Handlers**: `/handlers/` - event handlers (controllers) with `index()` as default action |
| 103 | +- **Models**: `/models/` - business logic with automatic DI registration when `autoMapModels=true` |
| 104 | +- **Views**: `/views/` - organized by handler name, rendered with `event.setView()` |
| 105 | +- **Layouts**: `/layouts/` - page templates with `renderView()` placeholder |
| 106 | +- **Modules**: `/modules/` - self-contained HMVC sub-applications with `ModuleConfig.cfc` |
| 107 | + |
| 108 | +## Dependency Injection Patterns |
| 109 | + |
| 110 | +WireBox uses several injection approaches: |
| 111 | +- **Property injection**: `property name="myService" inject="MyService";` |
| 112 | +- **Constructor injection**: Arguments automatically resolved by type/name |
| 113 | +- **Setter injection**: `setMyService()` methods called automatically |
| 114 | +- **Provider pattern**: `inject="provider:MyService"` for lazy loading |
| 115 | + |
| 116 | +## Testing Patterns |
| 117 | + |
| 118 | +Tests extend `BaseModelTest` or `BaseIntegrationTest`: |
| 119 | +```cfml |
| 120 | +component extends="coldbox.system.testing.BaseModelTest" { |
| 121 | + function run(testResults, testBox) { |
| 122 | + describe("My Service", function() { |
| 123 | + beforeEach(function() { |
| 124 | + mockService = createMock("app.models.MyService"); |
| 125 | + }); |
| 126 | +
|
| 127 | + it("can do something", function() { |
| 128 | + expect(mockService.doSomething()).toBe("expected"); |
| 129 | + }); |
| 130 | + }); |
| 131 | + } |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +## Error Handling & Debugging |
| 136 | + |
| 137 | +- **BugReport.cfm**: Comprehensive error template showing framework state, routing info, scopes |
| 138 | +- **Exception handling**: Uses `exceptionHandler` setting pointing to handler.action |
| 139 | +- **Reinit**: Use `?fwreinit=1` to reload framework or specific password via `reinitPassword` setting |
| 140 | +- **Debug mode**: Set `debugMode=true` in configuration for enhanced error reporting |
| 141 | + |
| 142 | +## Module Development |
| 143 | + |
| 144 | +Modules are self-contained with: |
| 145 | +- **ModuleConfig.cfc**: Configuration, routes, model mappings, interceptors |
| 146 | +- **handlers/models/views**: Standard MVC structure |
| 147 | +- **settings**: Module-specific configuration accessible via `getModuleSettings()` |
| 148 | +- **dependencies**: Other modules this module depends on |
| 149 | + |
| 150 | +## Multi-Language & Engine Support |
| 151 | + |
| 152 | +### Language Support |
| 153 | + |
| 154 | +ColdBox is designed for two programming languages: |
| 155 | + |
| 156 | +**BoxLang** (Owned and directed by the ColdBox team): |
| 157 | +- `.bx` - Components (classes, services, handlers) |
| 158 | +- `.bxm` - Templates (views, layouts, includes) |
| 159 | +- `.bxs` - Script files |
| 160 | +- Strategic future language with enhanced features and performance |
| 161 | +- Modern JVM language with superior type safety and performance |
| 162 | + |
| 163 | +**CFML** (ColdFusion Markup Language): |
| 164 | +- `.cfc` - Components (classes, services, handlers) |
| 165 | +- `.cfm` - Templates (views, layouts, includes) |
| 166 | +- Legacy language support maintained for existing applications |
| 167 | + |
| 168 | +BoxLang is the recommended language for new projects due to its modern design, enhanced performance, and direct support from the ColdBox team. |
| 169 | + |
| 170 | +### Engine Compatibility |
| 171 | + |
| 172 | +Framework supports BoxLang, Lucee 5+, and Adobe ColdFusion 2023+. Use engine-specific server configs: |
| 173 | +- `server-boxlang@1.json` - BoxLang development (port 8599, debug enabled) |
| 174 | +- `server-boxlang-cfml@1.json` - BoxLang with CFML compatibility |
| 175 | +- `server-lucee@5.json` - Lucee CFML engine |
| 176 | +- `server-adobe@2023.json` - Adobe ColdFusion |
| 177 | + |
| 178 | +Key consideration: BoxLang requires `enableNullSupport` in Application.cfc/bx for full null handling. |
0 commit comments