# akhan280/event-contract-arbitrage architecture

> Architecture diagram of the GitHub repository akhan280/event-contract-arbitrage, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akhan280/event-contract-arbitrage
- Repository: https://github.com/akhan280/event-contract-arbitrage

## Overview

This is a Next.js prediction-market arbitrage calculator. Users enter prices manually or paste a Kalshi/Polymarket link; the calculator manages venue and outcome inputs, computes fee-inclusive binary or multiple-choice opportunities, and displays trade size, payout, profit, and returns. The app also supports sharing inputs, email subscriptions, and support messages. The main flow is visible in the page and calculator excerpts; API integrations and persistence are represented where route references establish them. Some UI-to-endpoint behavior is not shown, so those links are omitted.

Main entry points: [`src/app/page.tsx`](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/page.tsx) (Calculator page), [`src/hooks/use-calculator.ts`](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/hooks/use-calculator.ts) (Calculator state), [`src/lib/prisma.ts`](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/prisma.ts) (Application database), [`src/components/price-table.tsx`](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/price-table.tsx) (Price table)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Calculator workflow"]
  node_page["Calculator page<br/>[page.tsx]"]
  node_calc["Calculator state<br/>[use-calculator.ts]"]
  node_price_table["Price table<br/>[price-table.tsx]"]
  node_results["Results view<br/>[results.tsx]"]
  node_arb_card["Opportunity card<br/>[arbitrage-card.tsx]"]
  node_additional["Market guidance"]
end

subgraph group_marketdata["Market data and math"]
  node_types["Market data types<br/>[types.ts]"]
  node_quote_api["Quote endpoint<br/>[route.ts]"]
  node_quote_parser["Live quote fetching<br/>[quotes.ts]"]
  node_market_apis{{"Kalshi and Polymarket"}}
  node_quote_apply["Quote matching<br/>[apply-quote.ts]"]
  node_arbitrage["Arbitrage calculations<br/>[arbitrage.ts]"]
end

subgraph group_webfeatures["Sharing and support"]
  node_share_ui["Share controls<br/>[sharable-url.tsx]"]
  node_share_api["Share endpoint<br/>[route.ts]"]
  node_subscription_ui["Email subscription<br/>[email-input.tsx]"]
  node_subscribe_api["Subscription endpoint<br/>[route.ts]"]
  node_contact_ui["Support form<br/>[contact-form.tsx]"]
  node_actions["Support actions<br/>[actions.ts]"]
end

subgraph group_platform["Persistence and platform"]
  node_schemas["Request validation<br/>[schemas.ts]"]
  node_database[("Application database<br/>[prisma.ts]")]
  node_cleanup["Share cleanup job<br/>[route.ts]"]
  node_layout["App layout<br/>[layout.tsx]"]
  node_analytics["PostHog integration<br/>[posthog.tsx]"]
end

node_user(("Calculator user"))

node_user -->|"uses"| node_page
node_page -->|"manages inputs"| node_calc
node_page -->|"renders"| node_price_table
node_page -->|"renders"| node_results
node_page -->|"renders"| node_additional
node_page -->|"renders"| node_share_ui
node_page -->|"renders"| node_subscription_ui
node_price_table -->|"updates prices"| node_calc
node_price_table -->|"matches outcomes"| node_quote_apply
node_calc -->|"requests quotes"| node_quote_api
node_quote_api -->|"fetches quote"| node_quote_parser
node_quote_parser -->|"reads prices"| node_market_apis
node_calc -->|"applies quote"| node_quote_apply
node_calc -->|"calculates opportunities"| node_arbitrage
node_results -->|"renders opportunities"| node_arb_card
node_arb_card -->|"reads fee rules"| node_arbitrage
node_calc -->|"uses models"| node_types
node_arbitrage -->|"uses models"| node_types
node_share_api -->|"validates input"| node_schemas
node_share_api -->|"persists shares"| node_database
node_subscribe_api -->|"validates email"| node_schemas
node_subscribe_api -->|"persists subscription"| node_database
node_contact_ui -->|"submits message"| node_actions
node_actions -->|"validates message"| node_schemas
node_actions -->|"stores message"| node_database
node_cleanup -->|"cleans records"| node_database
node_layout -->|"configures analytics"| node_analytics

