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:
For an overview of the model, see the graphic below. Each of these steps is explained in further detail below the graphic.

The individual steps in the model are as follows:
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.
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.
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.
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.
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.
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.
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.
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
$ composer install
# On project root directory make a copy of .env.example with name .env and update all variables according to your server configuration.
$ cp .env.example .env
connection, host, port, database name, username and password in .env configuration.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cosainto
DB_USERNAME=xxxx
DB_PASSWORD=xxxx
$ npm install
# Run all Mix tasks and minify output...
$ npm run dev
$ npm run watch-poll
$ apt-cache search php7.3-extension-name
$ sudo apt-get install php7.3-extension-name
$ sudo service php7.3-fpm restart
$ sudo service nginx restart
$ sudo apt-get install git
$ sudo apt-get install curl
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
$ sudo apt-get install npm
$ git clone https://github.com/cosainto/cosainto.git [folder-name]
$ cd [folder-name]
$ git checkout [latest-branch]
$ composer install
# On project root directory make a copy of .env.example with name .env and update all variables according to your server configuration.
$ cp .env.example .env
connection, host, port, database name, username and password in .env configuration DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cosainto
DB_USERNAME=root
DB_PASSWORD=secret
$ php artisan migrate
# Run all Mix tasks and minify output...
$ npm run production