coldbox hierarchical mvc for coldfusion/cfml

40
Hierarchical MVC Transform your Monolith

Upload: ortus-solutions-corp

Post on 23-Jan-2018

569 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: ColdBox Hierarchical MVC for ColdFusion/CFML

Hierarchical MVC

Transform your Monolith

Page 2: ColdBox Hierarchical MVC for ColdFusion/CFML

WHO AM I?

• Luis Majano - Computer Engineer

• Imported from El Salvador

• Houston, Texas

• CEO of Ortus Solutions

• Creator of many boxes

www.ortussolutions.com@ortussolutions

@lmajano

Page 3: ColdBox Hierarchical MVC for ColdFusion/CFML

AGENDA

• The Legacy Problem• Monolithic Applications• HMVC Architecture• ColdBox Modules• API Demo

Page 4: ColdBox Hierarchical MVC for ColdFusion/CFML

“Software is always bound to change”

Page 5: ColdBox Hierarchical MVC for ColdFusion/CFML

THE LEGACY PROBLEM

Page 6: ColdBox Hierarchical MVC for ColdFusion/CFML

LEGACY PROBLEM

• Gives CFML a bad name

• Security Issues

• Performance Issues

• Employee Issues

• Development Issues

• Finding Developer Issues

Page 7: ColdBox Hierarchical MVC for ColdFusion/CFML

LEGACY PROBLEM

•>35% No MVC•>60% No DI•>55% No Testing

FuseBox is NOT MVC

Page 8: ColdBox Hierarchical MVC for ColdFusion/CFML

LIKE MY CFML APP?

• MVC Framework or spaghetti hell?

• OO or cfinclude hell?

• Automated Tests? Continuous Integration?

• Agile/Scrum Methodologies?

• Source Control? (Zip files don’t count!)

• Continuous Delivery? Container Strategy?

• Developer Automation?

Page 9: ColdBox Hierarchical MVC for ColdFusion/CFML

Monolithic Apps

Page 10: ColdBox Hierarchical MVC for ColdFusion/CFML

HOW DO WE MODERNIZE CFML?

Page 11: ColdBox Hierarchical MVC for ColdFusion/CFML

BACK TO THE SCHOOL OF ARCHITECTURE

Page 12: ColdBox Hierarchical MVC for ColdFusion/CFML

1. COHESION - COUPLING

Page 13: ColdBox Hierarchical MVC for ColdFusion/CFML

2. MVC

• Separates layers of concerns• Helps enforce OO• Specialized team members• but

• Layers are still tightly coupled• MVC Monoliths

Page 14: ColdBox Hierarchical MVC for ColdFusion/CFML

3. N-TIER - MEXICAN CHALUPA

• Add more layers for organization• Layers are still tightly coupled• Still monolithic!

Page 15: ColdBox Hierarchical MVC for ColdFusion/CFML

4. HMVC

Page 16: ColdBox Hierarchical MVC for ColdFusion/CFML

4. HMVC

• Evolution of MVC• No more lasagna

• Independent MVC Triads• Benefits

• Higher Cohesion• Lower Coupling• Modularization• Better Organization• Reusability• Extensibility• Testability

Page 17: ColdBox Hierarchical MVC for ColdFusion/CFML

5. MICROSERVICES

AN APPROACH TO DEVELOPING A SINGLE APPLICATION AS A SUITE OF SMALL SERVICES, EACH RUNNING IN ITS OWN PROCESS AND COMMUNICATING WITH LIGHTWEIGHT MECHANISMS.

Martin Fowler

Page 18: ColdBox Hierarchical MVC for ColdFusion/CFML

5. MICROSERVICES

M CV

M CV

M CV

Page 19: ColdBox Hierarchical MVC for ColdFusion/CFML

• Legacy code updates less intimidating• Fault tolerance• Versionable & Maintainable• Short release cycles• Monoliths Evolution

5. MICROSERVICES

Identify

BreakOutScale

Page 20: ColdBox Hierarchical MVC for ColdFusion/CFML

COMMANDBOX-DOCKER

Run any CFML Engine

Run any WAR

Portable Server Settings

Portable CFML Engine Settings

Image Healthchecks

Secure Headless Modes

Page 21: ColdBox Hierarchical MVC for ColdFusion/CFML

HMVC Microservices+

FORMULA FOR SUCCESS

Page 22: ColdBox Hierarchical MVC for ColdFusion/CFML

A FUNDAMENTAL CHANGE IN APPROACH OR UNDERLYING ASSUMPTIONS.

PARADIGM SHIFT:

MODERNIZE…

Page 23: ColdBox Hierarchical MVC for ColdFusion/CFML

Monolithic)App)

App#Security#

Billing#

Blog#

Cart#

User#Admin#

EVOLVE TO HMVC MODULARITY

“As a system evolves, It’s complexity will increase unless work is done to maintain or reduce it.”

Lehman’s 2nd Law of software evolution

Page 24: ColdBox Hierarchical MVC for ColdFusion/CFML

WHAT IS A MODULE?

"In structured design and data-driven design, a module is a generic term used to describe a named and addressable

group of program statements” by Craig Borysowich (Chief Technology Tactician)

“A software module is a deployable, manageable, natively reusable, composable, unit of software that provides a

