cosainto

Cosainto

Cosainto is a web application platform for score credit card transactions based on risk as well as to track and perform manual investigations against transactions. The funcitonality of the application is split between user-facing functionality and admin-facing functionality.

Users can:

Admins can:

Typical User Flow

How the Model Runs Inside the Web Application

For an overview of the model, see the graphic below. Each of these steps is explained in further detail below the graphic.

An overview of the Cosainto Model

The individual steps in the model are as follows:

User uploads their data

A user clicks the ‘Upload’ button and selects a CSV or XLSX file from their computer. This file is uploaded into temporary storage so that the various pieces of the model can read it.

Python Script

Cosainto has provided a python script for cleaning/normalizing the data imported from different payment providers that also helps deal with various edge cases like empty data rows/columns. Once the uploaded data file has been moved into its temporary location, the python script is triggered. This script looks at each piece of data in the provided file and converts them to SQL queries that can then be imported into our model database.

Data import to MySQL

Now that the data is normalized and in the form of MySQL statements, it is imported into a temmporary data table in a MySQL database that has been set up for the purpose of running the model.

Run the model

After the transactions are imported to MySQL, the Cosainto provided model (in the form of MySQL commands) is run against this newly-imported data. The result of this should be a MySQL table in the temporary database containing a list of the risk scores for each transaction.

MySQL -> Laravel

These risk scores and risk reasons from the model are mapped back to the other transaction data that Laravel will store and each transaction is now saved in the Laravel database so that the user can see these transactions in their dashboard as well as trigger manual reviews against them and upload additional investigation documentation.

Redirect

Once the import process is complete and all the transactions are successfully stored in Laravel, the user is redirected to their dashboard, where they can see the transactions that have resulted from their data import and the run of the model.

To update the model, modify the data-ingestion/ingest.sql or the data-investion/ingest.py file. This can be done in Github and all modifications will be auto-deployed to the staging server 1-2 minutes after commit.

Updating the model

The model can be updated by checking in changes to the MySQL and/or Python scripts and pushing them to Github. As detailed below, and commit to the master branch that is pushed to Github will be automatically deployed. There are some important considerations for each of these file types that will keep the application working properly after every model update.

Python

FileType = str.rsplit(file_name,’.’,1)[1]

  - At the very end of the file, the script should print `success`. This will never be output to the user, but tells Laravel that the Python script ran successfully and the model process should be allowed to continue.

## MySQL
  - Make sure all `drop table` statements are `drop table if exists`. This will ensure if the database is altered or we decide to start cleaning up tables after model runs in the future there aren't fatal errors from dropping a table that doesn't exist.

# Deploy
All commits to the `master` branch are auto-deployed to staging ([https://cosainto.ap.dev](https://cosainto.ap.dev)) using Github Actions.

- [Local Environment](#markdown-header-local-environment)
- [Production Environment](#markdown-header-production-environment)
### Local Environment
##### System requirement
- Use [Laravel homestead](https://laravel.com/docs/8.x/homestead) OR [Laravel valet](https://laravel.com/docs/8.x/valet) for development environment.
##### Project installation
- Clone project from git repository
```sh
       $ git clone https://github.com/cosainto/cosainto.git [folder-name]
       $ cd [folder-name]
       $ git checkout dev-ms-develop
Database connection

Production Environment

System requirements
Database connection
        DB_CONNECTION=mysql
        DB_HOST=127.0.0.1
        DB_PORT=3306
        DB_DATABASE=cosainto
        DB_USERNAME=root
        DB_PASSWORD=secret