# midday-ai/v1 architecture

> Architecture diagram of the GitHub repository midday-ai/v1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/midday-ai/v1
- Repository: https://github.com/midday-ai/v1

## Overview

##### Project type and purpose
- This is an opinionated, full‑stack, monorepo SaaS starter kit (“Create v1”) comprising:
- A Supabase‑backed API (Postgres + Auth + Edge Functions)
- A Next.js “app” product (protected dashboard)
- A Next.js marketing “web” site
- Shared utility and UI packages (analytics, email, jobs, kv, logger, supabase client, ui)
- Tooling layers (Turborepo, Biome, TypeScript configs)

##### File structure
- Top‑level “apps” folder:
- apps/api → Supabase configuration, Edge Functions, DB migrations, seed script
- apps/app → the main product Next.js application, server‑actions, i18n, Sentry, Tailwind, Dub link‑sharing
- apps/web → marketing Next.js site, subscribe form, embedded calendar
- “packages” folder: shared libraries:
- analytics (OpenPanel)
- email (React Email templates + Resend)
- jobs (Trigger.dev background tasks)
- kv (Upstash Redis caching & rate‑limit)
- logger (central logging)
- supabase (typed queries, mutations, client wrappers)
- ui (Shadcn/Tailwind UI primitives)
- Tooling folder contains shared TypeScript configs; root hosts Turbo (monorepo build orchestrator) and Biome (formatter/linter).

