Bran18/backend-SafeTrust

SafeTrust is a decentralized P2P escrow platform built on Stellar securing deposits for hotels, vacation rentals, and tourism bookings without intermediaries.

β˜… 0Forks 0GitHub β†—Compare

README

CodeRabbit Pull Request Reviews

SafeTrust Description:

SafeTrust is a decentralized platform designed to revolutionize P2P transactions, providing secure deposits and payments powered by blockchain and trustless technologies. 🌐✨ Experience transparency and reliability in every cryptocurrency transaction. πŸ’ΈπŸ”’


πŸ“‹ Getting Started

Prerequisites

Tool Version Notes
Docker & Docker Compose β‰₯ 24 Required
Hasura CLI β‰₯ 2.x Required for migrations & seeds
curl any Used by health-check loop

Windows users: Run bin/dc_prep and bin/dc_console inside WSL (Ubuntu) or Git Bash, as they are Bash scripts targeting a Linux container environment.


πŸš€ bin/dc_prep β€” One-Command Setup

bin/dc_prep is the single entry point to bootstrap the entire backend. It starts all containers, deploys Hasura metadata for every tenant, applies database migrations, and seeds initial data β€” in the correct order.

Quick start

cp .env.example .env   # fill in your values first
bin/dc_prep            # boots everything

Once it completes, open the Hasura console in a separate terminal:

bin/dc_console

What bin/dc_prep does (in order)

Step Action
1 Start postgres, graphql-engine, and webhook containers via Docker Compose
2 Poll GET /healthz until Hasura is ready (up to 3 min)
3 Build and deploy tenant metadata for all tenants (metadata/setup-tenant.sh)
4 Apply all database migrations (hasura migrate apply) per tenant
5 Reload Hasura metadata
6 Apply seed data (hasura seed apply) per tenant

Targeting specific tenants

By default, bin/dc_prep deploys all tenants (safetrust and hotel_industry). You can pass tenant names as arguments to limit the scope:

# Deploy all tenants (default)
bin/dc_prep

# Deploy a single tenant
bin/dc_prep safetrust

# Deploy multiple specific tenants
bin/dc_prep safetrust hotel_industry

Environment variables

Copy .env.example to .env and fill in the required values before running bin/dc_prep:

POSTGRES_PASSWORD=your_postgres_password

# Must be valid JSON with a minimum 32-character key for HS256
HASURA_GRAPHQL_JWT_SECRET={"type":"HS256","key":"replace-with-min-32-char-secret-here"}

HASURA_EVENT_SECRET=your_event_secret

⚠️ HASURA_GRAPHQL_JWT_SECRET must be valid JSON and the key must be at least 32 characters for HS256. The script will fail at startup if this is malformed.


πŸ—‚οΈ Metadata Architecture

The metadata/ folder contains the Hasura GraphQL Engine configuration per tenant.

backend/
└── metadata/
    β”œβ”€β”€ base/
    β”‚   β”œβ”€β”€ actions.graphql
    β”‚   β”œβ”€β”€ actions.yaml
    β”‚   β”œβ”€β”€ allow_list.yaml
    β”‚   β”œβ”€β”€ api_limits.yaml
    β”‚   β”œβ”€β”€ backend_configs.yaml
    β”‚   β”œβ”€β”€ cron_triggers.yaml
    β”‚   β”œβ”€β”€ graphql_schema_introspection.yaml
    β”‚   β”œβ”€β”€ inherited_roles.yaml
    β”‚   β”œβ”€β”€ metrics_config.yaml
    β”‚   β”œβ”€β”€ network.yaml
    β”‚   β”œβ”€β”€ opentelemetry.yaml
    β”‚   β”œβ”€β”€ query_collections.yaml
    β”‚   β”œβ”€β”€ remote_schemas.yaml
    β”‚   β”œβ”€β”€ rest_endpoints.yaml
    β”‚   └── version.yaml
    β”œβ”€β”€ build/
    β”‚   └── tenant_a/
    β”‚   └── tenant_b/
    β”‚   └── ...
    β”œβ”€β”€ tenants/
    β”‚   β”œβ”€β”€ safetrust/
    β”‚   β”‚   β”œβ”€β”€ databases/
    β”‚   β”‚   β”œβ”€β”€ tables/
    β”‚   β”‚   β”œβ”€β”€ functions/
    β”‚   β”‚   └── databases.yaml
    β”‚   └── hotel_industry/
    β”‚       β”œβ”€β”€ databases/
    β”‚       β”œβ”€β”€ tables/
    β”‚       β”œβ”€β”€ functions/
    β”‚       └── databases.yaml
    β”œβ”€β”€ build-metadata.sh
    β”œβ”€β”€ deploy-tenant.sh
    └── setup-tenant.sh

