/auth-api

Primary LanguageTypeScript

๐Ÿ“ Description

Auth REST api using clean architecture

๐Ÿงฐ Installation

Prerequisites

Install yarn packages before continue

yarn

Ask other developers to share .env. For security reasons this file is not versioned.

Whenever a new environment variable is added, it must be also added to the .example.env file to keep everything up to date.

Setting up Docker

  • This is will make a new PostgreSQL running in the standard port 5432
  • Please shutdown any previous conflicting PostgreSQL instances before starting this
docker-compose up -d

Check the database is up

docker logs -f auth_pg

Check that you can log into a database with psql

docker exec -it auth_pg psql -U auth_user auth_db

View tables

\dt

Creating the initial database

Run initial migrations to set up initial database tables

yarn db:sync

Check the result of migrations using psql command-line tool

docker exec -it auth_pg psql -U auth_user auth_db
\d 'auth_db'

โŒจ Development

Running the app

yarn dev

๐Ÿงช Running tests per layer

Core layer

yarn test:core

# with code coverage
yarn test:core:coverage

After executing yarn test:core:coverage, the coverage/ folder will be generated with coverage details

Data layer

Creating tests database only integration tests are supported. Backend is spun up on a special database

Tests use their own database. To create it:

docker exec -it auth_pg psql -U auth_user -c "create database test" auth_db

Once the database is created, run the command below to test the data layer:

yarn test:data

Adding new migrations

You can generate migration files

  1. Update entity source code
  2. You have an up-to-date local development database
# creates a file under src/ports/mikroOrm/migrations/
yarn db:migration:create MigrationName

๐Ÿ“ Lint

Linting codebase

# getting lint issues
yarn lint

# fixing lint issues
yarn lint:fix

๐Ÿ“ฆ Building

Before building application to production, make sure environment variables are applied correctly

Building for production

yarn build

Running on production

yarn start

โœ… TODO

  • add JOI to validate data
  • add tests to ports layer
  • add mikroORM config for tests and disable logging in tests
  • add application logs
  • add way to detect if envs are loaded correctly
  • add swagger
  • add database health check
  • add stress tests
  • add CI
  • add CI security checks
  • add CD
  • add terraform or deploys with docker images
  • add localstack for local development
  • add husky pre-push hook

Observation: Some TODOS are spread across the code and need to be fixed ASAP