Skip to content

An example app built with JHipster, Angular 4, Redux, Webpack, and Angular-CLI

License

Notifications You must be signed in to change notification settings

btcioner/great-big-example-application

This branch is 337 commits behind dancancro/great-big-example-application:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

acf1620 · May 16, 2017
May 8, 2017
May 8, 2017
May 15, 2017
May 16, 2017
May 8, 2017
May 8, 2017
May 8, 2017
May 8, 2017
May 9, 2017
May 12, 2017
May 8, 2017
May 8, 2017
May 8, 2017
May 16, 2017
May 8, 2017
May 8, 2017
May 14, 2017
May 12, 2017
May 8, 2017
May 8, 2017
May 8, 2017
May 8, 2017
May 16, 2017
May 13, 2017

Repository files navigation

Build Status

Background and Motivation

The main goal of this project is to make available to unemployed developers source code for a state-of-the-art web application the likes of which only exist as intellectual property visible exclusively to employed experts who have signed non-disclosure agreements and can't let you see it or learn how they made everything work together.

You should not have to get hired before learning how to do a thing the right way

The other goal is to assemble enough functionality into one free example application that people think twice before starting another one-feature, no edge-case, example and exacerbating the already overwhelming starting point option overload. Hopefully this will persuade a few people to direct that energy instead into improving what already exists. To this end I have made, over the course of the past 4 years, the world's biggest, most detailed database of web technology selling points so things could be compared easily in broad daylight without the hype and selective disclosure of a typical product/project sales page. See below for a sample slice of it.

But why one great big app?

