# kaidesalo/spellbranch architecture

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

- Interactive diagram: https://gitdiagram.com/kaidesalo/spellbranch
- Repository: https://github.com/kaidesalo/spellbranch

## Overview

Spellbranch is a social Magic deck-building app. Players authenticate, find cards through Scryfall, build and organize decks, then share independent forks, compare branches, and comment; friends, favorites, and personal collections support that workflow. Server pages and actions use query/action modules and a backend-selected repository, with local JSON storage or Supabase. The README documents the major capabilities and backend split; source excerpts confirm selected search, deck-action, session, query, and rate-limit relationships. Several feature implementations were not sampled, so their documented links are shown from README evidence.

Main entry points: [`src/components/cards/card-search.tsx`](https://github.com/kaidesalo/spellbranch/blob/main/src/components/cards/card-search.tsx) (Card search UI), [`src/app/decks/[id]/page.tsx`](https://github.com/kaidesalo/spellbranch/blob/main/src/app/decks/%5Bid%5D/page.tsx) (Deck pages), [`src/lib/actions/decks.ts`](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/decks.ts) (Deck operations), [`src/lib/data/index.ts`](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/data/index.ts) (Backend repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and community"]
  node_auth["Sign-in and profiles<br/>[auth.ts]"]
  node_friends["Friend requests<br/>[friends.ts]"]
end

subgraph group_cards["Cards and collection"]
  node_favorites["Favorite cards<br/>[favorites.ts]"]
  node_searchui["Card search UI<br/>[card-search.tsx]"]
  node_collection["Personal collection<br/>[collection.ts]"]
end

subgraph group_decks["Deck building and sharing"]
  node_deckpages["Deck pages<br/>[page.tsx]"]
  node_deckactions["Deck operations<br/>[decks.ts]"]
  node_deckqueries["Deck reads<br/>[decks.ts]"]
  node_decklist["Deck import and export"]
  node_compare["Branch comparison<br/>[page.tsx]"]
  node_comments["Deck comments<br/>[comments.ts]"]
  node_browse["Browse and dashboard<br/>[page.tsx]"]
end

subgraph group_services["Application services"]
  node_searchapi["Scryfall search route<br/>[route.ts]"]
  node_scryfall["Scryfall API client<br/>[client.ts]"]
  node_session["Session and access<br/>[session.ts]"]
  node_queries["Feature queries"]
  node_actions["Server actions"]
  node_limiter["Rate limiting<br/>[index.ts]"]
  node_news["MTG news<br/>[mtg-news.ts]"]
end

subgraph group_storage["Persistence"]
  node_repository["Backend repository<br/>[index.ts]"]
  node_local[("Local JSON store<br/>[store.ts]")]
  node_supabase[("Supabase data and auth<br/>[supabase.ts]")]
end

node_player(("Player"))

node_player -->|"signs in"| node_auth
node_player -->|"searches cards"| node_searchui
node_searchui -.->|"requests results"| node_searchapi
node_searchapi -->|"queries cards"| node_scryfall
node_scryfall -.->|"returns card data"| node_player
node_searchui -->|"adds a card"| node_deckactions
node_searchui -->|"favorites a card"| node_favorites
node_player -->|"manages friends"| node_friends
node_player -->|"tracks cards"| node_collection
node_player -->|"builds and views"| node_deckpages
node_deckpages -->|"edits deck"| node_deckactions
node_deckpages -->|"loads deck"| node_deckqueries
node_deckpages -->|"imports or exports"| node_decklist
node_player -->|"compares branches"| node_compare
node_player -->|"comments on decks"| node_comments
node_player -->|"browses decks"| node_browse
node_deckqueries -->|"reads through"| node_repository
node_deckactions -->|"writes through"| node_repository
node_auth -->|"uses sessions"| node_session
node_repository -->|"selects local backend"| node_local
node_repository -->|"selects Supabase backend"| node_supabase
node_session -->|"reads local users"| node_local
node_session -->|"checks Supabase claims"| node_supabase
node_deckactions -->|"checks limits"| node_limiter
node_auth -->|"checks limits"| node_limiter
node_browse -->|"shows MTG news"| node_news

click node_auth "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/auth.ts"
click node_friends "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/friends.ts"
click node_favorites "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/favorites.ts"
click node_searchui "https://github.com/kaidesalo/spellbranch/blob/main/src/components/cards/card-search.tsx"
click node_searchapi "https://github.com/kaidesalo/spellbranch/blob/main/src/app/api/scryfall/search/route.ts"
click node_scryfall "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/scryfall/client.ts"
click node_collection "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/collection.ts"
click node_deckpages "https://github.com/kaidesalo/spellbranch/blob/main/src/app/decks/%5Bid%5D/page.tsx"
click node_deckactions "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/decks.ts"
click node_deckqueries "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/queries/decks.ts"
click node_decklist "https://github.com/kaidesalo/spellbranch/tree/main/src/lib/decklist"
click node_compare "https://github.com/kaidesalo/spellbranch/blob/main/src/app/decks/%5Bid%5D/compare/page.tsx"
click node_comments "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/comments.ts"
click node_browse "https://github.com/kaidesalo/spellbranch/blob/main/src/app/browse/page.tsx"
click node_session "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/auth/session.ts"
click node_queries "https://github.com/kaidesalo/spellbranch/tree/main/src/lib/queries"
click node_actions "https://github.com/kaidesalo/spellbranch/tree/main/src/lib/actions"
click node_repository "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/data/index.ts"
click node_local "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/data/store.ts"
click node_supabase "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/data/supabase.ts"
click node_limiter "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/rate-limit/index.ts"
click node_news "https://github.com/kaidesalo/spellbranch/blob/main/src/lib/news/mtg-news.ts"

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_auth,node_friends toneBlue
class node_favorites,node_searchui,node_collection toneAmber
class node_deckpages,node_deckactions,node_deckqueries,node_decklist,node_compare,node_comments,node_browse toneMint
class node_searchapi,node_scryfall,node_session,node_queries,node_actions,node_limiter,node_news toneRose
class node_repository,node_local,node_supabase,node_player toneIndigo
```

## Components

### Identity and community

- [Sign-in and profiles](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/auth.ts): `src/lib/actions/auth.ts`
- [Friend requests](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/friends.ts): `src/lib/actions/friends.ts`

### Cards and collection

- [Favorite cards](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/favorites.ts): `src/lib/actions/favorites.ts`
- [Card search UI](https://github.com/kaidesalo/spellbranch/blob/main/src/components/cards/card-search.tsx): `src/components/cards/card-search.tsx`
- [Personal collection](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/collection.ts): `src/lib/collection.ts`

### Deck building and sharing

- [Deck pages](https://github.com/kaidesalo/spellbranch/blob/main/src/app/decks/%5Bid%5D/page.tsx): `src/app/decks/[id]/page.tsx`
- [Deck operations](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/decks.ts): `src/lib/actions/decks.ts`
- [Deck reads](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/queries/decks.ts): `src/lib/queries/decks.ts`
- [Deck import and export](https://github.com/kaidesalo/spellbranch/tree/main/src/lib/decklist): `src/lib/decklist`
- [Branch comparison](https://github.com/kaidesalo/spellbranch/blob/main/src/app/decks/%5Bid%5D/compare/page.tsx): `src/app/decks/[id]/compare/page.tsx`
- [Deck comments](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/actions/comments.ts): `src/lib/actions/comments.ts`
- [Browse and dashboard](https://github.com/kaidesalo/spellbranch/blob/main/src/app/browse/page.tsx): `src/app/browse/page.tsx`

### Application services

- [Scryfall search route](https://github.com/kaidesalo/spellbranch/blob/main/src/app/api/scryfall/search/route.ts): `src/app/api/scryfall/search/route.ts`
- [Scryfall API client](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/scryfall/client.ts): `src/lib/scryfall/client.ts`
- [Session and access](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/auth/session.ts): `src/lib/auth/session.ts`
- [Feature queries](https://github.com/kaidesalo/spellbranch/tree/main/src/lib/queries): `src/lib/queries`
- [Server actions](https://github.com/kaidesalo/spellbranch/tree/main/src/lib/actions): `src/lib/actions`
- [Rate limiting](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/rate-limit/index.ts): `src/lib/rate-limit/index.ts`
- [MTG news](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/news/mtg-news.ts): `src/lib/news/mtg-news.ts`

### Persistence

- [Backend repository](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/data/index.ts): `src/lib/data/index.ts`
- [Local JSON store](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/data/store.ts): `src/lib/data/store.ts`
- [Supabase data and auth](https://github.com/kaidesalo/spellbranch/blob/main/src/lib/data/supabase.ts): `src/lib/data/supabase.ts`

### Other components

- **Player**

## Connections

- Player → Sign-in and profiles: signs in
- Player → Card search UI: searches cards
- Card search UI → Scryfall search route: requests results
- Scryfall search route → Scryfall API client: queries cards (evidence: `src/app/api/scryfall/search/route.ts`)
- Scryfall API client → Player: returns card data
- Card search UI → Deck operations: adds a card (evidence: `src/components/cards/card-search.tsx`)
- Card search UI → Favorite cards: favorites a card (evidence: `src/components/cards/card-search.tsx`)
- Player → Friend requests: manages friends
- Player → Personal collection: tracks cards
- Player → Deck pages: builds and views
- Deck pages → Deck operations: edits deck
- Deck pages → Deck reads: loads deck (evidence: `src/app/decks/[id]/page.tsx`)
- Deck pages → Deck import and export: imports or exports
- Player → Branch comparison: compares branches
- Player → Deck comments: comments on decks
- Player → Browse and dashboard: browses decks
- Deck reads → Backend repository: reads through (evidence: `src/lib/queries/decks.ts`)
- Deck operations → Backend repository: writes through (evidence: `src/lib/actions/decks.ts`)
- Sign-in and profiles → Session and access: uses sessions (evidence: `src/lib/actions/auth.ts`)
- Backend repository → Local JSON store: selects local backend
- Backend repository → Supabase data and auth: selects Supabase backend
- Session and access → Local JSON store: reads local users (evidence: `src/lib/auth/session.ts`)
- Session and access → Supabase data and auth: checks Supabase claims (evidence: `src/lib/auth/session.ts`)
- Deck operations → Rate limiting: checks limits (evidence: `src/lib/actions/decks.ts`)
- Sign-in and profiles → Rate limiting: checks limits (evidence: `src/lib/actions/auth.ts`)
- Browse and dashboard → MTG news: shows MTG news
