/bach.js

Bach.js is a full-stack framework using Nest.js and Next.js to jump start your next project.

Primary LanguageJavaScriptMIT LicenseMIT

Bach.js - Nest.js + Next.js + Tailwind + Lerna/NX

I started this project mainly because I have yet to find a suitable starter framework built using the latest stack with Nest.js and Next.js. These frameworks are great but there are still a lot of boilerplating you need to do when you are building your next project idea.

Some other motivations behind this framework was to speed up Nest.js dev time using Vite. I found the time it takes to hot-reload after each code change painful as the code base grew. Thankfully Vite was able to resolve these issues and putting this available for everyone to use.

β€œCeaseless work...that is my secret.” - J.S. Bach

Features

  • Nest.js equipped with Vite for astonishgly faster Hot Module Replacement πŸ”₯
  • Next.js + Tailwind UI theme for client and admin
  • Lerna with NX for faster builds and caching
  • TypeORM with better transactional support
  • Swagger documentation, Joi validation, Winston logger, ...
  • User auth and role-based access control
  • REST API w/ pagination
  • Folder structure, code samples and best practices
  • CI/CD ready using Github Actions

1. Getting started

1.1 Requirements

Before starting, make sure you have at least those components on your workstation:

  • Node v16+
  • Yarn 1.22+
  • Up-to-date installation of Docker is useful for setting up your local environment, but it is not required for development.

1.2 Project configuration

Start by cloning this project on your workstation.

git clone https://github.com/jaequery/bach.js

The next thing will be to install all the dependencies of the project.

cd ./bachjs
yarn

Once the dependencies are installed, you can now configure your project by creating a new .env file containing your environment variables used for development.

cp .env.example .env
vi .env

The example configuration is already setup to work with the Postgres database that will be instantiated via our docker-compose.yml file. But if you wish to use your separate Postgres instance, you may modify this file to suit your needs.

Last but not least, update the JWT_SECRET to sign the JWT tokens.

1.3 Launch and discover

You are now ready to launch the Postgres database, NestJS backend, and Next.js frontend using the commands below.

# Start Postgres database using Docker
yarn db:start

# Launch the backend development server
yarn api:start

# Launch the frontend development server
yarn ui:start

You can now head to http://localhost:3000 for backend as well as http://localhost:3001 for frontend to verify they are up and running.

2. Project structure

This template was made with a well-defined directory structure.

src/
β”œβ”€β”€ migrations/  # Contains the TypeORM migrations
β”œβ”€β”€ modules
β”‚   β”œβ”€β”€ common/  # The common module containing interfaces, pipes, guards, services used in the whole application
β”‚   β”œβ”€β”€ user/
β”‚   β”‚   β”œβ”€β”€ user.entity.ts
β”‚   β”‚   β”œβ”€β”€ user.controller.ts
β”‚   β”‚   β”œβ”€β”€ user.controller.spec.ts
β”‚   β”‚   β”œβ”€β”€ user.service.ts
β”‚   β”‚   β”œβ”€β”€ user.service.spec.ts
β”‚   β”‚   β”œβ”€β”€ user.module.ts
β”‚   β”‚   β”œβ”€β”€ user.dto.ts

3. Default NPM commands

The CLI commands below are already included with this template and can be used to quickly run, build and test your project.

# Start the Nest.js backend API w/ faster hot-reloads
yarn api:start

# Run the UI app using Next.js
yarn ui:start

# Create a new migration named MyMigration
yarn db:migration:create [MyMigration]

# Run the TypeORM migrations
yarn db:migration:up

# Revert the TypeORM migrations
yarn db:migration:down

# Builds all the apps
yarn build

# Tests all the apps
yarn test

4. Project goals

The goal of this project is to provide a clean and up-to-date "starter pack" for REST API projects that are built with Nest.js and Next.js.

5. Roadmap

The following improvements are currently in progress :

  • Configuration validation
  • TypeORM migration support
  • Project structure documentation
  • CI/CD ready improvements and better usage of environment variables
  • Secure authentication using JWT
  • Support SSO using Google
  • Role-based access control
  • Better logging configuration
  • Pagination support
  • Backend + UI scaffolder
  • Out of the box integrations to Segment for user tracking and events

6. Contributing

Feel free to suggest an improvement, report a bug, or ask something: https://github.com/jaequery/bach.js/issues