# nstealth/black-bull-herd-card architecture

> Architecture diagram of the GitHub repository nstealth/black-bull-herd-card, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nstealth/black-bull-herd-card
- Repository: https://github.com/nstealth/black-bull-herd-card

## Overview

#### Purpose and entry points
Black Bull Herd Card is a SvelteKit campaign app for $ANSEM holders: connect a Phantom wallet, read its Solana token balance without signing, derive a tier, generate/share a card, and submit a public X link for an airdrop workflow. The user-facing entry is `src/routes/+page.svelte`; campaign rules are at `src/routes/rules/+page.svelte`; global document/layout concerns live in `src/routes/+layout.svelte` and `src/app.html`.

#### Client application and interaction flow
The main page orchestrates wallet connection, verification, card presentation, sharing, and submission through composable Svelte components. `src/lib/components/molecules/WalletConnect.svelte` is the wallet boundary, while `src/lib/components/molecules/CardPreview.svelte`, `src/lib/components/molecules/SubmitModal.svelte`, and `src/lib/components/molecules/SuccessModal.svelte` represent the result/submission UX. Shared styling and responsive visual system originate in `src/app.css`.

#### Wallet verification API
`src/routes/api/check/[wallet]/+server.ts` exposes a server-side wallet-check endpoint. It is the key trust boundary: clients provide a public wallet address, while server code fetches eligibility data from Solana rather than accepting balance claims. The blockchain integration is isolated in `src/lib/solana.ts`, with RPC concurrency/rate handling in `src/lib/rpcQueue.ts`; cache support is separated in `src/lib/redis.ts`.

#### Solana and eligibility domain
The application uses Solana Web3 read-only token-account queries against the configured mainnet RPC endpoint (Helius recommended). `src/lib/solana.ts` obtains $ANSEM holdings; `src/lib/tiers.ts` maps balances to the five campaign tiers and calculates supply-related statistics. This separation ensures eligibility rules are independent of API transport and UI rendering. No transaction construction, signing, token approval, or wallet credential persistence is part of this architecture.

#### Card generation and assets
`src/lib/cardGenerator.ts` renders a personalized 1024×1024 Canvas card from wallet, balance, percentage, and tier data. Tier-specific artwork is served as static assets under `static/cards/common`, `static/cards/rare`, `static/cards/epic`, `static/cards/legendary`, and `static/cards/mythic`. The generated card is a client-side presentation/share artifact, not an on-chain NFT minting pipeline.

#### Submission and anti-duplicate persistence
`src/routes/api/submit/+server.ts` accepts the wallet identity and public tweet/X URL after the sharing step. It persists campaign entries through Drizzle database access in `src/lib/db/index.ts`, governed by the schema in `src/lib/db/schema.ts`. The database is Neon Postgres; the one-wallet-one-entry constraint is the principal anti-cheat control. Redis/Upstash is optional caching infrastructure rather than the system of record.

#### Runtime and deployment boundaries
The runtime is TypeScript/SvelteKit 2 with Vite and Tailwind, configured by `svelte.config.js`, `vite.config.ts`, and `tailwind.config.js`. Server API routes require Solana RPC and Neon `DATABASE_URL`; optional Upstash Redis uses `REDIS_URL`/`REDIS_TOKEN`. Drizzle migration/schema deployment is configured in `drizzle.config.ts`. Production hosting targets Vercel via `vercel.json`, with client-visible site URL supplied through `VITE_SITE_URL`.

