-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 39809c6
Showing
117 changed files
with
12,160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@commitlint/config-conventional"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.github | ||
.husky | ||
node_modules | ||
npm-debug.log | ||
tests | ||
**/__tests__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DATABASE_URL=postgresql://user:password@localhost:5432/app | ||
LOG_LEVEL=info | ||
NODE_ENV=development | ||
PORT=3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist/** | ||
/coverage/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"plugins": ["@typescript-eslint"], | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"no-console": "error" | ||
}, | ||
"env": { | ||
"node": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: '.nvmrc' | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Lint | ||
run: npm run lint | ||
|
||
- name: Create .env file | ||
run: cp .env.example .env | ||
|
||
- name: Start functional tests container | ||
run: docker-compose up -d | ||
|
||
- name: Test | ||
run: npm test -- --coverage | ||
|
||
- name: Stop functional tests container | ||
if: always() | ||
run: docker-compose -f "docker-compose.yml" down | ||
|
||
- name: Publish code coverage to Code Climate | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
uses: paambaati/[email protected] | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_REPORTER_ID }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules/ | ||
dist/ | ||
coverage/ | ||
.npm | ||
npm-debug.log* | ||
.env | ||
|
||
# Editor files | ||
.idea/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx --no -- commitlint --edit $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"*.ts": ["prettier --write", "eslint --fix"], | ||
"*": "prettier --write --ignore-unknown" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"printWidth": 120, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"importOrder": ["<THIRD_PARTY_MODULES>", "^[./]"], | ||
"importOrderSeparation": true, | ||
"importOrderSortSpecifiers": true, | ||
"plugins": ["@trivago/prettier-plugin-sort-imports"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM node:20-alpine AS builder | ||
WORKDIR /app | ||
COPY . . | ||
RUN npm pkg delete scripts.prepare | ||
RUN npm install | ||
RUN npm run build | ||
|
||
FROM node:20-alpine | ||
WORKDIR /app | ||
ENV NODE_ENV=production | ||
COPY package*.json ./ | ||
COPY --from=builder ./app/prisma ./ | ||
COPY --from=builder ./app/dist ./dist | ||
RUN npm pkg delete scripts.prepare | ||
RUN npm ci --only=production --quiet | ||
|
||
EXPOSE 3000 | ||
CMD ["node", "./dist/web/api/server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Clean Architecture Template | ||
|
||
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/JamieLivingstone/node-clean-architecture/blob/main/LICENSE) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/f2520d575fe754ae7032/test_coverage)](https://codeclimate.com/github/JamieLivingstone/node-clean-architecture/test_coverage) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/f2520d575fe754ae7032/maintainability)](https://codeclimate.com/github/JamieLivingstone/node-clean-architecture/maintainability) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/JamieLivingstone/node-clean-architecture/badge.svg)](https://snyk.io/test/github/JamieLivingstone/node-clean-architecture) | ||
|
||
A Node template that follows the Clean Architecture principles and encourages established practices. | ||
|
||
## Features | ||
|
||
- TypeScript first | ||
- Dependency injection via Awilix | ||
- CQRS (Command Query Responsibility Segregation) | ||
- Automatic API documentation via Swagger | ||
- Built with scalability and performance in mind by using Fastify (see [benchmarks](https://www.fastify.io/benchmarks)) | ||
- Built in logging with Pino | ||
- Comprehensive testing including unit and functional tests | ||
- Prisma ORM integration | ||
|
||
## Getting Started | ||
|
||
1. Install the latest [Node.js LTS](https://nodejs.org/en/) | ||
2. Install Docker and ensure that it is running | ||
3. Create .env file `cp .env.example .env` | ||
4. Install project dependencies by running `npm install` | ||
5. Start Docker (local Postgres instance) `docker-compose up -d` | ||
6. Create database `npx prisma migrate deploy` | ||
7. Start development server `npm run dev` | ||
8. Navigate to Swagger ([http://localhost:3000/api-docs](http://localhost:3000/api-docs)) | ||
|
||
## Scripts | ||
|
||
**Build production bundle** | ||
|
||
``` | ||
npm run build | ||
``` | ||
|
||
**Lint project (eslint)** | ||
|
||
``` | ||
npm run lint | ||
``` | ||
|
||
**Start development server** | ||
|
||
``` | ||
npm run dev | ||
``` | ||
|
||
**Run all tests** | ||
|
||
``` | ||
npm test | ||
``` | ||
|
||
**Run unit tests** | ||
|
||
``` | ||
npm run test:unit | ||
``` | ||
|
||
**Run functional tests (API tests)** | ||
|
||
``` | ||
npm run test:functional | ||
``` | ||
|
||
## License | ||
|
||
[This project is licensed with the MIT license.](https://github.com/JamieLivingstone/node-clean-architecture/blob/main/LICENSE) | ||
|
||
## Credits | ||
|
||
The project's inspiration is [Jason Taylor's clean architecture template](https://github.com/jasontaylordev/CleanArchitecture) for C#. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.8' | ||
|
||
services: | ||
db: | ||
image: postgres:16-alpine | ||
restart: always | ||
ports: | ||
- '5432:5432' | ||
environment: | ||
POSTGRES_USER: user | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Config } from '@jest/types'; | ||
import dotenv from 'dotenv'; | ||
import { pathsToModuleNameMapper } from 'ts-jest'; | ||
|
||
import { compilerOptions } from './tsconfig.json'; | ||
|
||
dotenv.config(); | ||
|
||
const config: Config.InitialOptions = { | ||
testEnvironment: 'node', | ||
collectCoverageFrom: ['src/**/*.ts', '!src/**/__tests__/*.ts'], | ||
projects: [ | ||
{ | ||
displayName: 'unit-tests', | ||
testMatch: ['<rootDir>/src/**/*.test.ts'], | ||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }), | ||
transform: { | ||
'^.+\\.ts?$': 'ts-jest', | ||
}, | ||
}, | ||
{ | ||
displayName: 'functional-tests', | ||
testMatch: ['<rootDir>/tests/**/*.test.ts'], | ||
testEnvironment: '<rootDir>/prisma/prisma-test-environment.ts', | ||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }), | ||
transform: { | ||
'^.+\\.ts?$': 'ts-jest', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.