Synapse Core is Phase 1 of the Synapse Bridge ecosystem — a fiat-to-crypto bridging platform built on the Stellar network. This service acts as a callback processor for the Stellar Anchor Platform, receiving webhooks when users deposit fiat currency (e.g., USD) via an anchor, persisting the transaction, and preparing it for downstream processing (swap and cross-chain bridging in later phases).
┌─────────────────────────────────────────────────────────────────┐
│ Synapse Bridge Ecosystem │
│ │
│ Phase 1: Fiat Gateway Phase 2 Phase 3 │
│ ┌──────────────┐ ┌───────────┐ ┌──────────────┐ │
│ │ synapse-core │ ──────► │ Swap │──►│ Cross-Chain │ │
│ │ (this repo) │ │ Engine │ │ Bridge │ │
│ └──────────────┘ └───────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
┌──────────────────────────┐
┌──────┐ Deposits Fiat ┌──────────┤ Stellar Anchor Platform │
│ User │ ────────────────► │ └──────────────────────────┘
└──────┘ │ │
│ POST /callback/transaction
│ │
│ ▼
│ ┌──────────────────┐
│ │ synapse-core │
│ │ │
│ │ Handlers │
│ │ ▼ │
│ │ Services ─ ─ ─► Stellar Client ─ ─ ┐
│ │ ▼ │ │
│ │ DB Queries │ │
│ └──────┬───────────┘ │
│ │ │
│ Read/Write Verify On-Chain
│ │ │
│ ▼ ▼
│ ┌──────────────┐ ┌────────────────────┐
│ │ PostgreSQL │ │ Stellar Horizon API│
│ └──────────────┘ └────────────────────┘
- A user initiates a fiat deposit through the Stellar Anchor Platform.
- The Anchor Platform processes the deposit and sends a webhook callback to
POST /callback/transaction. - synapse-core validates the payload, persists the transaction with status
pending, and returns a201 Created. - (Future) The Transaction Processor updates the status as the transaction moves through the pipeline (
pending→processing→completed/failed).
Sets up the Axum HTTP server, initializes logging via tracing-subscriber, creates the database connection pool, runs SQLx migrations, and mounts all routes.
Key struct:
pub struct AppState {
db: sqlx::PgPool,
}AppState is shared across all handlers via Axum's State extractor.
Reads environment variables using dotenvy and exposes them as a typed Config struct.
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL |
✅ | — | PostgreSQL connection string |
SERVER_PORT |
❌ | 3000 |
HTTP server listen port |
STELLAR_HORIZON_URL |
✅ | — | Stellar Horizon API base URL |
Will define a centralized AppError enum using thiserror, covering database, validation, and HTTP errors. Implements Axum's IntoResponse for automatic JSON error responses with proper status codes.
| File | Purpose |
|---|---|
mod.rs |
Creates a PgPool via PgPoolOptions (max 5 connections) |
models.rs |
Defines the Transaction struct (derives FromRow) |
Transaction Model:
| Field | Type | Description |
|---|---|---|
id |
UUID |
Primary key (auto-generated via Uuid::new_v4()) |
stellar_account |
String |
Stellar account address (max 56 chars) |
amount |
BigDecimal |
Deposit amount |
asset_code |
String |
Asset code (e.g., USD, max 12 chars) |
status |
String |
Transaction status (pending / processing / completed / failed) |
created_at |
DateTime<Utc> |
Insertion timestamp |
updated_at |
DateTime<Utc> |
Last update timestamp |
anchor_transaction_id |
Option<String> |
ID from the Anchor Platform callback |
callback_type |
Option<String> |
deposit or withdrawal |
callback_status |
Option<String> |
Original status from the callback |
| File | Purpose |
|---|---|
mod.rs |
/health endpoint — returns "OK" (to be enhanced with JSON + DB check) |
webhook.rs |
(Planned) POST /callback/transaction — receives Anchor Platform callbacks |
| File | Purpose |
|---|---|
mod.rs |
Module exports |
transaction_processor.rs |
Orchestrates callback processing: validation, persistence, status transitions |
| File | Purpose |
|---|---|
mod.rs |
Module exports |
client.rs |
HTTP client wrapper for the Stellar Horizon API (account lookups, tx verification) |
Defined in migrations/20250216000000_init.sql:
CREATE TABLE IF NOT EXISTS transactions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
stellar_account VARCHAR(56) NOT NULL,
amount NUMERIC NOT NULL,
asset_code VARCHAR(12) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
anchor_transaction_id VARCHAR(255),
callback_type VARCHAR(20),
callback_status VARCHAR(20)
);Indexes:
idx_transactions_status— onstatusfor filteringidx_transactions_stellar_account— onstellar_accountfor lookups
Callback received
│
▼
┌───────────┐
│ pending │
└─────┬─────┘
│ Processor picks up
▼
┌─────────────┐
│ processing │
└──┬───────┬──┘
│ │
On-chain verification│ │ Verification fails
passes │ │ or timeout
▼ ▼
┌──────────┐ ┌────────┐
│completed │ │ failed │
└──────────┘ └────────┘
┌──────────────────────────┐
│ Stellar Anchor Platform │
└────────────┬─────────────┘
│ HTTP POST
▼
┌─────────────────────────────────┐
│ Docker Compose │
│ │
│ ┌──────────────────────┐ │
│ │ synapse-core :3000 │ ─ ─ ─│─ ─ ► Stellar Horizon API
│ └──────────┬───────────┘ │ (HTTPS)
│ │ sqlx │
│ ▼ │
│ ┌──────────────────────┐ │
│ │ PostgreSQL :5432 │ │
│ └──────────────────────┘ │
│ │
└─────────────────────────────────┘
- synapse-core is containerized via a multi-stage
Dockerfile(Rust build → Debian slim runtime). - PostgreSQL 14 Alpine runs as a sidecar in
docker-compose.ymlwith a health check. - Migrations are bundled inside the container at
/app/migrationsand run automatically on startup.
| Technology | Version | Purpose |
|---|---|---|
| Rust | 2024 ed. | Systems language |
| Axum | 0.7 | HTTP framework |
| SQLx | 0.7 | Async PostgreSQL driver + migrations |
| Tokio | 1.x | Async runtime |
| Serde | 1.x | Serialization / deserialization |
| Tracing | 0.1 | Structured logging |
| Anyhow / Thiserror | 1.x | Error handling |
| Chrono | 0.4 | Date/time types |
| UUID | 1.x | UUID generation |
| PostgreSQL | 14+ | Primary data store |
| Docker | — | Containerization |
| Phase | Component | Description |
|---|---|---|
| Phase 1 | synapse-core | Fiat gateway callback processor (current) |
| Phase 2 | Swap Engine | Convert deposited fiat-backed tokens on Stellar DEX |
| Phase 3 | Cross-Chain Bridge | Bridge assets from Stellar to other chains (e.g., EVM) |