# rytkhs/event-pay architecture

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

- Interactive diagram: https://gitdiagram.com/rytkhs/event-pay
- Repository: https://github.com/rytkhs/event-pay

## Overview

##### Project Type and Purpose
- This is a full-stack, server-rendered web application (“みんなの集金 / EventPay”) built on Next.js 14’s App Router, deployed to Cloudflare Workers via OpenNext.
- It serves small community event organizers by providing event management, attendance tracking, payment collection (via Stripe Connect), reminder emails and balance monitoring.

##### Core Architectural Layers
a. Presentation Layer (app/)
- Next.js pages, Server Actions and API routes under app/
- Marketing, auth, dashboard, events, guest, invite, payments, payouts, settings, public/legal, error pages
b. Feature Layer (features/)
- Organized by domain: auth, events, guest, invite, payments, settlements, stripe-connect, settings
- Each has actions, components, hooks, services, validation and type definitions
c. Domain/Core Layer (core/)
- Domain models, constants, types, utilities, ports/interfaces, services (payment, settlement, stripe-connect), notification & logging, security, rate-limit, session management, analytics
- Implements hexagonal/clean-architecture patterns: core defines interfaces (ports) and domain logic, adapters in features or core/stripe, core/services implement business rules
d. Infrastructure/Integrations
- Supabase (Postgres) for BaaS: auth, database CRUD, RLS, migrations under supabase/
- Stripe (Checkout, Connect, Webhooks) for payments
- Upstash Redis for rate limiting (@upstash/ratelimit)
- Email service and Slack notifications via core/notification and Resend API
- Cloudflare R2 for incremental caching (open-next.config.ts)
- GitHub Actions for scheduled cron tasks (send reminders, monitor balance) hitting /api/cron/* routes

##### Main Components
- End users (organizers in dashboard, participants/guests via invite links, public visitors)
- Cloudflare Workers Edge (OpenNext worker.js)
- Next.js App Router & Server Actions
- API Routes / Serverless Functions:
- /api/payments/verify-session
- /api/webhooks/{stripe, stripe-connect}
- /api/cron/{send-reminders, monitor-platform-balance}
- /api/workers/*
- Feature modules orchestrating core services
- Core domain services & adapters
- Supabase Postgres DB
- Upstash Redis
- Stripe Connect & Stripe API
- Email/Slack notification endpoints
- GitHub Actions scheduler

##### Component Interactions and Data Flows
a. User Request Flow
User Browser → DNS → Cloudflare Workers (edge) → Next.js Router
→ Server-Side Rendering or Server Action
→ Feature layer → Core service → Supabase or External API
→ Response → Edge Cache / CDN → Browser
b. Payment Flow
Dashboard initiates checkout → Next.js Server Action calls Stripe API
→ Redirect to Stripe Checkout → Stripe → Webhook POST → /api/webhooks/stripe route
→ Core webhook handler → Update Supabase, trigger email via core/notification
c. Cron Tasks
GitHub Actions → HTTP POST to /api/cron/send-reminders and /api/cron/monitor-platform-balance
→ Cloudflare Worker → Next.js API Route → core/notification → dispatch emails & Slack alerts
d. Rate Limiting & Security
Requests pass through Upstash Redis rate limiter (core/rate-limit/client.ts)
Security headers applied in next.config.mjs; CSP, HSTS, Permissions-Policy

##### Architectural Patterns and Principles
- Clean / Hexagonal Architecture: core/ defines ports and domain logic, features/ and core/stripe-connect/adapters implement adapters
- Separation of concerns: Presentation (app/), Features, Core Domain, Infrastructure
- Serverless microservices style: each API route is an independent serverless function
- Edge-first: via Cloudflare Workers + R2 incremental caching for SSR and static assets

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Users & CDN
    subgraph "User & CDN Layer"
        direction TB
        UserBrowser["User Browser"]:::ui
        CDN["CDN / Edge Cache"]:::external
    end

    UserBrowser -->|"DNS, HTTP"| CDN

    %% Edge & Routing
    subgraph "Edge & Application Layer"
        direction TB
        CFWorker["Cloudflare Worker (OpenNext)"]:::serverless
        NextRouter["Next.js App Router"]:::application
    end

    CDN --> CFWorker --> NextRouter

    %% Presentation Layer
    subgraph "Presentation Layer (app/)" 
        direction TB
        Marketing["Marketing Pages"]:::ui
        AuthPages["Auth Pages & Actions"]:::ui
        DashboardUI["Dashboard (Organizers UI)"]:::ui
        EventsUI["Events Pages & Components"]:::ui
        GuestInvite["Guest & Invite Flows"]:::ui
        PaymentsUI["Payments & Payout Pages"]:::ui
    end

    NextRouter --> Marketing
    NextRouter --> AuthPages
    NextRouter --> DashboardUI
    NextRouter --> EventsUI
    NextRouter --> GuestInvite
    NextRouter --> PaymentsUI

    %% Serverless Functions
    subgraph "Serverless Functions (app/api/)" 
        direction TB
        VerifySession["Verify Payment Session"]:::serverless
        WebhookStripe["Webhook: Stripe"]:::serverless
        WebhookConnect["Webhook: Stripe-Connect"]:::serverless
        CronReminders["Cron: Send Reminders"]:::serverless
        CronBalance["Cron: Monitor Balance"]:::serverless
        WorkerCancel["Worker: Event Cancel"]:::serverless
        WorkerStripe["Worker: Stripe Webhook"]:::serverless
        WorkerConnect["Worker: Stripe-Connect Webhook"]:::serverless
    end

    NextRouter --> VerifySession
    NextRouter --> WebhookStripe
    NextRouter --> WebhookConnect
    CronReminders -->|via CFWorker| CFWorker
    CronBalance -->|via CFWorker| CFWorker
    CFWorker --> WorkerCancel
    CFWorker --> WorkerStripe
    CFWorker --> WorkerConnect

    %% Feature Layer
    subgraph "Feature Layer (features/)"
        direction TB
        FeatureAuth["Auth Module"]:::feature
        FeatureEvents["Events Module"]:::feature
        FeatureGuest["Guest Module"]:::feature
        FeatureInvite["Invite Module"]:::feature
        FeaturePayments["Payments Module"]:::feature
        FeatureSettlements["Settlements Module"]:::feature
        FeatureStripeConnect["Stripe-Connect Module"]:::feature
        FeatureSettings["Settings Module"]:::feature
    end

    Marketing --> FeatureAuth
    AuthPages --> FeatureAuth
    DashboardUI --> FeatureEvents
    EventsUI --> FeatureEvents
    GuestInvite --> FeatureGuest
    GuestInvite --> FeatureInvite
    PaymentsUI --> FeaturePayments
    PaymentsUI --> FeaturePayouts["Payouts Module"]:::feature
    VerifySession --> FeaturePayments
    WebhookStripe --> FeaturePayments
    WebhookConnect --> FeatureStripeConnect
    CronReminders --> FeatureEvents
    CronBalance --> FeatureSettlements
    WorkerCancel --> FeatureEvents
    WorkerStripe --> FeaturePayments
    WorkerConnect --> FeatureStripeConnect

    %% Core Domain Layer
    subgraph "Core Domain (core/)"
        direction TB
        CorePorts["Ports & Interfaces"]:::core
        CoreServices["Core Services"]:::core
        CoreNotification["Notification & Logging"]:::core
        CoreRateLimit["Rate Limiting"]:::core
        CoreSecurity["Security & Session"]:::core
        CoreUtils["Utilities & Validation"]:::core
        CoreStripeClient["Stripe Client Adapter"]:::core
        CoreSupabase["Supabase Adapter"]:::core
    end

    FeatureAuth --> CorePorts
    FeatureEvents --> CoreServices
    FeatureGuest --> CorePorts
    FeatureInvite --> CoreServices
    FeaturePayments --> CoreServices
    FeatureStripeConnect --> CoreStripeClient
    FeatureSettings --> CoreServices

    VerifySession --> CoreServices
    WebhookStripe --> CoreServices
    CronReminders --> CoreNotification
    CronBalance --> CoreNotification
    WorkerStripe --> CoreServices
    WorkerConnect --> CoreStripeClient

    CoreServices --> CoreSupabase
    CoreServices --> CoreStripeClient
    CoreNotification -->|"Email/Slack"| EmailService
    CoreRateLimit -->|"Rate Limit"| UpstashRedis
    NextRouter --> CoreRateLimit
    CFWorker --> CoreSecurity

    %% External Systems & Data
    subgraph "External Systems & Data"
        direction TB
        SupabasePostgres["Supabase Postgres"]:::db
        UpstashRedis["Upstash Redis"]:::db
        StripeAPI["Stripe API"]:::external
        StripeConnectAPI["Stripe Connect API"]:::external
        EmailService["Email & Slack Service"]:::external
        GitHubActions["GitHub Actions (Cron)"]:::external
    end

    CoreSupabase --> SupabasePostgres
    CoreStripeClient --> StripeAPI
    CoreStripeClient --> StripeConnectAPI
    GitHubActions --> CronReminders
    GitHubActions --> CronBalance

    %% Legend
    classDef ui fill:#D5E8D4,stroke:#82B366,stroke-width:1px;
    classDef serverless fill:#FFF2CC,stroke:#D6B656,stroke-width:1px;
    classDef application fill:#DAE8FC,stroke:#6C8EBF,stroke-width:1px;
    classDef feature fill:#F8CECC,stroke:#B85450,stroke-width:1px;
    classDef core fill:#E1D5E7,stroke:#9673A6,stroke-width:1px;
    classDef external fill:#F5F5F5,stroke:#999999,stroke-width:1px;
    classDef db fill:#FFE6CC,stroke:#D79B00,stroke-width:1px;

    %% Click Events
    click Marketing "https://github.com/rytkhs/event-pay/tree/main/app/(marketing)/"
    click AuthPages "https://github.com/rytkhs/event-pay/tree/main/app/(auth)/"
    click AuthPages "https://github.com/rytkhs/event-pay/blob/main/app/auth/callback/route.ts"
    click DashboardUI "https://github.com/rytkhs/event-pay/tree/main/app/(dashboard)/"
    click EventsUI "https://github.com/rytkhs/event-pay/tree/main/app/events/"
    click EventsUI "https://github.com/rytkhs/event-pay/blob/main/app/events/actions.ts"
    click GuestInvite "https://github.com/rytkhs/event-pay/tree/main/app/guest/"
    click GuestInvite "https://github.com/rytkhs/event-pay/tree/main/app/invite/"
    click PaymentsUI "https://github.com/rytkhs/event-pay/tree/main/app/payments/"
    click PaymentsUI "https://github.com/rytkhs/event-pay/tree/main/app/payouts/"
    click VerifySession "https://github.com/rytkhs/event-pay/blob/main/app/api/payments/verify-session/route.ts"
    click WebhookStripe "https://github.com/rytkhs/event-pay/blob/main/app/api/webhooks/stripe/route.ts"
    click WebhookConnect "https://github.com/rytkhs/event-pay/blob/main/app/api/webhooks/stripe-connect/route.ts"
    click CronReminders "https://github.com/rytkhs/event-pay/blob/main/app/api/cron/send-reminders/route.ts"
    click CronBalance "https://github.com/rytkhs/event-pay/blob/main/app/api/cron/monitor-platform-balance/route.ts"
    click WorkerCancel "https://github.com/rytkhs/event-pay/blob/main/app/api/workers/event-cancel/route.ts"
    click WorkerStripe "https://github.com/rytkhs/event-pay/blob/main/app/api/workers/stripe-webhook/route.ts"
    click WorkerConnect "https://github.com/rytkhs/event-pay/blob/main/app/api/workers/stripe-connect-webhook/route.ts"
    click FeatureAuth "https://github.com/rytkhs/event-pay/tree/main/features/auth/"
    click FeatureEvents "https://github.com/rytkhs/event-pay/tree/main/features/events/"
    click FeatureGuest "https://github.com/rytkhs/event-pay/tree/main/features/guest/"
    click FeatureInvite "https://github.com/rytkhs/event-pay/tree/main/features/invite/"
    click FeaturePayments "https://github.com/rytkhs/event-pay/tree/main/features/payments/"
    click FeatureSettlements "https://github.com/rytkhs/event-pay/tree/main/features/settlements/"
    click FeatureStripeConnect "https://github.com/rytkhs/event-pay/tree/main/features/stripe-connect/"
    click FeatureSettings "https://github.com/rytkhs/event-pay/tree/main/features/settings/"
    click CorePorts "https://github.com/rytkhs/event-pay/tree/main/core/ports/"
    click CoreServices "https://github.com/rytkhs/event-pay/tree/main/core/services/"
    click CoreNotification "https://github.com/rytkhs/event-pay/tree/main/core/notification/"
    click CoreRateLimit "https://github.com/rytkhs/event-pay/blob/main/core/rate-limit/client.ts"
    click CoreSecurity "https://github.com/rytkhs/event-pay/blob/main/core/auth-security.ts"
    click CoreUtils "https://github.com/rytkhs/event-pay/tree/main/core/utils/"
    click CoreStripeClient "https://github.com/rytkhs/event-pay/blob/main/core/stripe/client.ts"
    click CoreSupabase "https://github.com/rytkhs/event-pay/tree/main/core/supabase/"
    click SupabasePostgres "https://github.com/rytkhs/event-pay/blob/main/supabase/config.toml"
    click SupabasePostgres "https://github.com/rytkhs/event-pay/tree/main/supabase/migrations/"
    click CoreSupabase "https://github.com/rytkhs/event-pay/blob/main/core/supabase/factory.ts"
    click CoreSupabase "https://github.com/rytkhs/event-pay/blob/main/core/supabase/server.ts"
    click EmailService "https://github.com/rytkhs/event-pay/blob/main/core/notification/email-service.ts"
    click EmailService "https://github.com/rytkhs/event-pay/blob/main/core/notification/slack.ts"
    click EmailService "https://github.com/rytkhs/event-pay/tree/main/emails/"
    click UpstashRedis "https://github.com/rytkhs/event-pay/blob/main/core/rate-limit/client.ts"
    click CFWorker "https://github.com/rytkhs/event-pay/blob/main/open-next.config.ts"
    click CFWorker "https://github.com/rytkhs/event-pay/blob/main/wrangler.jsonc"
    click NextRouter "https://github.com/rytkhs/event-pay/blob/main/next.config.mjs"
    click GitHubActions "https://github.com/rytkhs/event-pay/blob/main/.github/workflows/send-reminders.yml"
    click GitHubActions "https://github.com/rytkhs/event-pay/blob/main/.github/workflows/monitor-platform-balance.yml"
```
