Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/web2solutions/arithmetic-calculator-api
REST API built Serverless, Typescript, Node, MongoDB, Redis, Jest, AWS Lambda, Docker, etc
https://github.com/web2solutions/arithmetic-calculator-api
aws aws-lambda javascript jest mongodb nodejs serverless serverless-framework tdd typescript
Last synced: 10 days ago
JSON representation
REST API built Serverless, Typescript, Node, MongoDB, Redis, Jest, AWS Lambda, Docker, etc
- Host: GitHub
- URL: https://github.com/web2solutions/arithmetic-calculator-api
- Owner: web2solutions
- Created: 2023-06-27T02:32:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-16T12:27:57.000Z (11 months ago)
- Last Synced: 2024-12-09T18:15:05.754Z (2 months ago)
- Topics: aws, aws-lambda, javascript, jest, mongodb, nodejs, serverless, serverless-framework, tdd, typescript
- Language: TypeScript
- Homepage:
- Size: 2.29 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Arithmetic Calculator API
This is a simple REST API built as coding challenge made for [TrueNorth](https://www.truenorth.co/).
See the [requirement's list](./TrueNorth_LoanPro_Coding_Challenge.pdf).
`CircleCI status:`
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/web2solutions/arithmetic-calculator-api/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/web2solutions/arithmetic-calculator-api/tree/main) main
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/web2solutions/arithmetic-calculator-api/tree/dev.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/web2solutions/arithmetic-calculator-api/tree/dev) dev
`Coverage`
[![codecov](https://codecov.io/gh/web2solutions/arithmetic-calculator-api/branch/main/graphs/sunburst.svg?token=MC5LUHIUGS)](https://codecov.io/web2solutions/arithmetic-calculator-api)
## Stack
* Node.js
* TypeScript
* MongoDB and Mongo Atlas as Database
* Redis and Redis Labs as Cache layer
* Jest
* AWS lambda
* Eslint
* Docker
* serverless and serverless-offline## Preparing the development environment using your current NodeJS installation
You need to install the project first:
```bash
npm install
```Before running the API, you must have Mongo and Redis installed first.
You can manually install them, or, you can use docker to install it by running:
```bash
npm run docker:compose:daemon
```### Testing using local Mongo and Redis services
You probably want to run the current test suite implementation:
```bash
npm test:dev
```### Running the application on local environment
`It is recommended to set the NODE_ENV env var value to 'dev'`
```bash
export NODE_ENV=dev
```Add some users and operations to the database:
```bash
npm run data:seed:dev
```An then you can start the dev environment by running:
```bash
npm run local:start:dev
```You can do login as admin user through the API by using curl:
```bash
curl -X POST http://localhost:3000/dev/users/login -H "Content-Type: application/json" -d '{"username": "[email protected]", "password": "123456"}'
```## Managing Mongo and Redis using Docker
```bash
npm run docker:compose:daemon
````Stop Docker environment`
```bash
npm run docker:stop
````Restart Docker environment`
```bash
npm run docker:restart
npm run docker:clean
````Clean Docker environment`
```bash
npm run docker:clean
```## Testing on CI
When running on CI, the API connects to Mongo Atlas and Redis Labs.
Please make sure you have the proper accounts.
You can create for free, both accounts at https://redis.com/try-free/ and https://www.mongodb.com/cloud/atlas/register .
Setup the following env vars on CI platform:
```bash
NODE_ENV="ci"
CODECOV_TOKEN="xxxxxxx" # for codecov service
TOKEN_KEY="mysecret" # for jwt tokenREDIS_HOST_LABS="redis-16050.c10.us-east-1-2.ec2.cloud.redislabs.com"
REDIS_PASSWORD_LABS="........"
REDIS_PORT_LABS=16050MONGO_ATLAS_URL="mongodb+srv://username:[email protected]/?retryWrites=true&w=majority"
MONGO_DATABASE="arithmetic_calculator_api"
```Run the default `npm test command` to run the test suite for CI.
```bash
npm test
```## Deploy
### Environment Config
By default the application will assume the following stage names and config files:
* test
* prod
* stgEach one of those will required a related config file:
* ./config/.env.test
* ./config/.env.prod
* ./config/.env.stgUse the following template:
```bash
TOKEN_KEY=mysecretREDIS_HOST_LABS="redis-16050.c10.us-east-1-2.ec2.cloud.redislabs.com"
REDIS_PASSWORD_LABS="password"
REDIS_PORT_LABS=16050MONGO_ATLAS_URL="mongodb+srv://username:[email protected]/?retryWrites=true&w=majority"
MONGO_DATABASE="arithmetic_calculator_api"
```### Deploy on AWS, simply run
```bash
$ npm run deploy# or
$ serverless deploy
```## Usage
send an HTTP request directly to the endpoint using a tool like curl
```bash
curl https://je6x0x8fa6.execute-api.us-east-2.amazonaws.com/test/users
```## Scaling
By default, AWS Lambda limits the total concurrent executions across all functions within a given region to 1000. The default limit is a safety limit that protects you from costs due to potential runaway or recursive functions during initial development and testing. To increase this limit above the default, follow the steps in [To request a limit increase for concurrent executions](http://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html#increase-concurrent-executions-limit).
## Project Tech Debits
1. Improve code coverage
2. Implement test suite for unit testing.
3. Implement test suite for e2e testing.
4. Adopt the Data Repository Pattern.
5. 100% Ensure the SOLID principles.
6. Implement API documentation - swagger OAS.
7. APM with datadog - custom error classes in 2 levels: service and controller