Giter Site home page Giter Site logo

event-driven-example's Introduction

Introduction to Monorepo Example Repository

๐Ÿ‘‹ Welcome to my Monorepo Boilerplate repository.

This project is structured as a monorepo and is managed with Nx, a powerful tool for monorepo development, which helps orchestrate and optimize the build process among other tasks.

The backend is built with NestJS, featuring many standard implementations ready to go out of the box. Read below for more details.

Table of Contents

Getting Started

To get the backend up and running in a development environment, follow these steps:

  1. Clone the repository: Use the following command to clone the repository to your local machine:

    git clone https://github.com/DeanRTaylor1/monorepo-example
  2. Install dependencies: Navigate to the project directory and use Yarn to install the necessary dependencies:

    cd <repository-directory>
    yarn
  3. Run the Application: You can now start the application with the following command (utilizes Docker):

    yarn dev:docker

    This command (dev:be) is shorthand for docker-compose up, as defined in the scripts section of package.json, which sets up the database and server containers. More applications can be added to the docker-compose.yml

Backend Structure

The backend is structured with an emphasis on modular organization aligned with my personal preference for NestJs. The root of the project contains the app directory, which holds global logic and forms the base of our Nest project.

Utility decorators such as @BodyToCamel and @SnakeInterceptor are integrated for handling case conversion of DTOs between snake case and camelCase. Types are shared in the common Case Utils directory to minimize repetition across backend and frontend.

Sensitive information is safeguarded by the responses interceptor, which automatically excludes specified fields from client exposure. These sanitized types are also declared in the common Sanitize Types package for frontend usage.

Configurations, including environment variables, are managed through an env object, which is set up to read from .env.NODE_ENV.local files. Sequelize is the chosen ORM, but you can swap it out for TypeORM if preferred.

Role-based authentication with JWT is implemented, with route-level control using decorators and guards, by default all routes have basic auth and you need to disable auth with the @Public() decorator, to set up role authentication you can apply the @Roles and @UseGuard decorators which is explained on the nestjs docs. Refer to the UsersController for an example of setup.

Further project details and instructions on extending functionality with Nx are available in the Nx documentation.

Directory Structure

Below is the directory structure of the backend, illustrating the organization and location of important files:

.
โ”œโ”€โ”€ databases
โ”‚   โ”œโ”€โ”€ config
โ”‚   โ”‚   โ””โ”€โ”€ config.js
โ”‚   โ”œโ”€โ”€ migrations
โ”‚   โ”‚   โ””โ”€โ”€ 20231031032120-create-users.ts
โ”‚   โ””โ”€โ”€ models
โ”‚       โ””โ”€โ”€ index.js
โ”œโ”€โ”€ jest.config.ts
โ”œโ”€โ”€ project.json
โ”œโ”€โ”€ sequelize.js
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ app
โ”‚   โ”‚   โ”œโ”€โ”€ app.controller.spec.ts
โ”‚   โ”‚   โ”œโ”€โ”€ app.controller.ts
โ”‚   โ”‚   โ”œโ”€โ”€ app.module.ts
โ”‚   โ”‚   โ”œโ”€โ”€ app.service.spec.ts
โ”‚   โ”‚   โ”œโ”€โ”€ app.service.ts
โ”‚   โ”‚   โ”œโ”€โ”€ decorators
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ body-to-camel.decorator.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ pagination.decorator.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ public-route.decorator.ts
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ roles.decorator.ts
โ”‚   โ”‚   โ”œโ”€โ”€ filters
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ all-exceptions.filter.spec.ts
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ all-exceptions.filter.ts
โ”‚   โ”‚   โ”œโ”€โ”€ guards
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.guard.ts
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ roles.guard.ts
โ”‚   โ”‚   โ”œโ”€โ”€ interceptors
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ responses.interceptor.spec.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ responses.interceptor.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ route-logger.interceptor.spec.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ route-logger.interceptor.ts
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ snakecase.interceptor.spec.ts
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ snakecase.interceptor.ts
โ”‚   โ”‚   โ”œโ”€โ”€ modules
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ [auth](apps/backend/src/app/modules/auth)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ [base](apps/backend/src/app/modules/base)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ [config](apps/backend/src/app/modules/config)
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [users](apps/backend/src/app/modules/users)
โ”‚   โ”‚   โ””โ”€โ”€ pipes
โ”‚   โ”‚       โ”œโ”€โ”€ compare-password.pipe.ts
โ”‚   โ”‚       โ””โ”€โ”€ hash-password.pipe.ts
โ”‚   โ”œโ”€โ”€ assets
โ”‚   โ”œโ”€โ”€ main.ts
โ”‚   โ””โ”€โ”€ utils
โ”‚       โ”œโ”€โ”€ encryption.ts
โ”‚       โ””โ”€โ”€ format.utils.ts
โ”œโ”€โ”€ tsconfig.app.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ tsconfig.spec.json
โ””โ”€โ”€ webpack.config.js

event-driven-example's People

Contributors

deanrtaylor1 avatar padi-dev-deantr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.