j-mendez / polyglot-starter

a deno polyglot persistence starter - (mongodb, redis, meilisearch)

Home Page:https://cutetaco.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deno-rest-starter

j-mendez Deploy to Amazon ECS Maintainability

a production ready deno starter focused on making tacos. Setup with redis, mongodb, and meilisearch model syncing.

Getting Started

You can start the application locally or using docker. The simplest option to get started is using docker and compose.

Docker

make sure to have docker and compose installed. The docker image is using a slim alpine build. On intial container start, its safe to ignore the log output /usr/lib/libstdc++.so.6 on the alpine image.

  1. docker-compose up

Local

Make sure to have deno installed. If your using mac you can use brew install deno. If your starting the application locally make sure to have mongodb running for database operations. You need to add a .env file and add DB_URL=$URL_DB_URL, replace $URL_DB_URL with your database endpoint.

  1. deno run --allow-read --allow-env --allow-net main.ts

Pages

Pages are views that are server side rendered.

url params models description
/pages/orders no Orders Get a list of recent orders from redis
/pages/order no Orders Find order from redis or meilisearch
/pages/create no Orders Create a new random order

Validation

REST validation is done through validator-middleware.

Middlewares

below are a list of custom middlewares in registration order.

  1. rate-limiting
  2. body-parser
  3. errors
  4. redirect
  5. validator
  6. 404

Databases

Below are a list of databases used. Mongodb is one of the databases used in the application. If your using docker and need an admin tool navigate to localhost:8081. We use meilisearch for the search server.

  1. redis
  2. mongo
  3. meilisearch

Testing

The app is setup with assertion testing that handles redirection to valid responses for a rest api. When building new features handle the validation through assertions inside the file.

To run unit test|e2e|intg run deno test --allow-read.

For integration test run ./integrations/run.sh.

Benchmarks

The benchmarks are located in the benchmarks directory. On each suite the rate limiting middleware is disabled. Please do not run in production since this will adjust the runtime of your server. Read benchmarks-docs for more information on the type of test, how to, average, and etc.

Env

Environmental variables are handled through .env files. For an example look at the usage below. Check out .env.defaults to see the full list.

PORT=8000
MONGO_DB_PORT=27017
MONGO_DB_NAME=taco-rocket
MONGO_DB_URL=mongodb://mongodb:27017/?compressors=zlib&gssapiServiceName=mongodb
MONGO_DB_RETRY_TIMOUT=15000
MEILISEARCH_DB_API_KEY=masterKey
REDIS_DB_URL=redis
SYSTEM_ADMIN_PASSWORD=password

Auto-Loader

All routers in the routes folder are autoloaded into the application. Simply export as a named export called router.

Fixtures

To get started with testing the api you can use the fixtures inside the project. For more information read fixtures-doc

Web Assembly

Compiling the taco creator visual is done with web assembly. To build the binary run ./assembly/build.sh which outputs the file into the src/assets/static folder. Make sure to have AssembyScript installed locally.

./assembly/build.sh

Deploying

Deployment is done using ECS for clustering, security groups, load balancing, logging, volumes, and elastic scaling. The docker image used for the api is at image

About

This apps main goal is for CRUD, architecture, and security. Since security is a core focus for the application we are using Deno for the backend along with oak as a middleware framework ("express like"). When you post an order, if the option is not a part of the ingredient list the order will be rejected with output of valid options. The ingredient list is in memory using enum. If we want to add the ability to add to the ingredients list we can either mutate the enum at runtime or use the database with a seed step to generate the intial ingredients based off the enums. For now neither was done and the option to add a new ingredient is set by bypassing the available options through the customIngredients property in the order item. For an example checkout custom-order-fixture. Rate limiting is added as a security feature to protect against DDOS. The current rate is set to 2 request per 3 seconds, to adjust the middleware go to Rate Limiting.

About

a deno polyglot persistence starter - (mongodb, redis, meilisearch)

https://cutetaco.com

License:MIT License


Languages

Language:TypeScript 91.0%Language:Shell 8.5%Language:Dockerfile 0.5%