List of things we need to improve in this example to make it a basis for loopback-workspace 3.0.
1. Multiple datasources
The current design of api/app.api.js seems to supports a single db datasource. This is a step back from what we already have in loopback-workspace, where datasources.json can define multiple different datasources.
Here is a list of datasources used by a fully-featured application:
db for the main database
push for push notifications
email for sending e-mails
rest or soap for getting data from legacy systems
storage for managing images via loopback-storage-service
On the client side, most models will be attached to the same Remoting datasource. The most notable exception is synchronization, it requires several datasources (local storage, remoting).
(SLA-1023)
2. Dynamic configuration of datasources
The current design makes it easy to change the db configuration depending on environment variables. While this is useful for demo purposes, our current direction regarding deployment & operations favours different approach - see the gist.
Configuration should not be present in a node application archive. The more configuration is bound in, the less choice there will be over deployment environment. Even deploying the same app to staging and then production could become impossible.
We need to keep in mind the use case of loopback-workspace, which should be able to load a list of available datasource without the need to build the project and load it to a Node.js process via require('app.js').
(SLA-1023)
3. Reduce boilerplate, auto-load components
The current version contains too much of boilerplate code and makes it impossible to add new features/models/datasources via loopback-workspace.
Here are few generators that cannot be implemented now:
- add a new model
- add a new datasource
- enable explorer (swagger)
- enable authentication
What is needed:
a. Extract most of api/app.api.js to loopback core. Ideally the existing method app.boot can be modified or extended to support the new layout.
b. Figure out how to simplify html5/app.html5.js. The code to require() all models should be generated by gulpfile, same applies to the code calling require() for all angular controller files.
c. (SLA-938) Refactor most of gulpfile into a module gulp-loopback, so that the application gulpfile contains only calls to gulp-loopback and application-specific options.
d. There should be a convention for adding new things by adding a new file, without modifying any existing code. All components (api, html5, web) should support these conventions, either directly in code (think of app.boot) or via a custom build step. (See also b.)
4. Automated tests
The pull request #1 touched the subject lightly, but no solution was implemented.
I would like to see at least these three categories of tests covered by the example project:
a. (SLA-841) Integration tests for the models and the api server, the tests are permitted to use the database (probably the real one, possibly an in-memory replacement). These tests should run on Node.js.
b. (SLA-1019) Unit-tests for the html5 client which do not communice with the backend. These tests should run in a browser via Karma.
c. (SLA-1020) End-to-end tests - html5 client, api server, models, datasources. There are two flavours: in the first one, developers write unit-test-like code, but the communication with backend is not mocked out. The second flavour tests the application via selenium or a similar framework (e.g. angular's protractor). Both flavours require to start the server before running the tests in the browser.
5. Mix and match components
To keep the loopback-workspace code simple, we should come up with a single structure flexible enough to support different kinds of projects:
- full-stack server + client as presented here:
api, models, html5, web.
- a pure API server:
api, models
- a website with REST API:
api, models, web
- (optional) a website without REST API:
models, web
The current design is pretty close, but not there yet.
List of things we need to improve in this example to make it a basis for loopback-workspace 3.0.
api/app.api.jsto loopback core.html5/app.html5.js1. Multiple datasources
The current design of
api/app.api.jsseems to supports a singledbdatasource. This is a step back from what we already have in loopback-workspace, wheredatasources.jsoncan define multiple different datasources.Here is a list of datasources used by a fully-featured application:
dbfor the main databasepushfor push notificationsemailfor sending e-mailsrestorsoapfor getting data from legacy systemsstoragefor managing images via loopback-storage-serviceOn the client side, most models will be attached to the same Remoting datasource. The most notable exception is synchronization, it requires several datasources (local storage, remoting).
(SLA-1023)
2. Dynamic configuration of datasources
The current design makes it easy to change the
dbconfiguration depending on environment variables. While this is useful for demo purposes, our current direction regarding deployment & operations favours different approach - see the gist.We need to keep in mind the use case of
loopback-workspace, which should be able to load a list of available datasource without the need to build the project and load it to a Node.js process viarequire('app.js').(SLA-1023)
3. Reduce boilerplate, auto-load components
The current version contains too much of boilerplate code and makes it impossible to add new features/models/datasources via loopback-workspace.
Here are few generators that cannot be implemented now:
What is needed:
a. Extract most of
api/app.api.jsto loopback core. Ideally the existing methodapp.bootcan be modified or extended to support the new layout.b. Figure out how to simplify
html5/app.html5.js. The code torequire()all models should be generated by gulpfile, same applies to the code callingrequire()for all angular controller files.c. (SLA-938) Refactor most of gulpfile into a module
gulp-loopback, so that the application gulpfile contains only calls togulp-loopbackand application-specific options.d. There should be a convention for adding new things by adding a new file, without modifying any existing code. All components (api, html5, web) should support these conventions, either directly in code (think of
app.boot) or via a custom build step. (See also b.)4. Automated tests
The pull request #1 touched the subject lightly, but no solution was implemented.
I would like to see at least these three categories of tests covered by the example project:
a. (SLA-841) Integration tests for the models and the api server, the tests are permitted to use the database (probably the real one, possibly an in-memory replacement). These tests should run on Node.js.
b. (SLA-1019) Unit-tests for the html5 client which do not communice with the backend. These tests should run in a browser via Karma.
c. (SLA-1020) End-to-end tests - html5 client, api server, models, datasources. There are two flavours: in the first one, developers write unit-test-like code, but the communication with backend is not mocked out. The second flavour tests the application via selenium or a similar framework (e.g. angular's protractor). Both flavours require to start the server before running the tests in the browser.
5. Mix and match components
To keep the loopback-workspace code simple, we should come up with a single structure flexible enough to support different kinds of projects:
api,models,html5,web.api,modelsapi,models,webmodels,webThe current design is pretty close, but not there yet.