##### Key architecture notes from README
- Monorepo, code reuse via shared packages
- Next.js at the frontends, Supabase as “backend” plus Edge Functions
- External SaaS integrations: Upstash, Resend, Trigger.dev, OpenPanel, Dub, Sentry

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontends"
        direction TB
        WEB["Next.js Marketing Site"]:::frontend
        APP["Next.js Dashboard App"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        EF["Supabase Edge Functions"]:::backend
        AUTH["Supabase Auth & Realtime"]:::backend
        DB[(“Postgres Database”)]:::backend
        MIG["DB Migrations & Seed"]:::backend
    end

    %% Shared Packages
    subgraph "Shared Packages"
        direction TB
        UI["UI Components"]:::libs
        SUPA["Supabase Client Wrappers"]:::libs
        ANALYTICS["Analytics Package"]:::libs
        EMAIL_LIB["Email Package"]:::libs
        JOBS["Jobs Package"]:::libs
        KV["KV Package"]:::libs
        LOGGER["Logger Package"]:::libs
    end

    %% External SaaS
    subgraph "External Services"
        direction TB
        UPSTASH["Upstash Redis"]:::external
        RESEND["Resend (SMTP/API)"]:::external
        TRIGGERDEV["Trigger.dev"]:::external
        OPENPANEL["OpenPanel Analytics"]:::external
        DUB["Dub Link‑Sharing"]:::external
        SENTRY["Sentry Monitoring"]:::external
    end

    %% Tooling
    subgraph "Monorepo Tooling"
        direction TB
        TURBO["Turborepo"]:::tooling
        BIOME["Biome"]:::tooling
        TSCONFIG["TypeScript Configs"]:::tooling
    end

    %% Connections: Frontends to Shared Packages
    WEB -->|"imports"| UI
    WEB -->|"imports"| SUPA
    WEB -->|"imports"| ANALYTICS
    WEB -->|"imports"| LOGGER

    APP -->|"imports"| UI
    APP -->|"imports"| SUPA
    APP -->|"imports"| ANALYTICS
    APP -->|"imports"| LOGGER

    %% Frontends to API
    WEB -->|"calls Edge Functions & Supabase"| EF
    WEB -->|"uses Auth & DB"| AUTH
    WEB -->|"uses Auth & DB"| DB

    APP -->|"calls Edge Functions & Supabase"| EF
    APP -->|"uses Auth & DB"| AUTH
    APP -->|"uses Auth & DB"| DB

    %% Edge Functions to Shared Packages and Externals
    EF -->|"uses"| EMAIL_LIB
    EF -->|"uses"| JOBS
    EF -->|"uses"| KV
    EF -->|"writes migrations"| MIG

    EMAIL_LIB -->|"delivers via"| RESEND
    JOBS -->|"executes on"| TRIGGERDEV
    KV -->|"caches in"| UPSTASH

    %% Dashboard Dub integration
    APP -->|"uses Dub API via dub.ts"| DUB

    %% Error reporting
    WEB -->|"reports errors"| SENTRY
    APP -->|"reports errors"| SENTRY
    EF -->|"reports errors"| SENTRY

    %% Tooling orchestration
    TURBO -->|"orchestrates build/test"| WEB
    TURBO -->|"orchestrates build/test"| APP
    TURBO -->|"orchestrates build/test"| EF
    TURBO -->|"orchestrates build/test"| UI
    TURBO -->|"orchestrates build/test"| SUPA
    TURBO -->|"orchestrates build/test"| ANALYTICS
    TURBO -->|"orchestrates build/test"| EMAIL_LIB
    TURBO -->|"orchestrates build/test"| JOBS
    TURBO -->|"orchestrates build/test"| KV
    TURBO -->|"orchestrates build/test"| LOGGER

    BIOME -->|"formats/lints"| WEB
    BIOME -->|"formats/lints"| APP
    BIOME -->|"formats/lints"| EF
    BIOME -->|"formats/lints"| UI
    BIOME -->|"formats/lints"| SUPA
    BIOME -->|"formats/lints"| ANALYTICS
    BIOME -->|"formats/lints"| EMAIL_LIB
    BIOME -->|"formats/lints"| JOBS
    BIOME -->|"formats/lints"| KV
    BIOME -->|"formats/lints"| LOGGER

    TSCONFIG -->|"shared configs to"| WEB
    TSCONFIG -->|"shared configs to"| APP
    TSCONFIG -->|"shared configs to"| EF
    TSCONFIG -->|"shared configs to"| UI
    TSCONFIG -->|"shared configs to"| SUPA
    TSCONFIG -->|"shared configs to"| ANALYTICS
    TSCONFIG -->|"shared configs to"| EMAIL_LIB
    TSCONFIG -->|"shared configs to"| JOBS
    TSCONFIG -->|"shared configs to"| KV
    TSCONFIG -->|"shared configs to"| LOGGER

    %% Click Events - Mapping
    click EF "https://github.com/midday-ai/v1/tree/main/apps/api/supabase/functions"
    click MIG "https://github.com/midday-ai/v1/tree/main/apps/api/supabase/migrations"
    click EF "https://github.com/midday-ai/v1/blob/main/apps/api/supabase/functions/send-email/index.ts"
    click EF "https://github.com/midday-ai/v1/blob/main/apps/api/supabase/functions/import_map.json"
    click MIG "https://github.com/midday-ai/v1/blob/main/apps/api/supabase/seed.sql"
    click AUTH "https://github.com/midday-ai/v1/tree/main/apps/api"
    click APP "https://github.com/midday-ai/v1/tree/main/apps/app"
    click APP "https://github.com/midday-ai/v1/blob/main/apps/app/src/app/[locale]/(dashboard)/page.tsx"
    click APP "https://github.com/midday-ai/v1/blob/main/apps/app/src/actions/post/share-link-action.ts"
    click APP "https://github.com/midday-ai/v1/blob/main/apps/app/src/lib/dub.ts"
    click WEB "https://github.com/midday-ai/v1/tree/main/apps/web"
    click WEB "https://github.com/midday-ai/v1/blob/main/apps/web/src/app/page.tsx"
    click WEB "https://github.com/midday-ai/v1/blob/main/apps/web/src/actions/subscribe-action.ts"
    click WEB "https://github.com/midday-ai/v1/blob/main/apps/web/src/components/cal-embed.tsx"
    click ANALYTICS "https://github.com/midday-ai/v1/tree/main/packages/analytics"
    click ANALYTICS "https://github.com/midday-ai/v1/blob/main/packages/analytics/src/client.tsx"
    click ANALYTICS "https://github.com/midday-ai/v1/blob/main/packages/analytics/src/server.ts"
    click EMAIL_LIB "https://github.com/midday-ai/v1/tree/main/packages/email"
    click EMAIL_LIB "https://github.com/midday-ai/v1/blob/main/packages/email/emails/welcome.tsx"
    click EMAIL_LIB "https://github.com/midday-ai/v1/blob/main/packages/email/components/logo.tsx"
    click JOBS "https://github.com/midday-ai/v1/tree/main/packages/jobs"
    click JOBS "https://github.com/midday-ai/v1/blob/main/packages/jobs/trigger.config.ts"
    click JOBS "https://github.com/midday-ai/v1/blob/main/packages/jobs/trigger/example.ts"
    click KV "https://github.com/midday-ai/v1/tree/main/packages/kv"
    click KV "https://github.com/midday-ai/v1/blob/main/packages/kv/src/index.ts"
    click KV "https://github.com/midday-ai/v1/blob/main/packages/kv/src/ratelimit.ts"
    click LOGGER "https://github.com/midday-ai/v1/tree/main/packages/logger"
    click LOGGER "https://github.com/midday-ai/v1/blob/main/packages/logger/src/index.ts"
    click SUPA "https://github.com/midday-ai/v1/tree/main/packages/supabase"
    click SUPA "https://github.com/midday-ai/v1/blob/main/packages/supabase/src/clients/client.ts"
    click SUPA "https://github.com/midday-ai/v1/tree/main/packages/supabase/src/queries"
    click SUPA "https://github.com/midday-ai/v1/tree/main/packages/supabase/src/mutations"
    click UI "https://github.com/midday-ai/v1/tree/main/packages/ui"
    click UI "https://github.com/midday-ai/v1/blob/main/packages/ui/src/components/button.tsx"
    click UI "https://github.com/midday-ai/v1/blob/main/packages/ui/src/components/dialog.tsx"
    click UI "https://github.com/midday-ai/v1/blob/main/packages/ui/src/components/input.tsx"
    click UI "https://github.com/midday-ai/v1/blob/main/packages/ui/src/components/tooltip.tsx"
    click TURBO "https://github.com/midday-ai/v1/blob/main/turbo.json"
    click BIOME "https://github.com/midday-ai/v1/blob/main/biome.json"
    click TSCONFIG "https://github.com/midday-ai/v1/blob/main/tsconfig.json"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#1e88e5,stroke-width:1px
    classDef backend fill:#c8e6c9,stroke:#43a047,stroke-width:1px
    classDef libs fill:#fff9c4,stroke:#fdd835,stroke-width:1px
    classDef external fill:#d1c4e9,stroke:#8e24aa,stroke-width:1px
    classDef tooling fill:#b0bec5,stroke:#546e7a,stroke-width:1px
```
