This project structure is for building Graphql server on top of / with RESTful APIs and microservices using Node.js, ExpressJS and Docker support. It is designed to be scalable on containerized environment like Kubernetes, and designed to be enterprise ready.
The principle of the project structure is isolation, so multiple developers can work on the same project without high dependency.
- ExpressJS with vanilla javascript.
- Apollo Server for Graphql
- Mocha & Chai for testing
- ESLint with Airbnb preset/ruleset
- Docker support
- dotenv to load environment variables from .env
- Compression for Gzip response compression
- Winston for Logging
- Node LTS 10.x
- Docker
- Npm
Root of the project
- package.json
- Entry point for node app with
npm
configurations for dependent packages and scripts.
- Entry point for node app with
- bin
- This folder holds single point of start for ther server.
www
file is executable file withnode
and include code which is reposnsible for creating http server with desirable port and other preconfigure applications (express and apollo server) to be run on top of the http server.
- _mocks_
- This folder will hold al the
mocks
require in unit tests.
- This folder will hold al the
- _tests_
- This folder will have all the tests file for application for TDD
- logs
- All logs generated using
winston
module will go in this folder. Bydefault daily rotaional setting has been applied for application logs.
- All logs generated using
- server.js
- Server.js file is ExpressJS application server where express app is being created and configured.
- This file is reposnible for setting up middlewares such as
apollo-server
,cors
,compression
etc.
- .eslintrc
- This file is configuration endpoint for
eslint
any rules, presets, other lint configuration goes in this file. For this appAirbnb
preset settings resides here.
- This file is configuration endpoint for
- Dockerfile
- The
Dockerfile
is essentially the build instructions to build the image withnode
as base image.
- The
- .env
- A file containing all the enviroment variables to be used in application using
dotenv
package.
- A file containing all the enviroment variables to be used in application using
This folder is where all application code is structured.
-
app.js
app
is apollo server with preconfigure typedefs and resolver. This file is single entry point for apollo server where all the other configuration can be set apart from typeDefs and resolvers etc.
-
modules This folder will hold all modules of project strcutured in folder with name of modules
typedef.index.js
file is entry point from which all typeDefs from all other modules to be exported.resolvers.index.js
file is entry point from which all resolvers to be exported from modules.mutations.index.js
file is entry point from which all mutations to be exported from modules.
-
lib
lib
is where libraries by the original author of the project are located. This should hold all reusable libraries which are used in project.
-
helper
helper
will hold all the resuable project doamain related helper code.
-
constant
- All the constants including string, variables, etc used in project will be structured in this folder.
-
config
- All the project configurations common for project such as db url etc will be stored in this folder.
-
adapter or db
- If your project has
interfaces
which will communicate with other parties that can collectively structure here. Ordb
communications for the project can be strctured in this folder
- If your project has
-
abstratction
- All abstarct classes require for the project can go in this folder.
Install:
npm install
npm start
npm run start:dev
npm run start:production
npm run lint
npm test
docker build -t <tag_name> .
docker run --name <project_name> -p 5000:5000 <tag_name>