Main entry points: [`src/routes/api/check/[wallet]/+server.ts`](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/api/check/%5Bwallet%5D/%2Bserver.ts) (Wallet check API), [`src/routes/+page.svelte`](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/%2Bpage.svelte) (Campaign page), [`src/routes/api/submit/+server.ts`](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/api/submit/%2Bserver.ts) (Entry submission API), [`vercel.json`](https://github.com/nstealth/black-bull-herd-card/blob/master/vercel.json) (Vercel deployment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["SvelteKit client"]
  node_app_shell["App shell and styles<br/>Svelte layout<br/>[+layout.svelte]"]
  node_campaign_page["Campaign page<br/>Svelte page<br/>[+page.svelte]"]
  node_rules_page["Campaign rules<br/>Svelte page<br/>[+page.svelte]"]
  node_wallet_connect["Wallet connection<br/>Svelte component"]
  node_card_ux["Card and submission UX<br/>Svelte components"]
  node_card_generator["Card generator<br/>Canvas renderer<br/>[cardGenerator.ts]"]
  node_tier_artwork["Tier artwork<br/>Static assets"]
end

subgraph group_server["Server and domain"]
  node_wallet_check_api{{"Wallet check API<br/>SvelteKit endpoint<br/>[+server.ts]"}}
  node_solana_reader["Solana holdings reader<br/>Blockchain integration<br/>[solana.ts]"]
  node_rpc_queue["RPC queue<br/>Rate control<br/>[rpcQueue.ts]"]
  node_tiers["Eligibility tiers<br/>Domain rules<br/>[tiers.ts]"]
  node_submit_api{{"Entry submission API<br/>SvelteKit endpoint<br/>[+server.ts]"}}
end

subgraph group_data["Data and runtime"]
  node_db_access["Drizzle database access<br/>Persistence adapter<br/>[index.ts]"]
  node_db_schema["Campaign entry schema<br/>Drizzle schema<br/>[schema.ts]"]
  node_neon_postgres[("Neon Postgres<br/>System of record")]
  node_redis_cache[("Optional Redis cache<br/>[redis.ts]")]
  node_solana_rpc(("Solana mainnet RPC<br/>External blockchain RPC"))
  node_vercel{{"Vercel deployment<br/>Hosting runtime<br/>[vercel.json]"}}
end

node_app_shell -->|"renders"| node_campaign_page
node_campaign_page -->|"links to"| node_rules_page
node_campaign_page -->|"connects"| node_wallet_connect
node_wallet_connect -->|"public wallet address"| node_wallet_check_api
node_wallet_check_api -->|"verifies holdings"| node_solana_reader
node_solana_reader -->|"queues requests"| node_rpc_queue
node_rpc_queue -->|"read-only queries"| node_solana_rpc
node_wallet_check_api -->|"derives tier"| node_tiers
node_campaign_page -->|"presents result"| node_card_ux
node_card_ux -->|"generates share card"| node_card_generator
node_card_generator -->|"uses tier art"| node_tier_artwork
node_card_ux -->|"wallet and X URL"| node_submit_api
node_submit_api -->|"persists entry"| node_db_access
node_db_access -->|"uses"| node_db_schema
node_db_access -->|"stores entries"| node_neon_postgres
node_wallet_check_api -.->|"optional cache"| node_redis_cache
node_submit_api -.->|"optional cache"| node_redis_cache
node_vercel -->|"hosts"| node_app_shell
node_vercel -->|"runs"| node_wallet_check_api
node_vercel -->|"runs"| node_submit_api

click node_app_shell "https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/%2Blayout.svelte"
click node_campaign_page "https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/%2Bpage.svelte"
click node_rules_page "https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/rules/%2Bpage.svelte"
click node_wallet_connect "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/components/molecules/WalletConnect.svelte"
click node_card_generator "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/cardGenerator.ts"
click node_tier_artwork "https://github.com/nstealth/black-bull-herd-card/tree/master/static/cards/common"
click node_wallet_check_api "https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/api/check/%5Bwallet%5D/%2Bserver.ts"
click node_solana_reader "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/solana.ts"
click node_rpc_queue "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/rpcQueue.ts"
click node_tiers "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/tiers.ts"
click node_submit_api "https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/api/submit/%2Bserver.ts"
click node_db_access "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/db/index.ts"
click node_db_schema "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/db/schema.ts"
click node_redis_cache "https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/redis.ts"
click node_vercel "https://github.com/nstealth/black-bull-herd-card/blob/master/vercel.json"

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_app_shell,node_campaign_page,node_rules_page,node_wallet_connect,node_card_ux,node_card_generator,node_tier_artwork toneBlue
class node_wallet_check_api,node_solana_reader,node_rpc_queue,node_tiers,node_submit_api toneAmber
class node_db_access,node_db_schema,node_neon_postgres,node_redis_cache,node_solana_rpc,node_vercel toneMint
```

## Components

### SvelteKit client

- [App shell and styles](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/%2Blayout.svelte): Svelte layout · Global document, layout, and responsive styling. · `src/routes/+layout.svelte`
- [Campaign page](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/%2Bpage.svelte): Svelte page · Orchestrates connection, verification, card sharing, and entry submission. · `src/routes/+page.svelte`
- [Campaign rules](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/rules/%2Bpage.svelte): Svelte page · `src/routes/rules/+page.svelte`
- [Wallet connection](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/components/molecules/WalletConnect.svelte): Svelte component · Phantom wallet boundary; no signing flow. · `src/lib/components/molecules/WalletConnect.svelte`
- **Card and submission UX**: Svelte components · Preview, submit modal, and success modal.
- [Card generator](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/cardGenerator.ts): Canvas renderer · Creates a client-side 1024×1024 share card. · `src/lib/cardGenerator.ts`
- [Tier artwork](https://github.com/nstealth/black-bull-herd-card/tree/master/static/cards/common): Static assets · Common through mythic card backgrounds. · `static/cards/common`

### Server and domain

- [Wallet check API](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/api/check/%5Bwallet%5D/%2Bserver.ts): SvelteKit endpoint · Trust boundary for public wallet eligibility checks. · `src/routes/api/check/[wallet]/+server.ts`
- [Solana holdings reader](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/solana.ts): Blockchain integration · Read-only $ANSEM token-account queries. · `src/lib/solana.ts`
- [RPC queue](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/rpcQueue.ts): Rate control · Controls RPC concurrency and rate handling. · `src/lib/rpcQueue.ts`
- [Eligibility tiers](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/tiers.ts): Domain rules · Maps balances to five tiers and supply statistics. · `src/lib/tiers.ts`
- [Entry submission API](https://github.com/nstealth/black-bull-herd-card/blob/master/src/routes/api/submit/%2Bserver.ts): SvelteKit endpoint · Accepts wallet identity and public X URL. · `src/routes/api/submit/+server.ts`

### Data and runtime

- [Drizzle database access](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/db/index.ts): Persistence adapter · `src/lib/db/index.ts`
- [Campaign entry schema](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/db/schema.ts): Drizzle schema · Enforces one wallet entry. · `src/lib/db/schema.ts`
- **Neon Postgres**: System of record · Stores airdrop workflow entries.
- [Optional Redis cache](https://github.com/nstealth/black-bull-herd-card/blob/master/src/lib/redis.ts): Cache · Upstash-backed optional cache, not the system of record. · `src/lib/redis.ts`
- **Solana mainnet RPC**: External blockchain RPC · Configured RPC endpoint, with Helius recommended.
- [Vercel deployment](https://github.com/nstealth/black-bull-herd-card/blob/master/vercel.json): Hosting runtime · Production SvelteKit hosting. · `vercel.json`

## Connections

- App shell and styles → Campaign page: renders
- Campaign page → Campaign rules: links to
- Campaign page → Wallet connection: connects
- Wallet connection → Wallet check API: public wallet address
- Wallet check API → Solana holdings reader: verifies holdings
- Solana holdings reader → RPC queue: queues requests
- RPC queue → Solana mainnet RPC: read-only queries
- Wallet check API → Eligibility tiers: derives tier
- Campaign page → Card and submission UX: presents result
- Card and submission UX → Card generator: generates share card
- Card generator → Tier artwork: uses tier art
- Card and submission UX → Entry submission API: wallet and X URL
- Entry submission API → Drizzle database access: persists entry
- Drizzle database access → Campaign entry schema: uses
- Drizzle database access → Neon Postgres: stores entries
- Wallet check API → Optional Redis cache: optional cache
- Entry submission API → Optional Redis cache: optional cache
- Vercel deployment → App shell and styles: hosts
- Vercel deployment → Wallet check API: runs
- Vercel deployment → Entry submission API: runs
