Architecture
4 microservices, PostgreSQL, ERC-3643 on Polygon, off-chain CLOB matching engine
platform-api
:8081Go / FiberCore business logic — authentication, KYC, business management, tokens, wallets, admin, compliance (PDPL)
trading-server
:8080Go / FiberOrder matching (CLOB), settlement, real-time WebSocket feeds, circuit breakers, price history
blockchain-svc
:8082Go / FiberERC-3643 smart contract operations — deploy, mint, transfer, identity registry, event indexing
web
:3000Next.js 14 / TypeScript / Tailwind4-portal frontend — Investor (teal), Issuer (indigo), Admin (amber), Staff (violet)
Technology Stack
Backend
Go 1.24
Fiber v2
GORM
JWT + bcrypt
AES-256-GCM
Frontend
Next.js 14
TypeScript
Tailwind CSS
Lucide Icons
Radix UI
Database
PostgreSQL 16
52 tables
JSONB columns
Deferrable constraints
Blockchain
Solidity ^0.8.20
ERC-3643 (T-REX)
Hardhat (local)
Polygon Amoy (testnet)
DevOps
alef.sh (unified CLI)
--amoy flag for testnet
Standalone Go builds
514 integration tests
Key Data Flows
Primary Offering (Token Allocation)
Investor subscribes to token offering
Admin confirms payment received
Fiat balance deducted (off-chain)
blockchain-svc: ERC-3643 transfer(treasury → investor)
Wallet balance updated (off-chain cache)
Wallet transaction recorded
Secondary Trading (Buy/Sell)
Investor places order via trading-server
Matching engine matches buy + sell orders
Trade created with pending settlement
Fiat balances adjusted (buyer -, seller +)
blockchain-svc: ERC-3643 transfer(seller → buyer)
Wallet balances synced, tx_hash stored
KYC → On-Chain Identity
User submits KYC application
Admin reviews and approves
kyc_status updated to 'approved'
blockchain-svc: Register address in Identity Registry
User can now hold and transfer tokens on-chain
System Topology
┌─────────────────────┐
│ Web (Next.js) │
│ :3000 │
└──────────┬───────────┘
│ REST / WebSocket
┌─────────────────┼─────────────────┐
│ │ │
┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐
│ platform-api│ │trading-server│ │blockchain-svc│
│ :8081 │ │ :8080 │ │ :8082 │
│ │ │ │ │ │
│ Auth, KYC │ │ CLOB Match │ │ ERC-3643 │
│ Business │ │ Settlement │ │ Deploy/Mint │
│ Tokens │ │ WebSocket │ │ Transfer │
│ Wallet │ │ Price OHLC │ │ Identity │
│ Admin/PDPL │ │ Circuit Brk │ │ Indexer │
└──────┬──────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
▼ ▼ ▼
┌────────────────────────────┐ ┌──────────────┐
│ PostgreSQL │ │ Polygon │
│ 52 tables │ │ ERC-3643 │
│ :5432 │ │ Amoy/Local │
└────────────────────────────┘ └──────────────┘Dual-mode blockchain: local Hardhat for development, Polygon Amoy testnet for staging.
Trade Settlement Flow
Investor places order Matching Engine Settlement
─────────────────── ───────────────── ──────────────
┌──────────────┐ REST ┌──────────────┐
│ Buy / Sell │────────────▶│ CLOB Order │
│ Order │ │ Book │
└──────────────┘ └──────┬───────┘
│ price-time match
▼
┌──────────────┐
│ Trade │
│ Created │
│ (pending) │
└──────┬───────┘
│
┌─────────────┼─────────────┐
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Fiat Transfer │ │ On-Chain │
│ (off-chain) │ │ Transfer │
│ buyer→seller │ │ ERC-3643 │
│ via DB update │ │ seller→buyer │
└──────┬───────┘ └──────┬───────┘
│ │
└────────────┬────────────┘
▼
┌──────────────┐
│ Trade │
│ Settled │
│ (tx_hash) │
└──────────────┘ERC-3643 Contract Architecture
┌──────────────────────────────────────────────────────────────┐
│ SecurityToken (ERC-3643) │
│ │
│ mint() transfer() freeze() batchMint() balanceOf() │
│ │
│ ┌─────────────────────┐ ┌─────────────────────────────┐ │
│ │ ERC-20 Interface │ │ Compliance Module │ │
│ │ (standard methods) │ │ canTransfer() check │ │
│ └─────────────────────┘ └──────────────┬──────────────┘ │
└─────────────────────────────────────────────┼────────────────┘
│ queries
▼
┌──────────────────────────────┐
│ Identity Registry │
│ │
│ registerIdentity(address) │
│ isVerified(address) → bool │
│ removeIdentity(address) │
│ │
│ Only KYC-approved addresses │
│ can hold / transfer tokens │
└──────────────────────────────┘
Flow: transfer(from, to, amount)
1. SecurityToken calls canTransfer()
2. Compliance module queries Identity Registry
3. Both from + to must be verified (KYC approved)
4. If compliant → transfer executes
5. If not → reverts with reasonSecurity & Compliance
Authentication
JWT in HttpOnly cookies
Refresh token rotation
TOTP 2FA (AES-256-GCM encrypted)
Rate-limited auth endpoints
Authorization
4 roles: investor, issuer, admin, staff
23 granular permissions (RBAC)
7 team_role presets
RequirePermission middleware
Security Headers
HSTS, X-Frame-Options
X-Content-Type-Options
Referrer-Policy
CORS restricted to localhost:3000
PDPL Compliance
Consent tracking (4 purposes)
Data subject requests (5 types)
Breach incident management (72hr SLA)
Automated retention & purge