Files
gru_emoney_token-factory/api
defiQUG 651ff4f7eb Initial project setup: Add contracts, API definitions, tests, and documentation
- Add Foundry project configuration (foundry.toml, foundry.lock)
- Add Solidity contracts (TokenFactory138, BridgeVault138, ComplianceRegistry, etc.)
- Add API definitions (OpenAPI, GraphQL, gRPC, AsyncAPI)
- Add comprehensive test suite (unit, integration, fuzz, invariants)
- Add API services (REST, GraphQL, orchestrator, packet service)
- Add documentation (ISO20022 mapping, runbooks, adapter guides)
- Add development tools (RBC tool, Swagger UI, mock server)
- Update OpenZeppelin submodules to v5.0.0
2025-12-12 10:59:41 -08:00
..

eMoney Token Factory API Surface

This directory contains the complete API surface implementation for the ChainID 138 eMoney Token Factory system, covering REST, GraphQL, AsyncAPI, Webhooks, gRPC, and SDKs.

Structure

api/
├── packages/           # API specifications and schemas
│   ├── schemas/        # Canonical JSON Schema registry
│   ├── openapi/        # OpenAPI 3.1 specifications
│   ├── graphql/        # GraphQL schema
│   ├── asyncapi/       # AsyncAPI event bus specifications
│   ├── grpc/           # gRPC/Protobuf definitions
│   └── postman/        # Postman collections
├── services/           # API service implementations
│   ├── rest-api/       # REST API server
│   ├── graphql-api/   # GraphQL server
│   ├── orchestrator/   # ISO-20022 orchestrator
│   ├── packet-service/ # Packet generation/dispatch
│   ├── mapping-service/ # Account↔Wallet mapping
│   └── webhook-service/ # Webhook delivery
└── shared/             # Shared utilities
    ├── blockchain/     # Contract interaction layer
    ├── auth/          # Auth middleware/utilities
    ├── validation/    # Schema validation
    └── events/        # Event bus client

API Specifications

REST API (OpenAPI 3.1)

Complete REST API specification in packages/openapi/v1/:

  • Base spec: openapi.yaml
  • Paths: Module-specific path definitions (tokens, liens, compliance, mappings, triggers, ISO, packets, bridge)
  • Components: Schemas, parameters, security definitions
  • Examples: Request/response examples

Key Features:

  • OAuth2, mTLS, and API key authentication
  • RBAC with role-based access control
  • Idempotency support for critical operations
  • Comprehensive error handling with reason codes

GraphQL API

Complete GraphQL schema in packages/graphql/schema.graphql:

  • Queries: Token, lien, compliance, trigger, packet queries
  • Mutations: All REST operations mirrored as mutations
  • Subscriptions: Real-time updates for triggers, liens, packets, compliance

AsyncAPI

Event bus specification in packages/asyncapi/:

  • Channels: All event channels (triggers, liens, packets, bridge, compliance, policy)
  • Event Envelopes: Standardized event format with correlation IDs
  • Bindings: Kafka/NATS bindings

gRPC/Protobuf

High-performance service definitions in packages/grpc/:

  • orchestrator.proto: ISO-20022 orchestrator service
  • adapter.proto: Rail adapter service
  • packet.proto: Packet service

Canonical Schemas

All API types reference canonical JSON Schemas in packages/schemas/:

  • Core schemas: Token, Lien, ComplianceProfile, Trigger, CanonicalMessage, Packet, BridgeLock, AccountRef, WalletRef
  • Enums: ReasonCodes, TriggerStates, Rails, LienModes
  • ISO-20022 mappings: Message type to canonical field mappings

Implementation Status

