# arahmatiiii/midnight-bsh architecture

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

- Interactive diagram: https://gitdiagram.com/arahmatiiii/midnight-bsh
- Repository: https://github.com/arahmatiiii/midnight-bsh

## Overview

Midnight BSH is a wallet-authenticated social app for short posts and votes during a configurable night window, with certificate-gated content and a morning highlights archive. The main workflow connects a wallet, loads the live feed, and lets signed-in users post or vote when the server-side night gate permits; certificates and profile setup are separate branches. The graph also includes the documented rollover and archive stages. Edges reflect shown route calls and explicit README behavior; unsampled UI and rollover internals are represented at their exact enclosing paths.

Main entry points: [`src/app/api/posts/route.ts`](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/posts/route.ts) (Post API), [`src/lib/prisma.ts`](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/prisma.ts) (Postgres database), [`src/lib/auth.ts`](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/auth.ts) (Session lookup), [`src/app/page.tsx`](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/page.tsx) (Live feed)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web experience"]
  node_profileui["Profile page<br/>[page.tsx]"]
  node_feedui["Live feed<br/>[page.tsx]"]
  node_composer["Post composer<br/>[post-composer.tsx]"]
  node_postcard["Post card<br/>[post-card.tsx]"]
  node_archiveui["Archive page<br/>[page.tsx]"]
end

subgraph group_identity["Wallet identity"]
  node_wallet["Wallet provider<br/>[wallet-context.tsx]"]
  node_authapi["Auth routes"]
  node_auth["Session lookup<br/>[auth.ts]"]
  node_session["Session cookie<br/>[session.ts]"]
  node_profileapi["Profile API<br/>[route.ts]"]
end

subgraph group_content["Nightly content"]
  node_postapi["Post API<br/>[route.ts]"]
  node_voteapi["Vote API<br/>[route.ts]"]
  node_nightstatus["Night status API<br/>[route.ts]"]
  node_nightlogic["Night window logic<br/>[night.ts]"]
  node_nightdata["Night records<br/>[nights.ts]"]
  node_serialize["Post serialization<br/>[posts.ts]"]
end

subgraph group_certs["Certificates"]
  node_certui["Certificate grid"]
  node_certapi["Certificate API<br/>[route.ts]"]
  node_claimapi["Certificate claims<br/>[route.ts]"]
end

subgraph group_archive["Night archive"]
  node_cron["Nightly rollover<br/>[route.ts]"]
  node_archiveapi["Archive API<br/>[route.ts]"]
end

node_visitor(("Visitor"))
node_ethereum(("Injected wallet"))
node_db[("Postgres database<br/>[prisma.ts]")]

node_visitor -->|"connects"| node_wallet
node_wallet -->|"requests signature"| node_ethereum
node_wallet -->|"requests nonce, verifies"| node_authapi
node_authapi -->|"creates session"| node_session
node_auth -->|"reads session"| node_session
node_auth -->|"looks up user"| node_db
node_visitor -->|"views feed"| node_feedui
node_feedui -->|"loads posts"| node_postapi
node_feedui -.->|"loads status"| node_nightstatus
node_feedui -->|"renders"| node_composer
node_feedui -->|"renders"| node_postcard
node_composer -.->|"submits post"| node_postapi
node_postcard -.->|"submits vote"| node_voteapi
node_postapi -->|"checks user"| node_auth
node_postapi -->|"checks window"| node_nightlogic
node_postapi -->|"gets current night"| node_nightdata
node_postapi -->|"serializes posts"| node_serialize
node_postapi -->|"reads, creates posts"| node_db
node_voteapi -->|"checks user"| node_auth
node_voteapi -->|"checks window"| node_nightlogic
node_voteapi -->|"records vote"| node_db
node_nightstatus -->|"computes status"| node_nightlogic
node_profileui -.->|"updates profile"| node_profileapi
node_profileapi -->|"checks user"| node_auth
node_profileapi -->|"reads, updates user"| node_db
node_profileui -->|"renders"| node_certui
node_certui -.->|"loads certificates"| node_certapi
node_certapi -->|"checks user"| node_auth
node_certapi -->|"reads certificates"| node_db
node_certui -.->|"claims badge"| node_claimapi
node_claimapi -->|"checks user"| node_auth
node_claimapi -->|"stores claim"| node_db
node_cron -->|"finds night boundary"| node_nightlogic
node_cron -->|"archives summaries"| node_db
node_archiveui -.->|"loads highlights"| node_archiveapi
node_archiveapi -->|"reads summaries"| node_db

