Skip to content

Boilerplate for NodeJS, Typescript, Express (wrapped with Routing-Controller) project with clean architecture structure

License

Notifications You must be signed in to change notification settings

jjteoh-pingspace/node-ts-clean-boilerplate

Repository files navigation

Project Title

version

This is a boilerplate for project wish to use nodeJS, Typescript, clean architecture. Its built on top of ExpressJS. Some common libraries are included in the project, please refer package.json for more details.


clean architecture [extracted from Google]



Folder Structure:

The base structure look like this:

config               → configurations
src                  → source code
 └ data              → data access layer, e.g. db models, data repositories
   └ models          → data structure of data layer (db, files)
   └ repositories    → communicator between data and domain layer
 └ domain            → domain layer, e.g. usecases, entities
   └ entities        → data structure that use within domain layer
   └  usecases       → business rules
 └ lib               → infrastructure layer, e.g. frameworks, db drivers, plugins
 └ presentation      → presentation layer, e.g. controllers, socket gateway
   └ controllers     → route handlers
test                 → test files
tools                → the build tools, CICD tool that not related to the business
.dockerignore        → docker ignore file
.eslintignore        → eslint ignore file
.eslintrc.js         → eslint configurations
.gitignore           → git ignore file
.prettierrc          → prettier configurations
Dockerfile           → docker configurations
gulpfile.js          → Gulp entry file
nodemon.json         → nodemon configurations
package.json         → project info and dependencies
README.md            → repo info
tsconfig.json        → typescript configurations
yarn.lock            → yarn dependencies lockdown


Naming Convention

folder naming convention

  • folder_name
  • no restriction on plural or singular, depend on use cases
  • e.g. system_configs

file naming convention

  • file_name.functional_area.file_ext
  • no restriction on plural or singuler, depend on use cases
  • e.g. user.repository.ts, user_repository.interface.ts


VS Code Extensions

These extensions are recommended to have in order to standardize coding style:

  • ESLint -- EcmaScript linter
  • Prettier -- Code formatter


Get Started

Assumptions:

  • you are running on VS Code on Windows
  • for other development environment, if you face problems in installing the required tools, please refer official manual online, or approach repo maintainers for help.

  1. Clone this repository locally.
  2. Install yarn globally/locally in your machine, installation guide.
  3. Install development dependencies with
    yarn install # or just yarn
  4. Install Gulp cli globally in your machine, installation guide
  5. Make sure you can build the project with:
    yarn build
  6. To run the application in watch mode:
    yarn start:dev
  7. To run the application in production mode:
    yarn start:prod
  8. You can explore more available commands in package.json


Docker

You are encouraged to work in containerized environment to prevent compatibility issue.

Please install docker in your local machine before proceed, to get started.

To build app into docker image (need help?):

docker build -t <username/my-service>

To list available images in your machine(need help?):

docker images

To run built image (need help?):

docker run -d <container_id>

To list running container (need help?)::

docker ps

For more details on how to use docker, please refer doc.



Git Commit Standard

Recommended to follow committizen practices when committing changes. Please install git cz on your machine.

About

Boilerplate for NodeJS, Typescript, Express (wrapped with Routing-Controller) project with clean architecture structure

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published