Home

Awesome

121 platform

121 is an open source platform for Cash based Aid built with Digital Account & Local/Global Financial service partners. -- Learn more about the platform: https://www.121.global/


License Releases


Status

See: status.121.global

Tests Status

Static analysis, formatting, code-style, functionality, integration, etc:

See also: Testing


Documentation

The documentation of the 121 platform can be found on the Wiki of this repository on GitHub: https://github.com/global-121/121-platform/wiki


Getting Started

Set up a local development-environment

Set up repository and code

With these tools in place you can checkout the code and start setting up:

git clone https://github.com/global-121/121-platform.git

Navigate to the root folder of this repository:

cd 121-platform

Then install the required version of Node.js and npm:


Now, make sure to run the following in the root folder to install the necessary pre-hooks:

npm install

Setup Services

Switch to the repository folder

cd services/

Copy the centralized .env file

cp .env.example .env

Environment variables are explained in the comments of the .env.example-file, some already have a value that is safe/good to use for development, some need to be unique/specific for your environment.

Some variables are for credentials or tokens to access third-party services.

Start Services

To start all services, after setup, from the root of this repository, run:

npm run start:services

To see the status/logs of all/a specific Docker-container(s), run: (Where <container-name> is optional; See container-names in docker-compose.yml).

npm run logs:services <container-name>

To verify the successful installation and setup of services, access their Swagger UI:


Setup Interfaces

Install dependencies for the portal, run:

npm run install:portal

Also, make sure to create an env file for each interface. For example:

cp interfaces/Portal/.env.example interfaces/Portal/.env

Start Interfaces

To start the portal, from the root of this repository, run:

npm run start:portal

When started, the portal will be available via:


Local development

When you use VS Code, you can start multiple editor-windows at once, from the root of this repository, run:

npm run code:all

To start an individual interface/service in VS Code:

Process for implementing data-model changes

When making changes to the data-model of the 121-service (creating/editing any \*.entity.ts files), you need to create a migration script to take these changes into affect.

The process is:

  1. Make the changes in the \*.entity.ts file

  2. To generate a migration-script run: docker exec 121-service npm run migration:generate src/migration/<descriptive-name-for-migration-script>. This will compare the data-model according to your code with the data-model according to your database, and generate any CREATE, ALTER, etc SQL-statements that are needed to make the database align with code again.

  3. Restart the 121-service through docker restart 121-service: this will always run any new migration-scripts (and thus update the data-model in the database), so in this case the just generated migration-script.

  4. If more changes required, then follow the above process as often as needed.

  5. Do NOT import any files from our code base into your migrations. For example, do NOT import seed JSON files to get data to insert into the database, since the migration may break if ever these seed JSON files change. Instead, "hard code" the needed data in your migration file.

  6. Do NOT change migration files anymore after they have been merged to main, like commenting out parts of it, since there is a high probability this will result in bugs or faulty data on production instances. Instead, create a new migration file. The exception is bug fixing a migration file, for example if a file was imported that causes the migration to fail (see 5 above).

  7. To run this file locally, do: docker exec -it 121-service npm run migration:run

  8. If you want to revert one migration you can run: docker exec -it 121-service npm run migration:revert

  9. If ever running into issues with migrations locally, the reset process is:

    • Delete all tables in the 121-service database schema
    • Restart 121-service container
    • This will now run all migration-scripts, which starts with the InitialMigration-script, which creates all tables
    • (Run seed)
  10. See also TypeORM migration documentation for more info

NOTE: if you're making many data-model changes at once, or are doing a lot of trial and error, there is an alternative option:

  1. In services/121-service/src/ormconfig.ts set synchronize to true and restart 121-service.
  2. This will make sure that any changes you make to \*.entity.ts files are automatically updated in your database tables, which allows for quicker development/testing.
  3. When you're done with all your changes, you will need to revert all changes temporarily to be able to create a migration script. There are multiple ways to do this, for example by stashing all your changes, or working with a new branch, etc. Either way:
    • stashing all your changes (git stash)
    • restart 121-service and wait until the data-model changes are actually reverted again
    • set synchronize back to false and restart 121-service
    • load your stashed changes again (git stash pop)
    • generate migration-script (see above)
    • restart 121-service (like above, to run the new migration-script)

Authentication

All services use JSON Web Token (JWT) to handle authentication. The token should be passed with each request by the browser via an access_token cookie. The JWT authentication middleware handles the validation and authentication of the token.

Adding third party API tokens

All the tokens and access keys for third party APIs should be added on the .env-file and subsequently imported using the environment variables within typescript files.

Recommended code-editor/IDE tools/extensions

To help with some types if files/tasks we've listed them here:

Common problems with Local Environment set-up

Swagger-UI not accessible

If the Swagger-UI is not accessible after installing Docker and setting up the services, you can take the following steps to debug:

  1. docker compose ps to list running containers and their status
  2. docker compose logs -f <container-name> to check their logs/console output (or leave out the <container-name> to get ALL output)

Docker related issues

If there are issues with Docker commands, it could be due to permissions. Prefix your commands with sudo docker....

Database related errors

If the errors are related to not being able to access/connect to the database then reset/recreate the database by:

Upgrade Node.js version

When considering upgrading the (LTS) version of the Node.js runtime, take into account:

Updated/new Node.js dependencies

When new Node.js dependencies are added to a service since it is last build on you local machine, you can:


Testing

When to use an API-test? (back-end + db? only)

Notes

These tests are still expensive (to bootstrap app + database)

Unit Tests

Why?

There are a few reasons why we write unit tests cases:

Maintenance with future changes

How are Unit Tests affected when we make changes within the code in future?

Our testing framework(s)

We are using jasmine for executing unit tests within interfaces and jest within services. However, while writing the unit test cases, the writing style and testing paradigm do not differ since jest is based on jasmine.

Writing tests

See the Guide: Writing tests


Releases

See notable changes and the currently released version on the Releases page.

This project uses the CalVer-format: YY.MM-MICRO.

Release Checklist

This is how we create and publish a new release of the 121-platform. (See the glossary for definitions of some terms.)

Patch/Hotfix Checklist

This follows a similar process to regular release + deployment, with some small changes.

Note: Do not rebase/update the hotfix/v*-branch onto the main-branch until AFTER you have successfully deployed the hotfix to production.
The hotfix branch is created from a "dangling" commit, this makes the GitHub UI confused when you look at a PR between the newly created hotfix-branch and the main-branch. Any conflict warnings shown on GitHub are not relevant for the hotfix-deployment, they'll only need to be addressed to merge the hotfix into the main-branch afterwards.


Deployment

Database

If you deploy the 121-platform to a server for the first time it is recommended to setup a separate Postgres database server. The connection to this database can be made by editing the POSTGRES_* variables in services/.env.

Interfaces

To "test" environment

See: (via GitHub Action(s); i.e. deploy_test_*.yml )

To "staging" and/or "production" environment(s)

See: (via GitHub Action(s); i.e. deploy_staging_*.yml )

Service(s)

To "test" environment

See: (via GitHub Action(s); i.e. deploy_test_service.yml, deploy_test_mock-service.yml )

To "staging" and/or "production" environment(s)

On initial deployment (only)

On next deployments

Glossary

TermDefinition (we use)
versionA name specified in the CalVer-format: YY.MM-MICRO
tagA specific commit or point-in-time on the git-timeline; named after a version, i.e. v22.1.0
releaseA fixed 'state of the code-base', published on GitHub
deploymentAn action performed to get (released) code running on an environment
environmentA machine that can run code (with specified settings); i.e. a service, or your local machine

License

Released under the Apache 2.0 License. See LICENSE.