Folder guide:

  • base/ β€” Hasura base configuration and GraphQL dependencies shared across all tenants
  • build/ β€” Generated output: tenants merged with base dependencies, ready to deploy
  • tenants/ β€” Tenant-specific database files, tables, functions, relations, and triggers
  • build-metadata.sh β€” Prepares a tenant by merging it with base configurations
  • deploy-tenant.sh β€” Deploys a built tenant to Hasura (tracks tables and relationships)
  • setup-tenant.sh β€” Runs both steps above in one command βœ…

πŸ”§ Manual Commands (advanced)

Tip: bin/dc_prep handles all of the following automatically. Use these only when targeting a specific step or tenant in isolation.

Metadata β€” single tenant

cd metadata
./setup-tenant.sh <tenant_name> [--admin-secret SECRET] [--endpoint URL]

Example:

./setup-tenant.sh safetrust --endpoint http://localhost:8080

Default values: --admin-secret myadminsecretkey Β· --endpoint http://localhost:8080

Or step by step:

# Step 1 β€” Build
./build-metadata.sh <tenant_name> --admin-secret myadminsecretkey --endpoint http://localhost:8080

# Step 2 β€” Verify build/ folder contains the correct tenant data

# Step 3 β€” Deploy
./deploy-tenant.sh <tenant_name> --admin-secret myadminsecretkey --endpoint http://localhost:8080

Migrations β€” single tenant

From the project root:

hasura migrate apply \
  --database-name safetrust \
  --endpoint http://localhost:8080 \
  --admin-secret myadminsecretkey

To apply a single migration version:

hasura migrate apply \
  --database-name safetrust \
  --version <timestamp> \
  --type up \
  --endpoint http://localhost:8080 \
  --admin-secret myadminsecretkey

Seeds β€” single tenant

hasura seed apply \
  --database-name safetrust \
  --endpoint http://localhost:8080 \
  --admin-secret myadminsecretkey

πŸ§ͺ Backend Karate Tests

This project uses the Karate framework for API testing. Tests run in a Docker environment.

⛩️ Karate Docs

Running Tests

docker compose -f docker-compose-test.yml run --rm --build karate

This command will:

  1. Build the test container
  2. Start PostgreSQL and Hasura containers
  3. Run all Karate tests
  4. Show test results in the console
  5. Generate HTML reports in target/karate-reports/

Test Reports

After running the tests, find the HTML reports at:

  • Summary: tests/results/karate-summary.html
  • Detailed: tests/results/karate-tags.html

Adding New Tests

  1. Create new .feature files in tests/karate/features/
  2. Follow the Karate DSL syntax
  3. Tests are automatically picked up when running the test command

Configuration

  • Main config: tests/karate/src/test/resources/karate-config.js
  • Database config: docker-compose-test.yml
  • Test environment: Dockerfile.test

Contributors

sotoJ24diegoTech14KevinMB0220emarc99akinteweolisaagbaforBenjtalkshowBosun-Josh121ryzen-xpPatrickKish1Josue19-08dependabot[bot]ShruGideonBatureAbidoyesimzerenzobanegassrobertocarloussublime247Cybermaxi7codebestiarohan911438Guzbyte-techamarjeet015Danielodingzsalazarsebassupreme2580Jopsan-gmzleypnermariocodecrKedwithGod

Issues