concise interface to consumers.” by Kirk Knoernschild

Page 25: ColdBox Hierarchical MVC for ColdFusion/CFML

COLDBOX MODULES = SUPER POWERS

• Mini MVC applications• Addressable• Composed• Dependencies• Runtime Installed• Reloaded• Unloaded

Page 26: ColdBox Hierarchical MVC for ColdFusion/CFML

COLDBOX MODULES ARE OLDAvailable since v3.0.0 (2011)

Page 27: ColdBox Hierarchical MVC for ColdFusion/CFML

COLDBOX MODULE TRIADS

Host%Application%Security%

News%

RSS%

eStore%

Admin%

Users% Comments% Posts% Billing%

Page 28: ColdBox Hierarchical MVC for ColdFusion/CFML

WHAT DO YOU GET?

• MVC Conventions• Automatic Model Mappings (DI)• Automatic CFML Mappings• Automatic URL Routing• Automatic Interceptors• Overridable Settings• Environment Detection• Module Dependencies

Page 29: ColdBox Hierarchical MVC for ColdFusion/CFML

ColdBox MVC Application

handlers

layouts

models

modules

views

box.json

modules_app

Tracked by CommandBox

Custom

Page 30: ColdBox Hierarchical MVC for ColdFusion/CFML

Anatomy of a Module

ModuleConfig.cfc

handlers

layouts

models

modules

modules_app

Module Name(unique on disk)

box.json

views

Page 31: ColdBox Hierarchical MVC for ColdFusion/CFML

{ "name":"cbSwagger-shell", "version":"1.1.0", "slug":"cbSwagger-shell", "private":false, "dependencies":{ "coldbox":"^4.3.0", “workbench":"git+https://github.com/ortus/unified-workbench.git", "cbjavaloader":">1.0.0", "swagger-sdk":">0.0.9" }, "devDependencies":{ "testbox":"^2.4.0" }, "installPaths":{ "coldbox":"coldbox/", "testbox":"testbox/", "cbjavaloader":"modules/cbjavaloader/", "swagger-sdk":"modules/swagger-sdk/", "workbench":"workbench" }, "testbox":{ "runner":"http://localhost:49616" }, "scripts":{ "postVersion":"recipe workbench/bump.boxr" } }

box.json

Page 32: ColdBox Hierarchical MVC for ColdFusion/CFML

MODULECONFIG.CFC

• Simple CFC• Bootstraps your module• Must exist in the root of your module folder• Has public properties• Callback methods

• Tier-detection enabled• It’s an interceptor too!

Page 33: ColdBox Hierarchical MVC for ColdFusion/CFML

MODULECONFIG.CFC PROPERTIES

// Module Properties     this.title              = "cbswagger";     this.author             = "Jon Clausen <[email protected]>";     this.webURL             = "https://github.com/coldbox-modules/cbSwagger";     this.description        = "Swagger API documentation from your routes";     this.version            = "@build.version@[email protected]@";     // If true, looks for views in the parent first, if not found, then in the module. Else vice-versa     this.viewParentLookup   = true;     // If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa     this.layoutParentLookup = true;     // Module Entry Point     this.entryPoint         = "cbswagger";     // Model Namespace     this.modelNamespace     = "cbswagger";     // CF Mapping     this.cfmapping          = "cbswagger";     // Module Dependencies That Must Be Loaded First, use internal names or aliases     this.dependencies       = [ "swagger-sdk" ];

Page 34: ColdBox Hierarchical MVC for ColdFusion/CFML

MODULECONFIG.CFC METHODS

Page 35: ColdBox Hierarchical MVC for ColdFusion/CFML

MO

DU

LECON

FIG.CFC C

ON

FIGU

RE

function configure(){         settings = {             caching = false,             mailTo = "[email protected]"         };

        layoutSettings = { defaultLayout = "relax.cfm" };

        i18n = {             resourceBundles = {                 "cbcore" = "#moduleMapping#/i18n/cbcore"             },             defaultLocale = "en_US",             localeStorage = "cookie"         };

        interceptorSettings = {             // ContentBox Custom Events             customInterceptionPoints = arrayToList( [                 // Code Rendering                 "cb_onContentRendering", "cb_onContentStoreRendering"             ] )         };         routes = [             //Module Root Requests             { pattern=“/", handler="Main", action="index" },             // Convention Route             { pattern=":handler/:action?" }         ];     }

Page 36: ColdBox Hierarchical MVC for ColdFusion/CFML

Bonus:ModuleConfig is also an interceptorbox install cors

Page 37: ColdBox Hierarchical MVC for ColdFusion/CFML

LEVERAGING WIREBOX

• Automatically maps all your models to• {modelName}@{moduleName}

• property name=“builder” inject=“builder@qb”;

Page 38: ColdBox Hierarchical MVC for ColdFusion/CFML

MODULAR EXECUTION

#runEvent( ‘module:users.dashboard' )#

Page 39: ColdBox Hierarchical MVC for ColdFusion/CFML

Demo Time!

modules

v1 v2 vx

modules_app

API

handlers models

Page 40: ColdBox Hierarchical MVC for ColdFusion/CFML

QUESTIONS?Go Modularize!

www.ortussolutions.com @ortussolutions