Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed May 2, 2023
0 parents commit 3446d48
Show file tree
Hide file tree
Showing 102 changed files with 14,385 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
NODE_ENV=dev
SERVER_PORT=4000
POSTGRES_USER=postgres
POSTGRES_PASSWORD=app123456
POSTGRES_DATABASE=languages
POSTGRESQL_DB_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DATABASE}"
MONGO_DB_URL=mongodb://mongodb:27017/languages
GOOGLE_CLIENT_ID=""
JWT_SECRET=""
FRONTED_URL="http://localhost:3000"
39 changes: 39 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
node: true,
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'no-undef': ['error', { 'typeof': true }],
'no-unused-vars': ['error', {'args': 'none'}],
'no-use-before-define': 'error',

'quotes': [2, 'single', { 'avoidEscape': true }],
'semi': ['error', 'always'],
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'no-extra-semi': 'error',

'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{
'allowTemplateLiterals': true
}
],
'@typescript-eslint/no-extra-semi': 'error'
}
};
26 changes: 26 additions & 0 deletions .github/workflows/express.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Express.js Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: '14.x'
- name: Install Dependencies
run: npm ci
- name: Run linter
run: npm run linter
- name: Run format-code
run: npm run format-code
- name: Run tests
run: npm run test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
/dist/
.env
/docker/data
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"printWidth": 120
}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:16

RUN apt-get update && apt-get install -y git

RUN mkdir -p /var/www/html/languages

WORKDIR /var/www/html/languages

COPY package*.json ./

RUN npm install
RUN npm install --global copy

COPY . .

EXPOSE 8000

CMD ["npm", "run", "dev"]
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Typescript-ddd-cqrs backend

## Development

Configuration for development.

### Configuration

1. Copy .env.example to .env and configure it.

2. Execute docker-compose:
```shell script
docker-compose up
```
4. Run migrations:
```shell script
docker-compose run app bash npm run typeorm migration:run
```
5. Create user via google.

### Running

After running docker-compose up the application will be available at https://localhost:4000.

### Migrations

To generate migrations run the next command:
```shell script
npm run typeorm migration:generate migrationName
```

To execute migrations run the next command:
```shell script
npm run typeorm migration:run
```

### Oauth2:

To get a token for testing you should go to https://developers.google.com/oauthplayground and configure it as "Use your own OAuth credentials" after that you should use Google OAuth2 API v2.

## Production

For production run the next command:
```shell script
npm run start
```
36 changes: 36 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3'
services:
app:
image: languages
container_name: languages-container
build:
context: .
restart: on-failure
env_file:
- .env
volumes:
- ./:/var/www/html/languages
ports:
- "4000:${SERVER_PORT}"
depends_on:
- db
- mongodb

db:
image: postgres
environment:
POSTGRES_DB: ${POSTGRES_DATABASE}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- ./docker/data/pgdata:/var/lib/postgresql/data/pgdata
ports:
- "5435:5432"

mongodb:
image: mongo:6-jammy
ports:
- '27017:27017'
volumes:
- ./docker/data/mongodata:/data/db
Empty file added docker/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^@src/(.*)$': '<rootDir>/src/$1',
'^@test/(.*)$': '<rootDir>/test/$1',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};
35 changes: 35 additions & 0 deletions migrations/1682870146619-createInitialTables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateInitialTables1682870146619 implements MigrationInterface {
name = 'CreateInitialTables1682870146619';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "countries" ("id" uuid NOT NULL, "name" character varying NOT NULL, "iso" character varying NOT NULL, "languages" text NOT NULL DEFAULT '[]', CONSTRAINT "PK_b2d7006793e8697ab3ae2deff18" PRIMARY KEY ("id"))`
);
await queryRunner.query(
`CREATE TABLE "expressions" ("id" uuid NOT NULL, "language_id" character varying NOT NULL, "country_id" character varying NOT NULL, "terms" text NOT NULL DEFAULT '[]', "userId" uuid, CONSTRAINT "PK_e75aa87c24b37cd86f6c8a668c9" PRIMARY KEY ("id"))`
);
await queryRunner.query(
`CREATE TABLE "users" ("id" uuid NOT NULL, "name" character varying NOT NULL, "provider" character varying NOT NULL, "email" character varying NOT NULL, "photo" character varying NOT NULL, CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))`
);
await queryRunner.query(
`CREATE TABLE "words" ("id" uuid NOT NULL, "language_id" character varying NOT NULL, "country_id" character varying NOT NULL, "terms" text NOT NULL DEFAULT '[]', "userId" uuid, CONSTRAINT "PK_feaf97accb69a7f355fa6f58a3d" PRIMARY KEY ("id"))`
);
await queryRunner.query(
`ALTER TABLE "expressions" ADD CONSTRAINT "FK_d6fc57a835713d8565153ff1807" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "words" ADD CONSTRAINT "FK_3f75018aa783695bfd293f0dc26" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "words" DROP CONSTRAINT "FK_3f75018aa783695bfd293f0dc26"`);
await queryRunner.query(`ALTER TABLE "expressions" DROP CONSTRAINT "FK_d6fc57a835713d8565153ff1807"`);
await queryRunner.query(`DROP TABLE "words"`);
await queryRunner.query(`DROP TABLE "users"`);
await queryRunner.query(`DROP TABLE "expressions"`);
await queryRunner.query(`DROP TABLE "countries"`);
}
}
Loading

0 comments on commit 3446d48

Please sign in to comment.