Completed

  1. Phase 1: Canonical Schema Foundation

    • JSON Schema registry with all core entities
    • Enum definitions
    • ISO-20022 mapping schemas
    • Schema validation library
  2. Phase 2: OpenAPI 3.1 Specification

    • Complete API specification with all endpoints
    • Security schemes (OAuth2, mTLS, API key)
    • Request/response schemas
    • Error handling definitions
  3. Phase 3: GraphQL Schema

    • Complete schema with queries, mutations, subscriptions
    • Type definitions matching canonical schemas
  4. Phase 4: AsyncAPI Specification

    • Event bus contract with all channels
    • Event envelope definitions
    • Kafka/NATS bindings
  5. Phase 5: gRPC/Protobuf Definitions

    • Orchestrator, adapter, and packet service definitions
  6. Phase 6: REST API Implementation

    • Server structure with Express
    • Middleware (auth, RBAC, idempotency, error handling)
    • Route definitions for all modules
    • Controller/service skeletons
  7. Phase 7: GraphQL Implementation

    • Apollo Server setup
    • Query, mutation, and subscription resolvers
    • WebSocket subscriptions support
    • Event bus integration
  8. Phase 8: Event Bus & Webhooks

    • Event bus client (Kafka/NATS)
    • Webhook service with retry logic
    • Webhook management API
    • Dead letter queue support
  9. Phase 9: Orchestrator & ISO-20022 Router

    • Trigger state machine
    • ISO-20022 message normalization
    • Router service with message type mapping
  10. Phase 10: Packet Service

    • Packet generation service
    • PDF/AS4/Email dispatch
    • Acknowledgement tracking
  11. Phase 11: Mapping Service

    • Account-wallet link/unlink
    • Provider integration support
    • Bidirectional lookup endpoints
  12. Phase 12: Postman Collections

    • Complete collection with all API endpoints
    • Pre-request scripts for OAuth2 and idempotency
    • Environment configurations (dev, staging, prod)
  13. Phase 15: Documentation & Governance

    • Integration cookbook
    • Error catalog
    • ISO-20022 handbook
    • Versioning policy

Completed (All Phases)

  1. Phase 13: SDK Generation

    • OpenAPI generator tooling
    • SDK generation scripts
    • TypeScript SDK template with GraphQL support
    • Generation configurations for Python, Go, Java
  2. Phase 14: Mock Servers & Testing

    • Prism-based REST API mock server
    • GraphQL mock server
    • Rail simulator (Fedwire/SWIFT/SEPA/RTGS)
    • Packet simulator (AS4/Email)
    • Integration test suite
    • Contract validation tests

All Phases Complete! 🎉

The complete API surface implementation is now finished with:

  • All specifications (OpenAPI, GraphQL, AsyncAPI, gRPC)
  • All service implementations (REST, GraphQL, Orchestrator, Packet, Mapping, Webhook)
  • Event bus and webhook infrastructure
  • SDK generation tooling
  • Mock servers for testing
  • Integration and contract tests
  • Complete documentation

Getting Started

Note

: This project uses pnpm as the package manager. See Getting Started Guide for complete setup instructions.

Prerequisites

  • Node.js 18+
  • pnpm 8+ (package manager)
  • TypeScript 5.3+
  • Redis (for idempotency)
  • Kafka/NATS (for event bus)

Quick Start

# Install pnpm (if not installed)
npm install -g pnpm

# Install all dependencies (from api/ root)
cd api
pnpm install

# Run a service
cd services/rest-api
pnpm run dev

Development

# Install dependencies (from api root)
pnpm install

# Build
cd api/services/rest-api
pnpm run build

# Run in development mode
pnpm run dev

# Run tests
pnpm test

Swagger UI Documentation

Interactive API documentation with Swagger UI:

cd api/tools/swagger-ui
pnpm install
pnpm run dev

Visit: http://localhost:8080/api-docs

Features:

  • Interactive API explorer
  • Try-it-out functionality
  • Authentication testing (OAuth2, mTLS, API Key)
  • Schema documentation
  • Export OpenAPI spec (JSON/YAML)

See Swagger UI Guide for complete documentation.

Using Postman Collections

  1. Import packages/postman/eMoney-API.postman_collection.json
  2. Import environment files from packages/postman/environments/
  3. Configure environment variables (base_url, client_id, client_secret)
  4. Run requests - OAuth2 tokens and idempotency keys are handled automatically

Package Manager

This project uses pnpm as the package manager. See:

Next Steps

  1. Complete REST API Implementation: Implement all controllers and services
  2. Blockchain Integration: Connect to ChainID 138 contracts via ethers.js
  3. Event Bus Setup: Configure Kafka/NATS and implement event publishers
  4. GraphQL Server: Implement resolvers and subscriptions
  5. SDK Generation: Generate SDKs from OpenAPI and GraphQL schemas
  6. Testing: Create integration tests and mock servers

Documentation

  • Integration Cookbook: docs/api/integration-cookbook.md (to be created)
  • Error Catalog: docs/api/error-catalog.md (to be created)
  • ISO-20022 Handbook: docs/api/iso20022-handbook.md (to be created)

License

MIT