├── .gitignore
├── .prettierrc
├── README.md
├── apps
├── api
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── nest-cli.json
│ ├── package.json
│ ├── src
│ │ ├── app.controller.spec.ts
│ │ ├── app.controller.ts
│ │ ├── app.module.ts
│ │ ├── app.service.ts
│ │ └── main.ts
│ ├── test
│ │ ├── app.e2e-spec.ts
│ │ └── jest-e2e.json
│ ├── tsconfig.build.json
│ └── tsconfig.json
└── client
│ ├── .gitignore
│ ├── index.html
│ ├── package.json
│ ├── postcss.config.js
│ ├── public
│ └── vite.svg
│ ├── src
│ ├── App.tsx
│ ├── assets
│ │ ├── nest.svg
│ │ └── react.svg
│ ├── index.css
│ ├── main.tsx
│ └── vite-env.d.ts
│ ├── tailwind.config.js
│ ├── tsconfig.json
│ ├── tsconfig.node.json
│ └── vite.config.ts
├── package.json
└── turbo.json
/.gitignore:
--------------------------------------------------------------------------------
1 | **/node_modules
2 |
3 | **/package-lock.json
4 |
5 | apps/api/dist
6 | apps/client/dist
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "trailingComma": "none",
4 | "semi": false
5 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Nestjs & Reactjs Boilerplate - Typescript
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | [circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
11 | [circleci-url]: https://circleci.com/gh/nestjs/nest
12 |
13 | A simple React - Nestjs boilerplate.
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
29 |
30 | ## Description
31 |
32 | [Nest](https://github.com/nestjs/nest) framework and [React](https://github.com/facebook/react) TypeScript starter repository.
33 |
34 | ## Installation
35 |
36 | ```bash
37 | $ npm install
38 | ```
39 |
40 | ## Running the app
41 |
42 | ```bash
43 | # development
44 | $ npm run dev
45 |
46 | # production
47 | $ npm run build
48 | $ npm start
49 | ```
50 |
51 | ## Expose
52 |
53 | ```bash
54 | # development
55 | $ frontend: http://localhost:3000
56 | $ backend: http://localhost:3000/api
57 |
58 | # build
59 | $ frontend: http://localhost
60 | $ backend: http://localhost/api
61 | ```
62 |
63 | ## Test
64 |
65 | ```bash
66 | # unit tests
67 | $ npm run test
68 |
69 | # e2e tests
70 | $ npm run test:e2e
71 |
72 | # test coverage
73 | $ npm run test:cov
74 | ```
75 |
76 | ## Features
77 | - TailwindCSS
78 |
79 | ## Stay in touch
80 |
81 | - Author - [Jason Mendoza](https://jasonmz.carrd.co/)
82 |
--------------------------------------------------------------------------------
/apps/api/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | parser: '@typescript-eslint/parser',
3 | parserOptions: {
4 | project: 'tsconfig.json',
5 | tsconfigRootDir: __dirname,
6 | sourceType: 'module',
7 | },
8 | plugins: ['@typescript-eslint/eslint-plugin'],
9 | extends: [
10 | 'plugin:@typescript-eslint/recommended',
11 | 'plugin:prettier/recommended',
12 | ],
13 | root: true,
14 | env: {
15 | node: true,
16 | jest: true,
17 | },
18 | ignorePatterns: ['.eslintrc.js'],
19 | rules: {
20 | '@typescript-eslint/interface-name-prefix': 'off',
21 | '@typescript-eslint/explicit-function-return-type': 'off',
22 | '@typescript-eslint/explicit-module-boundary-types': 'off',
23 | '@typescript-eslint/no-explicit-any': 'off',
24 | },
25 | };
26 |
--------------------------------------------------------------------------------
/apps/api/.gitignore:
--------------------------------------------------------------------------------
1 | # compiled output
2 | /dist
3 | /node_modules
4 |
5 | # Logs
6 | logs
7 | *.log
8 | npm-debug.log*
9 | pnpm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 | lerna-debug.log*
13 |
14 | # OS
15 | .DS_Store
16 |
17 | # Tests
18 | /coverage
19 | /.nyc_output
20 |
21 | # IDEs and editors
22 | /.idea
23 | .project
24 | .classpath
25 | .c9/
26 | *.launch
27 | .settings/
28 | *.sublime-workspace
29 |
30 | # IDE - VSCode
31 | .vscode/*
32 | !.vscode/settings.json
33 | !.vscode/tasks.json
34 | !.vscode/launch.json
35 | !.vscode/extensions.json
--------------------------------------------------------------------------------
/apps/api/nest-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/nest-cli",
3 | "collection": "@nestjs/schematics",
4 | "sourceRoot": "src",
5 | "compilerOptions": {
6 | "deleteOutDir": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/apps/api/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "api",
3 | "version": "0.0.1",
4 | "description": "",
5 | "author": "",
6 | "private": true,
7 | "license": "UNLICENSED",
8 | "scripts": {
9 | "build": "nest build",
10 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11 | "start": "nest start",
12 | "dev": "nest start --watch --preserveWatchOutput",
13 | "start:debug": "nest start --debug --watch",
14 | "start:prod": "node dist/main",
15 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
16 | "test": "jest",
17 | "test:watch": "jest --watch",
18 | "test:cov": "jest --coverage",
19 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
20 | "test:e2e": "jest --config ./test/jest-e2e.json"
21 | },
22 | "dependencies": {
23 | "@nestjs/common": "^9.0.0",
24 | "@nestjs/core": "^9.0.0",
25 | "@nestjs/platform-express": "^9.0.0",
26 | "@nestjs/serve-static": "^3.0.1",
27 | "reflect-metadata": "^0.1.13",
28 | "rxjs": "^7.2.0"
29 | },
30 | "devDependencies": {
31 | "@nestjs/cli": "^9.0.0",
32 | "@nestjs/schematics": "^9.0.0",
33 | "@nestjs/testing": "^9.0.0",
34 | "@types/express": "^4.17.13",
35 | "@types/jest": "29.2.4",
36 | "@types/node": "18.11.18",
37 | "@types/supertest": "^2.0.11",
38 | "@typescript-eslint/eslint-plugin": "^5.0.0",
39 | "@typescript-eslint/parser": "^5.0.0",
40 | "eslint": "^8.0.1",
41 | "eslint-config-prettier": "^8.3.0",
42 | "eslint-plugin-prettier": "^4.0.0",
43 | "jest": "29.3.1",
44 | "prettier": "^2.3.2",
45 | "source-map-support": "^0.5.20",
46 | "supertest": "^6.1.3",
47 | "ts-jest": "29.0.3",
48 | "ts-loader": "^9.2.3",
49 | "ts-node": "^10.0.0",
50 | "tsconfig-paths": "4.1.1",
51 | "typescript": "^4.7.4"
52 | },
53 | "jest": {
54 | "moduleFileExtensions": [
55 | "js",
56 | "json",
57 | "ts"
58 | ],
59 | "rootDir": "src",
60 | "testRegex": ".*\\.spec\\.ts$",
61 | "transform": {
62 | "^.+\\.(t|j)s$": "ts-jest"
63 | },
64 | "collectCoverageFrom": [
65 | "**/*.(t|j)s"
66 | ],
67 | "coverageDirectory": "../coverage",
68 | "testEnvironment": "node"
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/apps/api/src/app.controller.spec.ts:
--------------------------------------------------------------------------------
1 | import { Test, TestingModule } from '@nestjs/testing'
2 | import { AppController } from './app.controller'
3 | import { AppService } from './app.service'
4 |
5 | describe('AppController', () => {
6 | let appController: AppController
7 |
8 | beforeEach(async () => {
9 | const app: TestingModule = await Test.createTestingModule({
10 | controllers: [AppController],
11 | providers: [AppService]
12 | }).compile()
13 |
14 | appController = app.get(AppController)
15 | })
16 |
17 | describe('root', () => {
18 | it('should return "Hello World!"', () => {
19 | expect(appController.getHello()).toBe('Hello World!')
20 | })
21 | })
22 | })
23 |
--------------------------------------------------------------------------------
/apps/api/src/app.controller.ts:
--------------------------------------------------------------------------------
1 | import { Controller, Get } from '@nestjs/common'
2 | import { AppService } from './app.service'
3 |
4 | @Controller()
5 | export class AppController {
6 | constructor(private readonly appService: AppService) {}
7 |
8 | @Get()
9 | getHello(): string {
10 | return this.appService.getHello()
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/apps/api/src/app.module.ts:
--------------------------------------------------------------------------------
1 | import { Module } from '@nestjs/common'
2 | import { ServeStaticModule } from '@nestjs/serve-static'
3 | import { join } from 'path'
4 |
5 | import { AppController } from './app.controller'
6 | import { AppService } from './app.service'
7 |
8 | @Module({
9 | imports: [
10 | ServeStaticModule.forRoot({
11 | rootPath: join(__dirname, '../..', 'client', 'dist')
12 | })
13 | ],
14 | controllers: [AppController],
15 | providers: [AppService]
16 | })
17 | export class AppModule {}
18 |
--------------------------------------------------------------------------------
/apps/api/src/app.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@nestjs/common'
2 |
3 | @Injectable()
4 | export class AppService {
5 | getHello(): string {
6 | return 'Hello World from Nestjs API!'
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/apps/api/src/main.ts:
--------------------------------------------------------------------------------
1 | import { NestFactory } from '@nestjs/core'
2 | import { AppModule } from './app.module'
3 |
4 | async function bootstrap() {
5 | const app = await NestFactory.create(AppModule)
6 | app.setGlobalPrefix('api')
7 | await app.listen(80)
8 | }
9 | bootstrap()
10 |
--------------------------------------------------------------------------------
/apps/api/test/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { INestApplication } from '@nestjs/common'
2 | import { Test, TestingModule } from '@nestjs/testing'
3 | import * as request from 'supertest'
4 | import { AppModule } from './../src/app.module'
5 |
6 | describe('AppController (e2e)', () => {
7 | let app: INestApplication
8 |
9 | beforeEach(async () => {
10 | const moduleFixture: TestingModule = await Test.createTestingModule({
11 | imports: [AppModule]
12 | }).compile()
13 |
14 | app = moduleFixture.createNestApplication()
15 | await app.init()
16 | })
17 |
18 | it('/ (GET)', () => {
19 | return request(app.getHttpServer())
20 | .get('/')
21 | .expect(200)
22 | .expect('Hello World!')
23 | })
24 | })
25 |
--------------------------------------------------------------------------------
/apps/api/test/jest-e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "moduleFileExtensions": ["js", "json", "ts"],
3 | "rootDir": ".",
4 | "testEnvironment": "node",
5 | "testRegex": ".e2e-spec.ts$",
6 | "transform": {
7 | "^.+\\.(t|j)s$": "ts-jest"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/apps/api/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4 | }
5 |
--------------------------------------------------------------------------------
/apps/api/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "declaration": true,
5 | "removeComments": true,
6 | "emitDecoratorMetadata": true,
7 | "experimentalDecorators": true,
8 | "allowSyntheticDefaultImports": true,
9 | "target": "es2017",
10 | "sourceMap": true,
11 | "outDir": "./dist",
12 | "baseUrl": "./",
13 | "incremental": true,
14 | "skipLibCheck": true,
15 | "strictNullChecks": false,
16 | "noImplicitAny": false,
17 | "strictBindCallApply": false,
18 | "forceConsistentCasingInFileNames": false,
19 | "noFallthroughCasesInSwitch": false
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/apps/client/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/apps/client/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | NestJs + React + TS
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/apps/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "tsc && vite build",
9 | "preview": "vite preview"
10 | },
11 | "dependencies": {
12 | "react": "^18.2.0",
13 | "react-dom": "^18.2.0"
14 | },
15 | "devDependencies": {
16 | "@types/react": "^18.0.28",
17 | "@types/react-dom": "^18.0.11",
18 | "@vitejs/plugin-react": "^3.1.0",
19 | "autoprefixer": "^10.4.14",
20 | "postcss": "^8.4.21",
21 | "tailwindcss": "^3.3.1",
22 | "typescript": "^4.9.3",
23 | "vite": "^4.2.0"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/apps/client/postcss.config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | plugins: {
3 | tailwindcss: {},
4 | autoprefixer: {},
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/apps/client/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/client/src/App.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react'
2 | import nestLogo from './assets/nest.svg'
3 | import reactLogo from './assets/react.svg'
4 |
5 | function App() {
6 | const [greeting, setGreeting] = useState('')
7 |
8 | useEffect(() => {
9 | fetch('/api')
10 | .then((res) => res.text())
11 | .then(setGreeting)
12 | }, [])
13 |
14 | return (
15 |
16 |
17 |
25 |
Nest + React
26 |
{greeting}
27 |
28 |
29 | )
30 | }
31 |
32 | export default App
33 |
--------------------------------------------------------------------------------
/apps/client/src/assets/nest.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/client/src/assets/react.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/client/src/index.css:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
--------------------------------------------------------------------------------
/apps/client/src/main.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/apps/client/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/apps/client/tailwind.config.js:
--------------------------------------------------------------------------------
1 | /** @type {import('tailwindcss').Config} */
2 | export default {
3 | content: [
4 | "./index.html",
5 | "./src/**/*.{js,ts,jsx,tsx}",
6 | ],
7 | theme: {
8 | extend: {},
9 | },
10 | plugins: [],
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/apps/client/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ESNext",
4 | "useDefineForClassFields": true,
5 | "lib": ["DOM", "DOM.Iterable", "ESNext"],
6 | "allowJs": false,
7 | "skipLibCheck": true,
8 | "esModuleInterop": false,
9 | "allowSyntheticDefaultImports": true,
10 | "strict": true,
11 | "forceConsistentCasingInFileNames": true,
12 | "module": "ESNext",
13 | "moduleResolution": "Node",
14 | "resolveJsonModule": true,
15 | "isolatedModules": true,
16 | "noEmit": true,
17 | "jsx": "react-jsx"
18 | },
19 | "include": ["src"],
20 | "references": [{ "path": "./tsconfig.node.json" }]
21 | }
22 |
--------------------------------------------------------------------------------
/apps/client/tsconfig.node.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "composite": true,
4 | "module": "ESNext",
5 | "moduleResolution": "Node",
6 | "allowSyntheticDefaultImports": true
7 | },
8 | "include": ["vite.config.ts"]
9 | }
10 |
--------------------------------------------------------------------------------
/apps/client/vite.config.ts:
--------------------------------------------------------------------------------
1 | import react from '@vitejs/plugin-react'
2 | import { defineConfig } from 'vite'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | server: {
8 | port: 3000,
9 | strictPort: true,
10 | proxy: {
11 | '/api': {
12 | target: 'http://localhost',
13 | changeOrigin: true
14 | }
15 | }
16 | }
17 | })
18 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "dev": "turbo run dev",
4 | "build": "turbo run build",
5 | "start": "node apps/api/dist/main"
6 | },
7 | "devDependencies": {
8 | "turbo": "^1.8.8"
9 | },
10 | "workspaces": [
11 | "apps/*"
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/turbo.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://turborepo.org/schema.json",
3 | "pipeline": {
4 | "dev": {
5 | "cache": false
6 | },
7 | "build": {
8 | "dependsOn": [
9 | "^build"
10 | ],
11 | "outputs": [
12 | "dist/**"
13 | ]
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------