click node_wallet "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/wallet-context.tsx"
click node_authapi "https://github.com/arahmatiiii/midnight-bsh/tree/main/src/app/api/auth"
click node_auth "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/auth.ts"
click node_session "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/session.ts"
click node_profileui "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/profile/page.tsx"
click node_profileapi "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/profile/route.ts"
click node_feedui "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/page.tsx"
click node_composer "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/components/post-composer.tsx"
click node_postcard "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/components/post-card.tsx"
click node_postapi "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/posts/route.ts"
click node_voteapi "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/posts/%5BpostId%5D/vote/route.ts"
click node_nightstatus "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/night/status/route.ts"
click node_nightlogic "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/night.ts"
click node_nightdata "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/nights.ts"
click node_serialize "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/posts.ts"
click node_certui "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/components/certificate-grid.tsx"
click node_certapi "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/certificates/route.ts"
click node_claimapi "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/certificates/claim/route.ts"
click node_db "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/prisma.ts"
click node_cron "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/cron/nightly-rollover/route.ts"
click node_archiveapi "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/archive/route.ts"
click node_archiveui "https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/archive/page.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_profileui,node_feedui,node_composer,node_postcard,node_archiveui toneBlue
class node_wallet,node_authapi,node_auth,node_session,node_profileapi,node_db toneAmber
class node_postapi,node_voteapi,node_nightstatus,node_nightlogic,node_nightdata,node_serialize toneMint
class node_certui,node_certapi,node_claimapi toneRose
class node_cron,node_archiveapi,node_visitor,node_ethereum toneIndigo
```

## Components

### Web experience

- [Profile page](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/profile/page.tsx): `src/app/profile/page.tsx`
- [Live feed](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Post composer](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/components/post-composer.tsx): `src/components/post-composer.tsx`
- [Post card](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/components/post-card.tsx): `src/components/post-card.tsx`
- [Archive page](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/archive/page.tsx): `src/app/archive/page.tsx`

### Wallet identity

- [Wallet provider](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/wallet-context.tsx): `src/lib/wallet-context.tsx`
- [Auth routes](https://github.com/arahmatiiii/midnight-bsh/tree/main/src/app/api/auth): `src/app/api/auth`
- [Session lookup](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Session cookie](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/session.ts): `src/lib/session.ts`
- [Profile API](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/profile/route.ts): `src/app/api/profile/route.ts`

### Nightly content

- [Post API](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/posts/route.ts): `src/app/api/posts/route.ts`
- [Vote API](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/posts/%5BpostId%5D/vote/route.ts): `src/app/api/posts/[postId]/vote/route.ts`
- [Night status API](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/night/status/route.ts): `src/app/api/night/status/route.ts`
- [Night window logic](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/night.ts): `src/lib/night.ts`
- [Night records](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/nights.ts): `src/lib/nights.ts`
- [Post serialization](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/posts.ts): `src/lib/posts.ts`

### Certificates

- [Certificate grid](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/components/certificate-grid.tsx): `src/components/certificate-grid.tsx`
- [Certificate API](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/certificates/route.ts): `src/app/api/certificates/route.ts`
- [Certificate claims](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/certificates/claim/route.ts): `src/app/api/certificates/claim/route.ts`

### Night archive

- [Nightly rollover](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/cron/nightly-rollover/route.ts): `src/app/api/cron/nightly-rollover/route.ts`
- [Archive API](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/app/api/archive/route.ts): `src/app/api/archive/route.ts`

### Other components

- **Visitor**
- **Injected wallet**
- [Postgres database](https://github.com/arahmatiiii/midnight-bsh/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`

## Connections

- Visitor → Wallet provider: connects (evidence: `src/lib/wallet-context.tsx`)
- Wallet provider → Injected wallet: requests signature (evidence: `src/lib/wallet-context.tsx`)
- Wallet provider → Auth routes: requests nonce, verifies (evidence: `src/lib/wallet-context.tsx`)
- Auth routes → Session cookie: creates session (evidence: `src/app/api/auth/verify/route.ts`)
- Session lookup → Session cookie: reads session (evidence: `src/lib/auth.ts`)
- Session lookup → Postgres database: looks up user (evidence: `src/lib/auth.ts`)
- Visitor → Live feed: views feed (evidence: `src/app/page.tsx`)
- Live feed → Post API: loads posts (evidence: `src/app/api/posts/route.ts`)
- Live feed → Night status API: loads status
- Live feed → Post composer: renders (evidence: `src/app/page.tsx`)
- Live feed → Post card: renders (evidence: `src/app/page.tsx`)
- Post composer → Post API: submits post
- Post card → Vote API: submits vote
- Post API → Session lookup: checks user (evidence: `src/app/api/posts/route.ts`)
- Post API → Night window logic: checks window (evidence: `src/app/api/posts/route.ts`)
- Post API → Night records: gets current night (evidence: `src/app/api/posts/route.ts`)
- Post API → Post serialization: serializes posts (evidence: `src/app/api/posts/route.ts`)
- Post API → Postgres database: reads, creates posts (evidence: `src/app/api/posts/route.ts`)
- Vote API → Session lookup: checks user (evidence: `src/app/api/posts/[postId]/vote/route.ts`)
- Vote API → Night window logic: checks window (evidence: `src/app/api/posts/[postId]/vote/route.ts`)
- Vote API → Postgres database: records vote (evidence: `src/app/api/posts/[postId]/vote/route.ts`)
- Night status API → Night window logic: computes status (evidence: `src/app/api/night/status/route.ts`)
- Profile page → Profile API: updates profile
- Profile API → Session lookup: checks user (evidence: `src/app/api/profile/route.ts`)
- Profile API → Postgres database: reads, updates user (evidence: `src/app/api/profile/route.ts`)
- Profile page → Certificate grid: renders (evidence: `src/app/profile/page.tsx`)
- Certificate grid → Certificate API: loads certificates
- Certificate API → Session lookup: checks user (evidence: `src/app/api/certificates/route.ts`)
- Certificate API → Postgres database: reads certificates (evidence: `src/app/api/certificates/route.ts`)
- Certificate grid → Certificate claims: claims badge
- Certificate claims → Session lookup: checks user (evidence: `src/app/api/certificates/claim/route.ts`)
- Certificate claims → Postgres database: stores claim (evidence: `src/app/api/certificates/claim/route.ts`)
- Nightly rollover → Night window logic: finds night boundary (evidence: `src/app/api/cron/nightly-rollover/route.ts`)
- Nightly rollover → Postgres database: archives summaries (evidence: `src/app/api/cron/nightly-rollover/route.ts`)
- Archive page → Archive API: loads highlights
- Archive API → Postgres database: reads summaries (evidence: `src/app/api/archive/route.ts`)
