Skip to content

Ra9huvansh/Valoris-Systems

Repository files navigation

Valoris — Distributed Trade Lifecycle Simulator

A production-grade distributed system that simulates the full lifecycle of a financial trade — from order submission through compliance, execution, confirmation, settlement, and reporting. Built with Spring Boot microservices, Apache Kafka, and a React dashboard.


Screenshots

Landing

Pipeline

Submit Trade

Analytics


Architecture

                          ┌─────────────────────────────────┐
                          │         React Dashboard         │
                          │    (Vite + Recharts + nginx)    │
                          └───────────────┬─────────────────┘
                                          │ REST API calls
          ┌───────────────────────────────▼───────────────────────────────┐
          │                      FIX Gateway Service                      │
          │              POST /api/trades → Kafka: trades.incoming        │
          └───────────────────────────────┬───────────────────────────────┘
                                          │ Kafka
          ┌───────────────────────────────▼───────────────────────────────┐
          │                    Compliance Service                         │
          │         Checks counterparty, risk limits, instruments         │
          │         PASS → trades.validated  |  FAIL → trades.rejected    │
          └────────────────┬──────────────────────────────────────────────┘
                           │ Redis (rules cache)           │ Kafka
          ┌────────────────▼──────────────┐                │
          │    PostgreSQL (compliance_db) │                │
          └───────────────────────────────┘                │
                                          ┌────────────────▼──────────────┐
                                          │      Execution Service        │
                                          │  Prices trade, assigns venue  │
                                          │  → Kafka: trades.executed     │
                                          └────────────────┬──────────────┘
                                                           │ Kafka
                                          ┌────────────────▼──────────────┐
                                          │    Confirmation Service       │
                                          │  Counterparty confirms price  │
                                          │  (5% chance of mismatch)      │
                                          │  → Kafka: trades.confirmed    │
                                          └────────────────┬──────────────┘
                                                           │ Kafka
                                          ┌────────────────▼──────────────┐
                                          │     Settlement Service        │
                                          │  T+2 settlement scheduling    │
                                          │  Position netting             │
                                          │  → Kafka: trades.settled      │
                                          └────────────────┬──────────────┘
                                                           │ Kafka
                                          ┌────────────────▼──────────────┐
                                          │     Reporting Service         │
                                          │  Generates trade reports      |
                                          │  Analytics by instrument,     │
                                          │  counterparty, trader         │
                                          └───────────────────────────────┘

Trade Lifecycle

  1. Submit — Trader submits a trade via the dashboard or REST API. FIX Gateway assigns a UUID, persists a raw record, and publishes to trades.incoming.
  2. Compliance — Compliance Service checks the trade against counterparty approval lists, risk limits (notional cap), and allowed instruments. Passes or rejects; either way publishes to Kafka.
  3. Execution — Execution Service prices the trade using a market price simulator (±0.5% spread), assigns a venue (DIFC, DFM, NASDAQ Dubai), and publishes to trades.executed.
  4. Confirmation — Confirmation Service simulates counterparty confirmation. 95% confirm at execution price; 5% introduce a ±2% price mismatch. Status is either CONFIRMED or MISMATCHED.
  5. Settlement — Settlement Service schedules the trade for T+2 (skipping weekends). A scheduler runs every 60 seconds, marks due trades as SETTLED, and updates net positions per counterparty/instrument pair.
  6. Reporting — Reporting Service persists a final trade report for analytics queries.

Services

Service Port Description
fix-gateway-service 8081 Trade ingestion — REST API to Kafka
compliance-service 8082 Rules engine — counterparty, risk, instruments
execution-service 8083 Market pricing and venue assignment
confirmation-service 8084 Counterparty confirmation simulation
settlement-service 8085 T+2 scheduling and position netting
reporting-service 8086 Trade reports and analytics
valoris-dashboard 5173 React frontend

Tech Stack

Backend

  • Java 17, Spring Boot 3
  • Apache Kafka (event streaming between all services)
  • PostgreSQL (one database per service — strict service isolation)
  • Redis (compliance rules cache in compliance-service)
  • Spring Data JPA, Hibernate
  • Lombok

Frontend

  • React 18, Vite
  • Recharts (bar, pie, area charts)
  • React Router v6
  • nginx (production serve + SPA routing)

Infrastructure

  • Docker + Docker Compose (full stack with one command)
  • Apache Zookeeper

Running the Stack

Prerequisites

  • Docker Desktop (with at least 4 GB RAM allocated)
  • Docker Compose v2

Start everything

cd /path/to/Valoris

# First run — builds all images and starts containers
docker compose up --build

# Subsequent runs
docker compose up

All 11 containers start: PostgreSQL, Redis, Zookeeper, Kafka, 6 Spring Boot services, and the dashboard.

Dashboard: http://localhost:5173

Stop everything

docker compose down

Wipe all data (including database volumes)

docker compose down -v

API Reference

FIX Gateway — Submit a Trade