"There are already lots of little example apps!!" (written in all different styles) "Software development is always taught using lots of inconsistent simple examples!!" "Approaches are a matter of personal preference and shouldn't be imposed" (on beginners who don't have strong opinions yet)

"Bloated!!"

There's a strange resistance to using big examples to educate instead of small ones, but no complaints about using cars to teach automechanics instead of go-karts. There are lots of reasons to do this. Here are some I thought of:

1. Real code answers every question, not just what the authors of tutorials choose to answer through
their choices of simplifications.

2. To make something new as an expert would do it, it's much easier to copy and modify a thing
made by experts, no matter how complex, than to synthesize the missing details removed for the 
sake of simplicity, out of nothing, no matter how simple. To do the latter requires full 
comprehension of a menagerie of inconsistent resources with inconsistent contexts. To do the 
former takes a few searches, a few replacements and a little bug fixing.

3. If you want a job making commercial-grade code, you should study commercial-grade code,
not tutorial-grade code. Anything you learn in a tutorial must be handled with caution 
because corners have probably been cut (e.g. the entire back-end), and it probably doesn't 
show you the exact way anyone does it on a real job. The difference between exact and almost 
exact is the difference between ten stones balanced on top of each other and those stones lying on
the ground. You keep your job and the company makes money only if *everything* works.

4. Tutorials show you how you *can* use a feature of the technology but often they 
do so in situations when in real life you would not do things that way. This can cost a lot of 
time. It's just as important to know when to use a technology's features as it is to know how.

5. If you want to know how fast an app using a particular technology will build, run and test 
before investing the time to learn it - and you should - then you need source code for a big 
app before you even write Hello World.

6. If you want to know the complexity limits a technology will place on your app before you
commit to using it, there's no better way than to see a complex example made with that technology.

7. It's a whole lot easier to vet an idea or accept an approach others have taken when you have
a complete application with all of its edge cases to show you what needs to be accommodated. 
By containing many edge cases, a big application will quickly answer the common learner's question:
"Why isn't this done the easy way I think it should be done?", or "What if we tried X instead?"
Without access to lots of edge cases in the beginning, you can go down the wrong road for a long time.

I've had a peculiarly difficult time making the case to software development educators to provide a single, giant example app for their students akin to what they work on every day for their clients and employers. So here's this attempt at one from unemployed me. No NDA needed to see it.

How did this great big app happen?

This application has been constructed by combining small open source demos into one big application. It's basically a structure that would have been had all the tutorial experts worked together instead of separately. Coming from different demos, the features of the app are not related to each other and it won't make any sense to have them together but the point is just to demonstrate how things should work technically, so that's okay. I took these projects and integrated/restructured/restyled their code according to the following prioritization. Disagreements in approach between two influences are resolved by the lower authority yielding to the higher one:

  1. Angular Style Guide by Google (see change log for updates)
  2. Tour of Heroes (ngModules, Routing, App Specs, HTTP, Server Communication versions) by Google
  3. Angular CLI by Google and the community
  4. Redux Docs Redux.org
  5. JHipster Example - Bank accounts by @jdubois
  6. JHipster Example - Blog by @mraible
  7. scalable-architecture-demo - P2P Typing Game by @mgechev
  8. ngrx example app - book collection by @MikeRyan52
  9. angular-seed-advanced by @mgechev + @NathanWalker + community
  10. FAMN example by @implustech
  11. ng2-state-talk - drag/editable notes by @JavascriptMick
  12. feathers-starter-react-redux-login-roles - Feathers back end with auth by @eddyystop
  13. rangle-starter Angular 2 with TypeScript and Redux version - counter by @SethDavenport

In addition to the features from these demos, I added one of my own. I replaced

  1. this other project which was made with JQuery and Google Scripts. The data is contained in this Google Sheet and served as JSON by a Google script.

A huge thanks to those who created the example demos from which I put together this amalgam.

Home Screen

Image

Bernie Rebuttals

Image

Book Collection

Image

Counter

Image

Entities

Image

Typing Speed Game

Image

Tour of Heroes Dashboard

Image

Tour of Heroes List

Image

Drag, Drop and Edit Notes

Image

To Do List

Image

My Innovations

While the goal of the project is to combine the wisdom of different experts, nobody can resist introducing improvements when there's no obvious case against doing so. So you will see a couple of practices in this project that came from my head rather than the sources of expertise from which the project was assembled. If you can think of reasons not to do these things, please let me know.

  1. I put the Redux store reducers in app/core/store separate from the feature directories located under app and did not make folders for reducers, actions, and effects. There is a many-to-many relationship between Redux store slices and features. So putting the Redux code for a given slice into the same directory as one of the features that uses it doesn't make sense. How do you decide which feature gets it?

  2. As much as practical the names of files in a directory begin with the directory name. I did this to prevent directories from having a mixture of unrelated concerns. If a directory in a source demo had files for two different things, I created more directories. I thought about removing that part of the file name, src/app/app.page.ts -> src/app/page.ts, for the sake of DRY, but that makes it too confusing when you are working on multiple files with the same names and different directories.

  3. I noticed a lot of duplication and boilerplate of identical CRUD code for each of my types of entities. So I made utility functions and the related actions and models for each of three types of store slice - entities, id lists, and slices (everything else).

  4. I came up with a mini lexicon of file types to keep file names shorter and more expressive. A "page" is understood to be a smart @Component class that fills the page and might have a router-outlet and route configurations. A "guard" is understood to be an @Injectable "service" class that returns a boolean. A "routing" is a @NgModule class that contains route configurations. So I memorize this simple lexicon, and drop the redundant, less-clear words from the names. For example, I use the name app.page.ts rather than app.component.ts or app-page.component.ts. I use auth.guard.ts instead of auth-guard.service.ts. I use books.routing.ts instead of books-routing.module.ts.

A is a class decorated with that Example file name Example class name
page @Component more or less fills the screen - a "smart" component that gets data from something other than @Inputs and dispatches actions to change state app.page.ts AppPage
component @Component has to be contained by a page or other components - a "dumb" component that only gets data from @Inputs login.component.ts LoginComponent
guard @Injectable returns a boolean and does whatever an Angular guard does auth.guard.ts AuthGuard
service @Injectable provides a service or data auth.service.ts AuthService
routing @NgModule contains route configurations books.routing.ts BooksRouting
module @NgModule associates related components and providers books.module.ts BooksModule

That's it. It shouldn't be too hard to remember these, and in return you will have consistent, short, expressive file names.

Development

Before you can build this project, you must install and configure the following dependencies on your machine:

  1. Node.js: We use Node to run a development web server and build the project. Depending on your system, you can install Node either from source or as a pre-packaged bundle. Be sure to use an LTS version of node nvm is handy for managing different versions of node.
  2. Yarn: We use Yarn to manage Node dependencies. Depending on your system, you can install Yarn either from source or as a pre-packaged bundle.

After installing Node, you should be able to run the following command to install development tools. You will only need to run this command when dependencies change in package.json.

yarn install

We use yarn scripts and Webpack as our build system.

Run the following commands in two separate terminals to create a blissful development experience where your browser auto-refreshes when files change on your hard drive.

./mvnw
yarn start

Yarn is also used to manage CSS and JavaScript dependencies used in this application. You can upgrade dependencies by specifying a newer version in package.json. You can also run yarn update and yarn install to manage dependencies. Add the help flag on any command to see how you can use it. For example, yarn help update.

The yarn run command will list all of the scripts available to run for this project.

Managing dependencies

For example, to add Leaflet library as a runtime dependency of your application, you would run following command:

yarn add --exact leaflet

To benefit from TypeScript type definitions from DefinitelyTyped repository in development, you would run following command:

yarn add --dev --exact @types/leaflet

Then you would import the JS and CSS files specified in library's installation instructions so that Webpack knows about them:

Edit src/main/webapp/app/vendor.ts file:

import 'leaflet/dist/leaflet.js';

Edit src/main/webapp/content/css/vendor.css file:

@import '~leaflet/dist/leaflet.css';

Note: there are still few other things remaining to do for Leaflet that we won't detail here.

For further instructions on how to develop with JHipster, have a look at Using JHipster in development.

Using angular-cli

You can also use Angular CLI to generate some custom client code.

For example, the following command:

ng generate component my-component

will generate few files:

create src/main/webapp/app/my-component/my-component.component.html
create src/main/webapp/app/my-component/my-component.component.ts
update src/main/webapp/app/app.module.ts

Building for production

To optimize the GreatBigExampleApplication application for production, run:

./mvnw -Pprod clean package

This will concatenate and minify the client CSS and JavaScript files. It will also modify index.html so it references these new files. To ensure everything worked, run:

java -jar target/*.war

Then navigate to http://localhost:8090 in your browser.

Refer to Using JHipster in production for more details.

Testing

To launch your application's tests, run:

./mvnw clean test

Client tests

Unit tests are run by Karma and written with Jasmine. They're located in src/test/javascript/ and can be run with:

yarn test

UI end-to-end tests are powered by Protractor, which is built on top of WebDriverJS. They're located in src/test/javascript/e2e and can be run by starting Spring Boot in one terminal (./mvnw spring-boot:run) and running the tests (yarn run e2e) in a second one.

Other tests

Performance tests are run by Gatling and written in Scala. They're located in src/test/gatling and can be run with:

./mvnw gatling:execute

For more information, refer to the Running tests page.

Using Docker to simplify development (optional)

You can use Docker to improve your JHipster development experience. A number of docker-compose configuration are available in the src/main/docker folder to launch required third party services. For example, to start a postgresql database in a docker container, run:

docker-compose -f src/main/docker/postgresql.yml up -d

To stop it and remove the container, run:

docker-compose -f src/main/docker/postgresql.yml down

You can also fully dockerize your application and all the services that it depends on. To achieve this, first build a docker image of your app by running:

./mvnw package -Pprod docker:build

Then run:

docker-compose -f src/main/docker/app.yml up -d

For more information refer to Using Docker and Docker-Compose, this page also contains information on the docker-compose sub-generator (yo jhipster:docker-compose), which is able to generate docker configurations for one or several JHipster applications.

Continuous Integration (optional)

To configure CI for your project, run the ci-cd sub-generator (yo jhipster:ci-cd), this will let you generate configuration files for a number of Continuous Integration systems. Consult the Setting up Continuous Integration page for more information.

If you get stuck on anything, no matter how little, please let me know. I know how the little things are what cause the problems and I don't want you to have any problems.

FAQ

1) In many Redux examples it seems like there is a lot of boilerplate and duplicate code per store slice. Why not have the Action Types be created dynamically by combining the store slice name nouns and action name verbs?

I agree. That's why I created utility functions to hold all the common code and got rid of plural names to enable generic handling, and I replaced static action type definitions with dynamic functions that combine slice nouns and action verbs. It also turns out that most of the tricky RxJS code is also boilerplate code that now resides inside functions that you don't have to mess with most of the time. So you should be able to get productive on an app that uses Observables without first having to be an expert at them, which is hard.

That's a pretty big benefit. What could be seen as costs of doing that?

  1. You lose some static type checking of action types.

Given that most Redux apps are done with React and React doesn't have any static type checking at all, I decided that was a small price to pay. You can also mix this approach and the other one if you really want to. Use the general, un-type-checked, CRUD stuff for ordinary parts of your app (most of it), and use hard-coded, specialty action types when you really need TypeScript's compiler to help you.

Here's some code from the ngrx example app that gives you type checking for the action types. You won't get these checks using my approach.

export function reducer(state: Entities<Book> = initialEntities<Book>({}, slices.BOOK, actions, {}),
  action: book.Actions | collection.Actions): Entities<Book> {
  switch (action.type) {
    ...

action: book.Actions | collection.Actions means that action must be an object of a class in this union of two unions of class definitions

That gives us two checks: action.type must be a string value among the union of string values of the type properties of the classes that action can be. If any of the case values are not among this union of string values, Typescript will point that out to you. And same with action.payload. It must be an object with the structure of the payload property of one of the classes that action can be.

  1. Using only generic action classes like LoadSuccess instead of SearchComplete, the dispatch calls in your components will be more explicit and refer to details of the store.

I see this as a plus in most cases. Otherwise you have extraneous levels of abstraction and you have to look into three files to see exactly what's going on. In most cases, the same person is writing the component, action and reducer files, so what's the point in hiding details in one of them from the other? Now you can get the whole story by reading one line of code. You should decouple things when the need arises, but you can overdo it too.

2) Why are entities modeled as a hash (map) of objects and an array of IDs instead of just an array of objects?

I got the idea from the ngrx example app. I asked about it once and was told that it was done for performance reasons but I'm not sure under what conditions they apply.

3) Why do you generate IDs on the client side, not the server side?

This makes it possible to have the application work offline. It also lets your objects have some persisted attributes and some transient, UI attributes without it affecting the api code. The way this works is that the UI lets you display things before they have been persisted to the server. Then a request to persist happens. The request only sends persistent attributes because the api is ignorant of the user interface. When the response comes back you can find the original object by its previously established ID and handle it accordingly. If successful, you'd likely do nothing that the user sees. However, if you hadn't given it an ID, it would be discarded and recreated from the object in the response. This response object would not have all the transient attributes of the object in the request. So, for example, if its location on the screen were a transient attribute, then the user would see it jump to a default location since the former location would be lost.

Any other questions? Just ask.

Demonstrations and Features

Developer Experience great big example application Angular-kitchen-sink angular-seed-advanced feathers-starter-react-redux-login-roles angular-webpack2-starter
Ambitransportous (?) UNIQUE.
API introspection report and testing interface (?) UNIQUE.
Authentication X X X.
Authentication, JSON Web Token (JWT) (?) X. X.
Authentication, social sign-in UNIQUE.
Authentication, using Oauth (?) X. X.
Authentication, with two-factor authentication UNIQUE
Authorization, Role-based (?) X. X.
Automated device testing X. X.
back end generator (?) X. X.
Can run on a desktop without a browser UNIQUE.
Client-side dependency injection X. X. X. X.
Client-side performance monitoring & instrumentation (?) UNIQUE
Client-side routing, routes/states contain special properties (?) UNIQUE
Client-side routing, State-based routing (?) X. X. X. X.
Client-side unit tests X X X X
Clustered HTTP sessions UNIQUE.
Code coverage reporting (?) X. X. X.
Command line interface (CLI) X. X. X.
Command line interface (CLI), can do database migration/evolution (?) UNIQUE.
Compiled, supports ahead of time (AOT) compilation X X. X
Components communicate with events X X
Concurrency (synchronization), supports database transactions UNIQUE.
Core Module (client-side) X X
Cross-Origin Resource Sharing (CORS) (?) X. X
Data binding & change detection/tracking, no dirty checks (good), getters/setters (bad) (?) UNIQUE.
Database connection pooling UNIQUE.
Deployment automation, to a mobile native executable UNIQUE
Deployment automation, using Docker (?) X X
Deployment automation, using Heroku (?) UNIQUE
Development build, html page processing (?) UNIQUE.
Development build, script UNIQUE.
End-to-end tests (?) X X X X
Error handling, Client-side logging X X X
Error handling, Server-side logging X. X. X. X.
FEATURE (a.k.a. module, entity) generator (?) UNIQUE.
Graphical schema editing UNIQUE.
Hot Module Replacement (?) X X
Instrumentation, Metrics, server-side (?) UNIQUE.
Lazy (on-demand) loading of client-side code (?) X. X. X. X.
Local storage X X X
Microservice generator UNIQUE.
Modularized, route-specific CSS X. X. X. X.
No pluralization (?) UNIQUE
Object-relational mapping (?) X. X.
Observables for databinding a.k.a. KVO (?) X. X. X. X.
Persistent, server-side data storage (?) X. X. X. X.
Preloads client-side data (?) X. X. X. X.
Production build, generate docs (?) X. X.
Production build, safe pre-minification (?) X. X. X. X.
Renders markup on the server (universal) (?) UNIQUE
route (client side) generator UNIQUE.
Safe from clickjacking (?) UNIQUE.
Safe from session id hacks (?) UNIQUE.
Separate route configuration files for each module UNIQUE
Separation of smart containers and dumb components (?) UNIQUE
Server-side caching UNIQUE.
Server-side integration & unit tests X. X. X.
Share code between projects (?) UNIQUE.
Shared Module (client side) X X
Single source of truth, central state management, without lots of boilerplate (?) UNIQUE
Style guide for code (?) X. X.
Supports database layer triggers (?) X. X.
Templating, parsable HTML, no imperative code allowed X. X. X. X.
Two-way data binding (?) X. X. X. X.
Typed (?) X. X. X. X.
Typed, statically (?) X. X. X. X.
UML to model generation (?) UNIQUE.
Update generated code in an existing app X. X.
Virtual, shadow DOM (?) UNIQUE.
User Experience great big example application Angular-kitchen-sink angular-seed-advanced feathers-starter-react-redux-login-roles angular-webpack2-starter
Account Management, add/remove user UNIQUE
Account Management, forgotten/recover/reset password X X X
Account Management, login/logout X X X
Account Management, register X X
Asynchronously loaded data example X X X
Blog UNIQUE
Breadcrumbs (?) UNIQUE
Derived, computed properties X X
Dynamic component creation UNIQUE
External, 3rd party, API interaction X X
File Upload UNIQUE
Footer X X
Front-end CRUD, with mock/seed data UNIQUE
Full-stack CRUD (?) X X
Full-stack CRUD, screencast of it UNIQUE
Full-stack CRUD, with Create, Update and Delete X X
Full-stack CRUD, with Create, Update and Delete, individual records X X
Full-stack CRUD, with Create, Update and Delete, whole data structures UNIQUE
Full-stack CRUD, with db-persisted seed data UNIQUE
Full-stack CRUD, with Read X X
i18n, localization (?) X X
Many-to-many data UNIQUE
Modals (popups, dialogs) (?) UNIQUE
Navigation bar X X
Notifications UNIQUE
Number spinner UNIQUE
Pagination, paging (client-side) UNIQUE
Pagination, paging (server-side) X X.
Pagination, paging (server-side), with sorting UNIQUE
Panels, draggable UNIQUE
Realtime data sync (?) UNIQUE
Responsive styles UNIQUE
Search, actually works with backend API UNIQUE
Tables (?) UNIQUE
Timepicker UNIQUE
To do list UNIQUE
User tracking and analytics X X
Dependencies great big example application Angular-kitchen-sink angular-seed-advanced feathers-starter-react-redux-login-roles angular-webpack2-starter
Builders Gradle (opt), Maven (opt), Yeoman
Client-side API interfaces @angular/http @angular/http @angular/http @angular/http
Convenience method libraries lodash lodash lodash lodash
Databases Cassandra (opt), ElasticSearch (opt), H2, MongoDB (opt), MySQL (opt), Postgresql (opt), Redis (opt), SQL Server (opt) Redis Cassandra (opt), CouchDB (opt), ElasticSearch (opt), LevelDB (opt), MongoDB (opt), MySQL (opt), Neo4J (opt), Postgresql (opt), Redis (opt), SQLite (opt) Cassandra (opt), CouchDB (opt), ElasticSearch (opt), LevelDB (opt), MongoDB (opt), MySQL (opt), NeDB (opt), Neo4J (opt), Postgresql (opt), Redis (opt), Rethinkdb (opt), SQLite (opt) Cassandra (opt), CouchDB (opt), ElasticSearch (opt), LevelDB (opt), MongoDB (opt), MySQL (opt), Neo4J (opt), Postgresql (opt), Redis (opt), SQLite (opt)
Documentation generators typedoc typedoc
Examples mgechev's angular-seed
Frameworks (Back-End) Express Express, Feathers.js Express
Frameworks (Front-End) Angular 2.0, Vue (opt) Angular 2.0 Angular 2.0 React, React Native (opt) Angular 2.0
Frameworks (Full Stack) Spring MVC
Generators angular-cli, JHipster angular-cli
Languages Java 7, Java 8, JS ES5, JS ES6 (ES2015), JSX (opt), Typescript JS ES5, JS ES6 (ES2015), Typescript JS ES2016, JS ES5, JS ES6 (ES2015), Typescript JS ES5, JS ES6 (ES2015), JSX (opt) JS ES5, JS ES6 (ES2015), Typescript
Linters codelyzer, ESLint, JSHint, tslint codelyzer, tslint ESLint tslint
Loaders/Bundlers Spring, Webpack Webpack Rollup, SystemJS Webpack Webpack
Misc Angular Style Guide, angular-omni-bar (opt), cssnano, Jackson, JDL Studio, Liquibase, Logback, ng-annotate, nodemon, redux-devtools, RxJS, Swagger, useref, wiredep Immutable, redux-devtools, RxJS Angular Style Guide, cssnano, Electron, redux-devtools, RxJS Passport, react-router, redux-devtools nodemon, redux-devtools, RxJS
Package Managers bower, npm, Yarn npm npm npm npm, Yarn (opt)
Routers Angular Component Router Angular Component Router Angular Component Router Angular Component Router
Runtime Environments Node Node NativeScript, Node Node Node
Security Frameworks Spring Social
State Managers ngrx ng-redux ngrx Redux ngrx
Styles Normalize.css
Task Runners Gulp Gulp
Test assertion libraries Chai, Jasmine, Mocha Chai, Jasmine, Mocha Jasmine Chai, Mocha Jasmine
Test coverage reporters Istanbul, karma-coverage Istanbul
Test runners BrowserSync, Karma BrowserSync (opt), Karma Karma
Transpilers libsass libsass libsass libsass
Unit testers JUnit, Mockito
Widget collections Angular Material Angular Material Angular Material

See any mistakes? Help improve this data

About

An example app built with JHipster, Angular 4, Redux, Webpack, and Angular-CLI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 45.0%
  • Java 33.7%
  • HTML 14.8%
  • CSS 2.5%
  • Scala 2.2%
  • JavaScript 1.0%
  • Other 0.8%