Skip to content

feat: adding kotlin sample#192

Open
pengying wants to merge 8 commits intomainfrom
02-12-feat_adding_kotlin_sample
Open

feat: adding kotlin sample#192
pengying wants to merge 8 commits intomainfrom
02-12-feat_adding_kotlin_sample

Conversation

@pengying
Copy link
Contributor

No description provided.

pengying and others added 7 commits February 12, 2026 14:11
Defines architecture for a Kotlin backend + shared Vite frontend
sample demonstrating the payout flow (customer → external account →
quote → execute → sandbox fund) with live webhook streaming via SSE.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
12-task plan covering Kotlin backend scaffold, routes, frontend
scaffold, components, wizard assembly, and READMEs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add all Kotlin source files for the Grid API sample app backend:
- Core infrastructure: Config, GridClientBuilder, WebhookStream, JsonUtils
- Application entry point with CORS and SSE configuration
- Route handlers: Customers, ExternalAccounts, Quotes, Sandbox, Webhooks, SSE
- Fix build.gradle.kts to use correct SDK coordinates (com.grid.api:grid-kotlin)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add node-gradle plugin to build frontend as part of ./gradlew run
- Vite outputs to backend's src/main/resources/static/
- Ktor serves static files at / (after API routes)
- Update README with single-command and dev-server run options

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pengying pengying marked this pull request as ready for review February 13, 2026 02:20
Copy link
Contributor Author

pengying commented Feb 13, 2026

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

This PR adds a comprehensive Kotlin sample application for the Grid API, demonstrating the complete payout flow with a React frontend and Ktor backend. The implementation includes a step-by-step wizard for creating customers, linking external accounts, creating quotes, and executing payments, with real-time webhook streaming via SSE.

Key Changes:

  • Kotlin backend using Ktor 3.x with thin proxy pattern - translates JSON requests to Grid SDK calls
  • React frontend with Vite, TypeScript, and Tailwind CSS implementing wizard flow
  • Gradle integration that builds frontend and serves it from backend resources
  • Webhook verification and SSE streaming for real-time event updates
  • Comprehensive documentation including architecture diagrams and setup instructions
  • Proper error handling, structured logging with colorized output

Architecture:
The backend acts as a credential-holding proxy while the frontend orchestrates the user flow. Webhooks are verified, unwrapped using the Grid SDK, and broadcast to frontend clients via Server-Sent Events. The design enables easy replication in other languages by reusing the shared frontend.

The implementation is production-quality for a sample app with proper security practices (webhook signature verification, credential management via environment variables).

Confidence Score: 4/5

  • Safe to merge with minor ambiguity in quote source detection logic
  • Well-structured sample application with proper architecture, comprehensive documentation, and secure webhook handling. The buildQuoteSource logic in Quotes.kt:91 has ambiguous detection (checks both sourceType and presence of currency field) but the frontend consistently sends sourceType: "REALTIME_FUNDING" so it works in practice. All other routes are clean with proper error handling.
  • samples/kotlin/src/main/kotlin/com/grid/sample/routes/Quotes.kt - review the source type detection logic

Important Files Changed

Filename Overview
samples/kotlin/src/main/kotlin/com/grid/sample/Application.kt Sets up Ktor server with CORS, SSE, routing, and serves frontend static files
samples/kotlin/src/main/kotlin/com/grid/sample/routes/Quotes.kt Implements quote creation and execution routes; has ambiguous source type detection logic
samples/kotlin/src/main/kotlin/com/grid/sample/routes/Webhooks.kt Handles webhook reception, unwraps events using SDK, broadcasts to SSE stream
samples/kotlin/src/main/kotlin/com/grid/sample/routes/ExternalAccounts.kt Creates external bank accounts with proper beneficiary and account info handling
samples/kotlin/src/main/kotlin/com/grid/sample/routes/Customers.kt Creates individual customers with proper optional field handling
samples/kotlin/build.gradle.kts Gradle build with node plugin for frontend integration, proper dependencies
samples/frontend/src/components/WebhookStream.tsx SSE-connected webhook stream component with auto-reconnect and expandable events
samples/frontend/vite.config.ts Vite config with API proxy to backend and build output to Kotlin resources

Sequence Diagram

sequenceDiagram
    participant Browser
    participant Vite as Vite Dev Server
    participant Ktor as Ktor Backend
    participant Grid as Grid API
    participant Webhooks as Grid Webhooks

    Browser->>Vite: Load App (http://localhost:5173)
    Vite-->>Browser: React Frontend
    Browser->>Ktor: SSE Connection (/api/sse)
    Ktor-->>Browser: Connected

    Note over Browser,Ktor: Step 1: Create Customer
    Browser->>Vite: POST /api/customers
    Vite->>Ktor: Proxy to :8080
    Ktor->>Grid: customers.create()
    Grid-->>Ktor: Customer Response
    Ktor-->>Browser: Customer JSON

    Note over Browser,Ktor: Step 2: Create External Account
    Browser->>Vite: POST /api/customers/{id}/external-accounts
    Vite->>Ktor: Proxy to :8080
    Ktor->>Grid: externalAccounts.create()
    Grid-->>Ktor: Account Response
    Ktor-->>Browser: Account JSON

    Note over Browser,Ktor: Step 3: Create Quote
    Browser->>Vite: POST /api/quotes
    Vite->>Ktor: Proxy to :8080
    Ktor->>Grid: quotes.create()
    Grid-->>Ktor: Quote Response
    Ktor-->>Browser: Quote JSON

    Note over Browser,Ktor: Step 4: Execute Quote
    Browser->>Vite: POST /api/quotes/{id}/execute
    Vite->>Ktor: Proxy to :8080
    Ktor->>Grid: quotes.execute()
    Grid-->>Ktor: Updated Quote
    Ktor-->>Browser: Quote JSON

    Note over Browser,Ktor: Step 5: Sandbox Fund
    Browser->>Vite: POST /api/sandbox/send-funds
    Vite->>Ktor: Proxy to :8080
    Ktor->>Grid: sandbox.sendFunds()
    Grid-->>Ktor: Funding Response
    Ktor-->>Browser: Confirmation JSON

    Note over Webhooks,Browser: Webhook Flow
    Webhooks->>Ktor: POST /api/webhooks
    Ktor->>Ktor: Verify signature & unwrap
    Ktor->>Ktor: Broadcast to WebhookStream
    Ktor-->>Browser: SSE event with webhook data
Loading

Last reviewed commit: ed33d3f

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

52 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 02-12-feat_adding_kotlin_sample branch from a8558f0 to 61be1bc Compare February 13, 2026 02:24
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

50 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@pengying pengying force-pushed the 02-12-feat_adding_kotlin_sample branch 3 times, most recently from 9e09ccc to 6d3a5a1 Compare February 13, 2026 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant