Musing About Web App Structure
Tue Dec 16 18:25:35 EST 2014
I've been giving a lot of thought lately to how I feel about different structures for web apps. Specifically, in this case, the "structure" I'm thinking about is the "client-server" balance in the app itself and the associated method of data access.
The impetus has been my minor fiddling with Angular over the past half a year or so. If you're not familiar with it, Angular is a client-side JavaScript framework focused on building full-fledged apps that run in the browser. The way it (and frameworks like it) distinguish themselves from more server-heavy methods of development is that the primary logic of running the UI happens in client-side code - resources and data are fetched from the server (including HTML snippets), but little or no presentation logic takes place there. You should go read Marky Roden's posts on the topic and then attend his session at ConnectED.
For a while, I thought of this as an interesting idea, but mostly just another method of writing apps, like PHP vs. Ruby vs. XPages. However, the idea kept churning away in the back of my brain, offering itself up as the right answer as I started writing the REST APIs in my Framework (I swear I'll get to that final post in the series eventually) and thought more about mobile development. The thing that's really latched onto my psyche isn't that Angular or JavaScript are particularly compelling, but the idea of writing a decoupled app is. Writing an app in Angular isn't really like writing an app in XPages or PHP - instead, it's (at a very high level) like writing a native mobile or desktop application. You split your app into two main tiers: the model/data/connection tier on the server and the app tier on the client.
That is something that is starting to seem really right to me. Even if it did nothing else, having an architecture like that forces you to think in terms of "services" instead of just data access - once you've written a model layer that provides REST services with access and validation rules enforced, then you have a single interface that can be used by browser-based Angular apps, mobile and desktop apps, and remote applications and services you didn't write. There's also no reason you couldn't write a server-side app that consumes those services, continuing to build XPages apps that don't use the normal data sources. This is sort of what my framework has evolved towards, just with a first-among-equals twist where the XPage app gets direct Java access to the same objects REST serves up.
Once you have this sort of setup, the answers to what your data-access and client UI frameworks should be both become "whatever". Want to write your REST API in Node and consume it in XPages? Sure, go ahead. Decide later that you'd rather have the data served up by Rails? Can do - the XPages side wouldn't need a change if the API is the same. Similarly, if you want to swap out XPages for Angular served up as static files or, god forbid, a PHP app, the way is smoothed.
Even though it starts as a small thing - switching from accessing data "directly" on the server to always thinking about that REST-API abstraction - this really seems compelling to me. Not so compelling that I've actually written any non-test apps this way yet, but I've opened the door for myself with my framework.
Nathan T. Freeman - Tue Dec 16 20:07:00 EST 2014
Jesse, you are exactly correct. This is where the market is heading full-tilt, and when we recently refactored a part of our tools to use backbone.js with custom REST services, it completely changed the experience and vastly accelerated our feature rate.
Stephan H. Wissel - Tue Dec 16 23:14:51 EST 2014
The whole shabang is called "Contract first programming" and is the web version of SOA (kind of). So you are on the right track. What would be interesting: have some Domino component render the HTML snippets you use in those applications, so you could automate more of it.
Nathan T. Freeman - Wed Dec 17 23:15:45 EST 2014
So an Angular or Backbone HTML template renderkit for XPages, Stephan? Maybe that also generates javascript components for you that couple with those templates? Brilliant.
And, of course, Jesse is an expert in writing custom renderers :)
Sven Hasselbach - Thu Dec 18 05:00:40 EST 2014
Here you can find some inspiration: https://github.com/stephanrauh/AngularFaces