Skip to content

CarmineOptions/derisk-research

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DeRisk Starknet

Projects overview

This project consist of a monorepo with components required for the implementation of DeRisk on Starknet. There are several components in this repository, each with its own purpose and functionality. The main components are:

Shared

shared Both projects data_handler, dashboard_app work with the same shared database, which is contained in the shared folder. It also contains all shared modules.

Data Handler

data_handler Data processing and analysis component: Collects data from DeFi, analyzes it, and saves it to the db. It contains Celery tasks to schedule data collection runs. Once the data is collected, it triggers an endpoint on the dashboard_app

Dashboard App

dashboard_app Works as a server for the frontend_dashboard. Generates an analytics dashboard using Streamlit. Contains an API to handle the Telegram webhook and send bot messages. Key Features:

  • Interactive data visualization
  • Protocol statistics monitoring
  • Loan portfolio analysis
  • Real-time data updates

Dashboard Frontend

frontend_dashboard React client app. Uses API if the dashboard_app

Legacy Apps

Legacy apps contain code that has been migrated to the current apps, along with additional code. Explore them in case of a stack issue:

Quick Start Guide

Prerequisites

  • Docker installed on your machine (v19.03+ recommended).
  • Docker Compose installed (v2.0+ recommended).

Data Handler local development

  1. To set up this project run next command for local development in derisk-research directory:

  2. Environment Configuration:

cp apps/data_handler/.env.dev apps/data_handler/.env
  1. Start the Services:
docker-compose -f devops/dev/docker-compose.data-handler.yaml up --build
  1. Stop the Services:
docker-compose -f devops/dev/docker-compose.data-handler.yaml down
  1. To run test cases for this project run next command in derisk-research directory:
make test_data_handler

For detailed documentation, see the Data Handler

Dashboard App local development

  1. To set up this project run next command for local development in derisk-research directory:

  2. Environment Configuration:

cp apps/dashboard_app/.env.dev apps/dashboard_app/.env
  1. Start the Services:
docker-compose -f devops/dev/docker-compose.dashboard-app.yaml up --build
  1. Stop the Services:
docker-compose -f devops/dev/docker-compose.dashboard-app.yaml down

Backend API (FastAPI)

cd apps/dashboard_app
poetry install
cp .env.dev .env  
poetry run uvicorn app.main:app --reload --port 8000

Explore the API will be available at http://localhost:8000/docs.

Frontend App (React + Vite)

Make sure dashboard_app is running!

cd apps/frontend_dashboard
npm install
npm run dev

Navigate to http://localhost:5173 to access the subscription form.

CORS & Proxy

The backend is configured with CORS to allow requests from http://localhost:5173, and the Vite dev server proxies /api to the backend.

Shared package (Common code shared between the components)

  1. How to run test cases for shared package, run next command in root folder:
make test_shared

Running the dashboard frontend with Docker

  1. Naviagte to frontend_dashboard directory:

    cd apps/frontend_dashboard
  2. Build the Docker Image:

    docker build -t frontend_dashboard .

    or on linux

    sudo docker build -t frontend_dashboard .
  3. Run the Docker Container::

    docker run -p 5173:5173 frontend_dashboard

    or on linux

    sudo docker run -p 5173:5173 frontend_dashboard
  4. Access the Application: Open your browser and navigate to http://localhost:5173.

Data migrations with Alembic

In this project is using alembic for data migrations.

Generating Migrations

Navigate to the project folder and generate a new migration using the following command:

  1. Run:
docker compose -f devops/dev/docker-compose.db.yaml up --build
  1. Then:
cd apps/shared
alembic -c alembic.ini revision --autogenerate -m "your message"
  1. ? You may need to set up .env and install missing packages. Check the terminal, as pip-install missing packages

Applying Migrations

After generating new migration, you need to apply it:

alembic -c alembic.ini upgrade head

Rolling Back Migrations

For downgrading migration:

alembic -c alembic.ini downgrade -1

Migration Utility Commands

Useful commands: Purge all celery tasks:

docker compose run --rm celery celery -A celery_conf purge

Purge all celery beat tasks:

docker compose run --rm celery_beat celery -A celery_conf purge

Go to bash

docker compose exec backend bash

#TODO review:

How to run migration command:

  1. Set up .env.dev into derisk-research/apps/data_handler
  2. Go back to derisk-research/apps directory
  3. Then run bash script to migrate:
bash data_handler/migrate.sh

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 130