GithubHelp home page GithubHelp logo

yowidin / biostasis-backend Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomorrowbiostasis/biostasis-backend

0.0 0.0 0.0 1.8 MB

Here you could find the source code for the Biostasis Backend project.

License: GNU Affero General Public License v3.0

Shell 0.07% TypeScript 99.77% Dockerfile 0.16%

biostasis-backend's Introduction

Biostasis-Backend:

biostasis-backend-repo-header.png

license docker build node

windows os mac os Linux os

Table of content:

Before You Start:

  • Read our contribution guidance if you did not already to gain better understanding on how to be part of biostasis community.
  • Please make sure to visit the Biostasis-Cloud-infrastructure and create your own cloud and external services. Otherwise, you can't run the application properly (you need your own .env credentials).

Introduction:

The following document contains documentation for the backend part of the Biostasis application. You can find here overall information about how the backend works, how to set it for development/production purposes, and a deep engineering analysis of internal app processes.

Tech Stack:

TypeScript Node.js Express nest.js MySQL typeorm redis Docker

The Biostasis application uses modern programming technologies which allow for building maintainable and versatile software. Node.js, Express.js, and NestJs frameworks were used with TypeScript as the programing language due to the simplicity of provided solutions and easy development processes. To properly handle varying configuration and credentials keys the app uses environment variables.

For data storing purposes the application uses MySQL database in version 8+. From a software perspective, to allow quick data manipulation ORM mechanism has been involved. The app uses TypeORM which is a modern and readable way to handle database queries and mapping objects into db records.

Biostasis backend uses Redis for caching temporary data and queuing long live or postponed processes. Used Redis version: 5.0.7.

Everything is containerized using Docker. Each stage of the app (dev, staging, production) has separated docker definitions. Docker compose files have been written using version 3.4 of the language syntax. The application runs on node.js ver 16.10.0 image.

installation:

  1. Setting up Environment Credentials:

    Copy the .example.env file and paste its context to a new .env file

    OR

    Change the name of the file from .example.env to .env

    fill the file with proper values. You can also use alternative ways to bind environment variables but we recommend using the .env file.

  2. Docker Containerization:

    ⚠️ Make sure to have docker installed on your machine before starting.

    Either run:

    • docker compose -f docker-compose-staging.yaml up --build
      

      This command will build the whole system without installing any dependencies on your machine. it will create a container called biostasisbackendapp which will include 4 services using the docker-compose-staging.yaml file:

      ⚠️ Make sure the values for DB_HOST and REDIS_HOST in .env file are equal to their service name in the container (eg. biostasis_database - biostasis_redis).

      1. biostasis_database: MySQL service will create a database for our application.
      2. biostasis_redis: Redis service will create an in-memory database for fast response.
      3. biostatsis_app: This service will host and install the backend application linked to the MySQL and Redis databases.
      4. biostasis_phpmyadmin: MySQL administration tool to control database. you can access it by visting http://localhost:17009 and to grant access use Username: root Password: root

    • docker compose -f docker-compose-only-db.yml up --build
      

      ⚠️ Make sure you have node.js installed on your machine before you start. And the values for DB_HOST and REDIS_HOST in .env file are localhost to avoid failed connection to the database.

      if you want to have control of application flow you can run MySQL and Redis using docker, then simply run the application by firing below commands:

      1. we use yarn package manager instead of npm.

        npm install --global yarn
        
      2. install all dependencies for the application.

        yarn
        
      3. Build the database schema and tables using typeorm migrations from src/migrations.

        yarn typeorm:run
        
      4. Run the application in the development environment.

        yarn start:dev
        

      Setting the app staging and production stages is the same as for development. You just have to keep in mind to have environment variables up to date and use proper Docker files.

Running Tests:

Please make sure everytime you implement new feature small or big to run tests to be fully sure that your application instance works properly or your changes haven’t broken anything, you can fire unit and integration tests included in the app:

  • Unit tests

    yarn test
    
  • Integration tests:

    ❗ Requires database and redis connection. So, the appropriate docker instance (only db) should be running.

    yarn test:integration
    

Swagger Documentation:

⚠️ If the NODE_ENV variable in .env file is set to production then swagger is not available.

For development and staging purposes to simplify monitoring and manual testing we use swagger documentation. To access swagger documentation simply start the application and go to http://localhost:5000/swagger.

Software Overview:

If you want to get a complete understading about the software architecture of the application and how everything connected from the inside, you can Click Here and visit our documentation built using compodoc.

The application consist of:

  • 10 Modules
  • 24 Controllers
  • 9 Entities
  • 18 Injectables
  • 73 Classes
  • 1 Guard
  • 7 Interfaces

Modules:

Each module has its own responsibilities and logic to handle. Modules can interact with each other e.g. to obtain necessary information or fire some tasks. We can distinguish ten modules in the app:

  • AppModule File: src/app.module.ts main application module.
  • AuthorizationModule File: src/authentication/authenticaiton.module.ts handling auth logic, connection with AWS Cognito.
  • ContactModule File: src/contact/contact.module.ts contact’s API.
  • FileModule File: src/file/file.module.ts uploading and accessing files.
  • MessageModule File: src/message/message.module.ts sending email messages and sms 'REST API' endpoints.
  • NotificationModule File: src/notification/notification.module.ts low level logic of handling all types of notifications (including push notifications).
  • QueueModule File: src/queue/queue.module.ts low level logic of handling queue.
  • SchedulerModule File: src/scheduler/scheduler.module.ts scheduling background or postponed tasks.
  • TriggerTimeSlotModule File: src/trigger-time-slot/trigger-time-slot.module.ts off time slots API.
  • UserModule File: src/user/user.module.ts handling all data and processes connected with user and user profile.

Database:

Entities are managed by TypeORM. Each entity has a repository class which allows it to execute write and read queries to the database. List of app entities:

  • ContactEntity
  • FileCategoryEntity
  • FileEntity
  • PositiveInfoEntity
  • ProfileEntity
  • TimeSlotDayEntity
  • TimeSlotEntity
  • UnconfirmedEmailEntity
  • UserEntity

License:

Licensed under the GNU General Public License v3.0

biostasis-backend's People

Contributors

tomorrowbiostasis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.