Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(backend): migrate to nestjs #68

Merged
merged 10 commits into from
Jun 3, 2024
Next Next commit
chore(backend): initialize the backend project with nestjs
  • Loading branch information
tericcabrel committed May 22, 2024
commit c725544dac19e20a442ff226cbeac0d247ffbb89
14 changes: 14 additions & 0 deletions apps/backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
extends: '../../.eslintrc.json',
ignorePatterns: [
'jest.config.ts',
'.eslintrc.js'
],
parserOptions: {
ecmaVersion: 2023,
sourceType: 'module',
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
},
};
56 changes: 56 additions & 0 deletions apps/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
73 changes: 73 additions & 0 deletions apps/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<p align="center">
<a href="http:https://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http:https://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation

```bash
$ yarn install
```

## Running the app

```bash
# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod
```

## Test

```bash
# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov
```

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](LICENSE).
18 changes: 18 additions & 0 deletions apps/backend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
clearMocks: true,
maxWorkers: 1,
moduleFileExtensions: ['js', 'json', 'ts'],
preset: 'ts-jest',
roots: ['.'],
snapshotFormat: {
printBasicPrototype: false,
},
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|test).[jt]s'],
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
};

export default config;
8 changes: 8 additions & 0 deletions apps/backend/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
39 changes: 39 additions & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@snipcode/backend",
"version": "1.1.0",
"private": true,
"description": "Snipcode core backend",
"main": "dist/index.js",
"license": "AGPL-3.0",
"scripts": {
"build": "nest build",
"clean": "rm -rf .turbo dist build logs",
"dev": "nest start --watch",
"dev:debug": "nest start --debug --watch",
"prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --watch",
"test:coverage": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:it": "jest integration.spec.ts"
},
"dependencies": {
"@nestjs/common": "10.3.8",
"@nestjs/core": "10.3.8",
"@nestjs/platform-express": "10.3.8",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1"
},
"devDependencies": {
"@nestjs/cli": "10.3.2",
"@nestjs/schematics": "10.1.1",
"@nestjs/testing": "10.3.8",
"@types/express": "4.17.21",
"@types/supertest": "6.0.2",
"source-map-support": "0.5.21",
"supertest": "7.0.0",
"ts-loader": "9.5.1",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0"
}
}
23 changes: 23 additions & 0 deletions apps/backend/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Test, TestingModule } from '@nestjs/testing';

import { AppController } from './app.controller';
import { AppService } from './app.service';

describe('AppController', () => {
let appController: AppController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();

appController = app.get<AppController>(AppController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
13 changes: 13 additions & 0 deletions apps/backend/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get } from '@nestjs/common';

import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello();
}
}
11 changes: 11 additions & 0 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
controllers: [AppController],
imports: [],
providers: [AppService],
})
export class AppModule {}
8 changes: 8 additions & 0 deletions apps/backend/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
11 changes: 11 additions & 0 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app.module';

const bootstrap = async () => {
const app = await NestFactory.create(AppModule);

await app.listen(3000);
};

void bootstrap();
22 changes: 22 additions & 0 deletions apps/backend/src/tests/app.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import request from 'supertest';

import { AppModule } from '../app.module';

describe('AppController (e2e)', () => {
let app: INestApplication;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('/ (GET)', () => {
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!');
});
});
8 changes: 8 additions & 0 deletions apps/backend/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"exclude": [
"node_modules",
"dist",
"**/*spec.ts"
]
}
26 changes: 26 additions & 0 deletions apps/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"allowSyntheticDefaultImports": true,
"outDir": "./dist",
"incremental": true,
"composite": true,
"strictNullChecks": true
},
"include": [
"./src/**/*"
],
"exclude": [
"node_modules",
".turbo"
],
"references": [
{
"path": "../../packages/utils"
},
{
"path": "../../packages/logger"
}
]
}
1 change: 1 addition & 0 deletions apps/core/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NODE_ENV=development
APP_VERSION=1.0.0
HOST=http:https://localhost
PORT=7501
ENABLE_INTROSPECTION=true
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snipcode",
"version": "1.0.0",
"license": "MIT",
"license": "AGPL-3.0",
"private": true,
"scripts": {
"build": "turbo run build",
Expand All @@ -14,7 +14,8 @@
"cache:login": "turbo login",
"cache:link": "turbo link",
"cache:disable": "turbo unlink",
"pre-release": "changeset"
"prerelease": "changeset",
"branch:create": "pscale branch create core-db $(git rev-parse --abbrev-ref HEAD)"
},
"workspaces": [
"packages/domain",
Expand All @@ -23,6 +24,7 @@
"packages/logger",
"packages/utils",
"apps/core",
"apps/backend",
"apps/web",
"apps/functions/**"
],
Expand Down Expand Up @@ -63,7 +65,7 @@
"prettier": "3.2.5",
"prisma": "5.11.0",
"ts-jest": "29.1.2",
"turbo": "1.13.0",
"turbo": "1.13.3",
"typescript": "5.4.3"
},
"packageManager": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions packages/domain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"build": "tsc --project tsconfig.prod.json",
"clean": "rm -rf .turbo dist",
"lint": "eslint --fix",
"db:dev:create": "pscale branch create core-db dev",
"db:dev:connect": "pscale connect core-db dev --port 3311",
"db:dev:create": "pscale branch create core-db $(git rev-parse --abbrev-ref HEAD)",
"db:dev:connect": "pscale connect core-db $(git rev-parse --abbrev-ref HEAD) --port 3311",
"db:shadow": "docker run -d --rm -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=snipcode --name snipcode-shadow-db -p 3312:3306 mysql:8.0.34",
"db:shadow:stop": "docker kill snipcode-shadow-db && docker container prune -f",
"db:deploy:create": "pscale deploy-request create core-db dev",
Expand Down
Loading