- Notifications
You must be signed in to change notification settings - Fork0
Production ready full stack starter kit. Featuring: Docker, Node, Postgres, Sequelize, React, Redux, GraphQL, RXjs, Webpack 3, Hot Module Reloading, Server Side Rendering and Code Splitting.
License
klk2/docker-postgres-react-redux-graphql-hmr-ssr-kit
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a meta framework, framework. A project made up of specific technologies that are easily interchangable.
Docker: - This is where our stack starts our app is split up into three containers an Nginx container for serving static files, a Node.js container for the backend and a Postgres container for our database. This also enables for cross platform development and deployment. Robust, Flexible and Dead Simple.
Postgres: - The tried, trued and tested defacto databse. In this project I use the popular sequelize ORM.
GraphQL: - A more effecient way to query data from a server. A better way to develop with the interactive graphql interface. This also provides an abstraction layer between our api and database that provides additional flexiblity if we every need to swap it out.
React, Redux, React Router: - At this point its almost and industry standard. Undirectional data flow, fast render times and extremely flexible.
Redux Observables (Rxjs): - RxJS 5-based middleware for Redux. Compose and cancel async actions to create side effects and more.
Server Side Rendering: - We use server side rending by utilizing Universal javascript on the Node.js server. Because were using React its simply a matter of rendering React views on the server.
Code Splitting: - Split code into bundles so that code is asynchronously loaded by the client.
Hot Module Reloading: - Replaces modules that have been changed in real time while preserving the state.
The application works like this.
We use shell scripts to handle docker and related tasks, these are located in thebin directory. e.x../bin/develop.sh or./bin/deploy.sh (more details on this below)
The shell scripts sets up our docker containers, migrates the database, installs dependencies, compiles source code and launches our servers.
The Nginx server handles static file requests and the Node.js Express server handles all other request. When a request is made we render our React application on the server based on that route and return the output as a html.
Once the Html is sent to the client our React application takes over.
On build our application is split up into bundles for each route. Only that routes bundle is served to the client; when a new route is entered a new bundle is requested and sent to the client.
In addition our core dependencies are split into a seperate bundles and cached our our Nginx server. Everything is fingerprinted.
When developing we spin up a seperate frontend server that handles hot module reloading.
On a more techinical note we use all sorts of goodies that I leave you to explore, things likereselect,redux-actions,immutablejs,cssnext,react-router-redux etc...
Last but not least I have to give a huge shout out to @Producters for thehttps://github.com/Producters/docker-node-react-starter which is what this project is based off of.
Get latest docker (1.11+) & docker-compose (1.7+):
https://www.docker.com/
https://docs.docker.com/compose/
Pull down the repository:
git clone git@github.com:Alex-ray/docker-postgres-react-redux-graphql-hmr-ssr-kit.git
Start the dev server:
./bin/develop.sh
Wait for docker to set up dev env, then openhttp://localhost:8000
# build production images, create db backup & start./bin/deploy.sh# stop server./bin/stop_production.sh# start srever./bin/start_production.sh
In prod mode sources are added to docker image rather than mounted from host. Nginx serves static files, proxy pass to node for app. Logs inlogs dir.
Copy your .key and .crt files tonginx/ssl and run./bin/deploy.sh.
# frontend./bin/npm_frontend.sh install [package] --save-dev# backend./bin/npm_backend.sh install [package] --save
# open psql session./bin/psql.sh# create a backup in backups dir./bin/backup.sh# restore from a backup in backups dir (server must be stopped)./bin/restore.sh backups/somebackup.bak
bin/ - various utility scriptsdocker-compose.yml - base docker compose configdocker-compose.overrides.yml - development docker compose configdocker-compose.production.yml - production docker compose configfrontend/ - frontend stufffrontend/package.json - npm package file with frotnend dependenciesfrontend/dist/ - compiled and production ready client side codefrontend/universal/ - universal javascript codefrontend/index.js - js entry point. include other js deps herebackend/ - backend stuffbackend/lib/ - node appbackend/lib/index.js - entry pointbackend/lib/models/ - sequelize model definitionsbackend/lib/migrations/ - sequelize migrationsbackend/config/ - configbackend/config/default.json - config defaultsbackend/views/ - pug templatesbackend/Dockerfile - production build dockerfilebackend/media/ - user uploads @TODObackend/package.json - npm pacakge file with backend & test deposbackend/nightwatch.json - nigthwatch configbackend/tests/specs/* - nightwatch test specslogs/ - in prod mode app, nginx logs go herenginx/ - nginx stuff for prod modenginx/ssl/ - put key & cert here if you use sslnginx/nginx_nossl.conf - nginx conf if no ssl is usednginx/nginx_ssl.conf - nginx conf for deploy with sslConfig files for backend are located atconfig/*.json.
Ifconfig/[NODE_ENV].json exists, values are loaded from it first. Then defaults are filled in fromconfig/default.json;
Winston is used for logging. Loggers and transport are configured via config files, seeconfig/default.json.
importlogger,{getLogger}from'winston';//default loggerlogger.info('logging to default');logger.error('bad thing happened');//custom logger, define transports in configletnetlogger=getLogger('network');netlogger.info('network stuff');
# create new migration./bin/sequelize.sh migration:create --name some_migration# run migrations./bin/sequelize.sh db:migrate
e2e tests are implemented usingnightwatch.js. Test specs are located atbackend/tests/specs/
#run tests./bin/test.sh# skip frontend build (eg, running tests repeatedly)./bin/test.sh --skipbuild# keep selenium, vnc server & database running after tests end# for fast next run & to keep vnc from disconnecting if debuggin./bin/test.sh --dontstop# run a particular test file only./bin/test.sh -- --test tests/specs/auth.js# run particular test case only./bin/test.sh -- --test tests/specs/auth.js --testcase'User can login via auth0'
To debug tests it's possible to vnc into selenium container while its running at localhost:5900 and view the browser. Password issecret.
sudo apt-get install vinagre# vnc clientvinagre localhost:5900About
Production ready full stack starter kit. Featuring: Docker, Node, Postgres, Sequelize, React, Redux, GraphQL, RXjs, Webpack 3, Hot Module Reloading, Server Side Rendering and Code Splitting.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- JavaScript80.1%
- Shell10.6%
- CSS9.3%