click node_page "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/page.tsx"
click node_calc "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/hooks/use-calculator.ts"
click node_price_table "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/price-table.tsx"
click node_results "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/results.tsx"
click node_arb_card "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/arbitrage-card.tsx"
click node_types "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/types.ts"
click node_quote_api "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/quote/route.ts"
click node_quote_parser "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/quotes.ts"
click node_quote_apply "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/apply-quote.ts"
click node_arbitrage "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/arbitrage.ts"
click node_additional "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/additional-info.tsx"
click node_share_ui "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/sharable-url.tsx"
click node_share_api "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/share/route.ts"
click node_subscription_ui "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/email-input.tsx"
click node_subscribe_api "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/subscribe/route.ts"
click node_contact_ui "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/contact-form.tsx"
click node_actions "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/actions.ts"
click node_schemas "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/schemas.ts"
click node_database "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/prisma.ts"
click node_cleanup "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/cron/cleanup/route.ts"
click node_layout "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/layout.tsx"
click node_analytics "https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/posthog.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_page,node_calc,node_price_table,node_results,node_arb_card,node_additional,node_user toneBlue
class node_types,node_quote_api,node_quote_parser,node_market_apis,node_quote_apply,node_arbitrage toneAmber
class node_share_ui,node_share_api,node_subscription_ui,node_subscribe_api,node_contact_ui,node_actions toneMint
class node_schemas,node_database,node_cleanup,node_layout,node_analytics toneRose
```

## Components

### Calculator workflow

- [Calculator page](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Calculator state](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/hooks/use-calculator.ts): `src/hooks/use-calculator.ts`
- [Price table](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/price-table.tsx): `src/components/price-table.tsx`
- [Results view](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/results.tsx): `src/components/results.tsx`
- [Opportunity card](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/arbitrage-card.tsx): `src/components/arbitrage-card.tsx`
- [Market guidance](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/additional-info.tsx): `src/components/additional-info.tsx`

### Market data and math

- [Market data types](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/types.ts): `src/lib/types.ts`
- [Quote endpoint](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/quote/route.ts): `src/app/api/quote/route.ts`
- [Live quote fetching](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/quotes.ts): `src/lib/quotes.ts`
- **Kalshi and Polymarket**
- [Quote matching](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/apply-quote.ts): `src/lib/apply-quote.ts`
- [Arbitrage calculations](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/arbitrage.ts): `src/lib/arbitrage.ts`

### Sharing and support

- [Share controls](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/sharable-url.tsx): `src/components/sharable-url.tsx`
- [Share endpoint](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/share/route.ts): `src/app/api/share/route.ts`
- [Email subscription](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/email-input.tsx): `src/components/email-input.tsx`
- [Subscription endpoint](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/subscribe/route.ts): `src/app/api/subscribe/route.ts`
- [Support form](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/components/contact-form.tsx): `src/components/contact-form.tsx`
- [Support actions](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/actions.ts): `src/lib/actions.ts`

### Persistence and platform

- [Request validation](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/schemas.ts): `src/lib/schemas.ts`
- [Application database](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`
- [Share cleanup job](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/api/cron/cleanup/route.ts): `src/app/api/cron/cleanup/route.ts`
- [App layout](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/app/layout.tsx): `src/app/layout.tsx`
- [PostHog integration](https://github.com/akhan280/event-contract-arbitrage/blob/main/src/lib/posthog.tsx): `src/lib/posthog.tsx`

### Other components

- **Calculator user**

## Connections

- Calculator user → Calculator page: uses (evidence: `src/app/page.tsx`)
- Calculator page → Calculator state: manages inputs (evidence: `src/app/page.tsx`)
- Calculator page → Price table: renders (evidence: `src/app/page.tsx`)
- Calculator page → Results view: renders (evidence: `src/app/page.tsx`)
- Calculator page → Market guidance: renders (evidence: `src/app/page.tsx`)
- Calculator page → Share controls: renders (evidence: `src/app/page.tsx`)
- Calculator page → Email subscription: renders (evidence: `src/app/page.tsx`)
- Price table → Calculator state: updates prices (evidence: `src/app/page.tsx`)
- Price table → Quote matching: matches outcomes (evidence: `src/components/price-table.tsx`)
- Calculator state → Quote endpoint: requests quotes (evidence: `src/hooks/use-calculator.ts`)
- Quote endpoint → Live quote fetching: fetches quote (evidence: `src/app/api/quote/route.ts`)
- Live quote fetching → Kalshi and Polymarket: reads prices (evidence: `src/lib/quotes.ts`)
- Calculator state → Quote matching: applies quote (evidence: `src/hooks/use-calculator.ts`)
- Calculator state → Arbitrage calculations: calculates opportunities (evidence: `src/hooks/use-calculator.ts`)
- Results view → Opportunity card: renders opportunities (evidence: `src/components/results.tsx`)
- Opportunity card → Arbitrage calculations: reads fee rules (evidence: `src/components/arbitrage-card.tsx`)
- Calculator state → Market data types: uses models (evidence: `src/hooks/use-calculator.ts`)
- Arbitrage calculations → Market data types: uses models (evidence: `src/lib/arbitrage.ts`)
- Share endpoint → Request validation: validates input (evidence: `src/app/api/share/route.ts`)
- Share endpoint → Application database: persists shares (evidence: `src/app/api/share/route.ts`)
- Subscription endpoint → Request validation: validates email (evidence: `src/app/api/subscribe/route.ts`)
- Subscription endpoint → Application database: persists subscription (evidence: `src/app/api/subscribe/route.ts`)
- Support form → Support actions: submits message (evidence: `src/components/contact-form.tsx`)
- Support actions → Request validation: validates message (evidence: `src/lib/actions.ts`)
- Support actions → Application database: stores message (evidence: `src/lib/actions.ts`)
- Share cleanup job → Application database: cleans records (evidence: `src/app/api/cron/cleanup/route.ts`)
- App layout → PostHog integration: configures analytics (evidence: `src/app/layout.tsx`)