POST http://localhost:8081/api/trades
Content-Type: application/json
{
  "instrument": "US0378331005",
  "side": "BUY",
  "quantity": 500,
  "counterpartyId": "CP-001",
  "currency": "USD",
  "notionalValue": 94750.00,
  "submittedBy": "trader.dubai"
}

Response:

{
  "tradeId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
  "status": "SUBMITTED",
  "message": "Trade accepted and published to compliance pipeline"
}

Compliance Service

Endpoint Description
GET :8082/api/compliance/{tradeId} Compliance result for a trade
GET :8082/api/rules/counterparties Approved counterparty list
GET :8082/api/rules/instruments Allowed instruments
GET :8082/api/rules/risk-limits Notional risk limits per counterparty

Execution Service

Endpoint Description
GET :8083/api/executions All executions
GET :8083/api/executions/{tradeId} Execution detail

Confirmation Service

Endpoint Description
GET :8084/api/confirmations All confirmations
GET :8084/api/confirmations/{tradeId} Confirmation detail
GET :8084/api/confirmations/mismatched Trades with price mismatches

Settlement Service

Endpoint Description
GET :8085/api/settlements All settlements
GET :8085/api/settlements/{tradeId} Settlement detail
GET :8085/api/settlements/pending Trades awaiting settlement
GET :8085/api/positions All net positions
GET :8085/api/positions/{counterpartyId} Positions for a counterparty

Reporting Service

Endpoint Description
GET :8086/api/reports All trade reports
GET :8086/api/reports/{tradeId} Report for a specific trade
GET :8086/api/reports/by-instrument/{isin} Trades by instrument
GET :8086/api/reports/by-counterparty/{id} Trades by counterparty
GET :8086/api/reports/by-trader/{name} Trades by trader
GET :8086/api/analytics/volume-by-instrument Volume analytics by ISIN
GET :8086/api/analytics/volume-by-counterparty Volume analytics by counterparty
GET :8086/api/analytics/summary Overall settled/pending summary

Supported Instruments (ISINs)

ISIN Description
US0378331005 Apple Inc.
US5949181045 Microsoft Corp.
US02079K3059 Alphabet Inc.
US4592001014 IBM Corp.
US912828ZL9 US Treasury 2Y
US9128284Y00 US Treasury 5Y
XS2314659447 Emirates NBD Bond
AEA007601011 Emaar Properties
AEA000301011 First Abu Dhabi Bank

Compliance Rules (Seeded on Startup)

Approved Counterparties: CP-001, CP-002, CP-003, CP-004, CP-005

Risk Limits (notional cap):

  • CP-001: $10,000,000
  • CP-002: $5,000,000
  • CP-003: $8,000,000
  • CP-004: $3,000,000
  • CP-005: $12,000,000

Making Code Changes After Docker Setup

When you change code and want to see it reflected in Docker:

# Rebuild only the changed service (e.g., settlement-service)
docker compose up --build settlement-service

# Rebuild everything
docker compose up --build

Schema changes (schema.sql) require wiping the volume for that service's database, since CREATE TABLE IF NOT EXISTS won't re-run on an existing table:

docker compose down -v   # drops all volumes
docker compose up --build

Project Structure

Valoris/
├── docker-compose.yml          # Full stack orchestration
├── docker/
│   └── init-db.sql             # Creates all 6 PostgreSQL databases
├── fix-gateway-service/        # Port 8081 — trade ingestion
├── compliance-service/         # Port 8082 — rules engine + Redis cache
├── execution-service/          # Port 8083 — market pricing
├── confirmation-service/       # Port 8084 — counterparty confirmation
├── settlement-service/         # Port 8085 — T+2 settlement + positions
├── reporting-service/          # Port 8086 — analytics
└── valoris-dashboard/          # Port 5173 — React frontend
    ├── nginx.conf
    └── Dockerfile

Each service follows the same internal layout:

service/
├── src/main/java/com/valoris/<service>/
│   ├── controller/     REST endpoints
│   ├── service/        Business logic
│   ├── consumer/       Kafka listeners
│   ├── producer/       Kafka publishers
│   ├── repository/     Spring Data JPA
│   ├── model/          JPA entities
│   ├── event/          Kafka event DTOs
│   └── dto/            Request/response objects
└── src/main/resources/
    ├── application.yml
    └── db/
        ├── schema.sql  Table definitions + indexes
        └── data.sql    (compliance-service only — seeds rules)

Kafka Topics

Topic Producer Consumer
trades.incoming fix-gateway-service compliance-service
trades.validated compliance-service execution-service
trades.rejected compliance-service
trades.executed execution-service confirmation-service
trades.confirmed confirmation-service settlement-service
trades.settled settlement-service (scheduler) reporting-service

About

A distributed trade lifecycle simulator built with Spring Boot microservices and Apache Kafka, modeling the full pipeline from compliance through settlement. Features event-driven architecture, PostgreSQL per service, Redis caching, and a React dashboard.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors