Streams is a chronological ATProto PDS explorer. streams.synthetic.software
streams CONTRIBUTING.md
8.8 kB · 283 lines
Markdown
at main

Contributing #

Contributions welcome, especially new lexicon components for ATProto record types not yet supported.

Setup #

pnpm install
pnpm dev

Requires Node 18+ and pnpm.

Adding a lexicon component #

The lexicon registry at src/lib/lexicons/ maps ATProto NSIDs to Svelte components. Each component receives record and uri props and renders a record in the timeline.

Steps:

  1. Create src/lib/lexicons/<namespace>/MyComponent.svelte

    <script lang="ts">
    	interface Props {
    		record: { $type: string; [key: string]: unknown };
    		uri?: string;
    	}
    
    	let { record, uri }: Props = $props();
    </script>
    
    <article class="record-card flex flex-col gap-1">
    	<p class="text-xs font-semibold opacity-60">Display Name</p>
    	<!-- render record -->
    </article>
    

    If generated types are available for the lexicon (via @atproto/lex), use them instead of a generic interface. See BlueskyPost.svelte for a full example with embeds, or FeedLike.svelte for a minimal one.

  2. Register in src/lib/lexicons/<namespace>/index.ts:

    import type { RegistryEntry } from '../types';
    import MyComponent from './MyComponent.svelte';
    
    export const entries: Record<string, RegistryEntry | null> = {
    	'com.example.foo': {
    		component: MyComponent,
    		displayName: 'Human Name',
    		recordUrl: (record, atUri) => `https://example.com/...` // optional — links the record to its source
    	}
    };
    

    Null entries suppress the fallback JSON renderer for noisy types you don't want displayed:

    'com.example.noisy': null
    
  3. If it's a new namespace, import the entries in src/lib/lexicons/index.ts:

    import { entries as comExample } from './com.example/index';
    // ...
    const registry = { ...appBsky, ...comExample, ... };
    

Component standards #

Typing the record prop #

Prefer generated types from $lib/generated-lexicons/ when available:

import type { Main } from '$lib/generated-lexicons/app/bsky/feed/post.defs.js';
record: Main;

When no generated type exists, use an inline interface. Mark fields that may be absent as optional, and include [key: string]: unknown as a catch-all:

record: {
	$type: string;
	title?: string;
	description?: string;
	createdAt?: string;
	[key: string]: unknown;
};

Always include $type: string — it's needed by getRecordUrl and getDisplayName.

Wrapper element #

Every component renders an <article> as its root:

<article class="record-card flex flex-col gap-1">...</article>
  • record-card is the base class (used by Stream.svelte for layout)
  • gap-1 for standard card density; gap-2 acceptable for richer components (posts with images, profiles with avatars)
  • Do not add borders or vertical padding — Stream.svelte handles card spacing

Type label #

Each card starts with a type label:

<p class="text-xs font-semibold opacity-60">Human-Readable Type</p>

This should match the displayName in the registry entry.

Text sizing #

Element Class
Type label text-xs font-semibold opacity-60
Primary content (title, text body) default size, optionally font-semibold
Secondary content (description) text-sm
Metadata (dates, URLs, small labels) text-xs

Opacity for visual hierarchy #

Purpose Value
Type label opacity-60
Secondary text (descriptions) opacity-70
Metadata (dates, tertiary links) opacity-40 to opacity-50

All external links:

<a href={url} target="_blank" rel="noopener">...</a>
  • Use rel="noopener" consistently (not noopener noreferrer)
  • Use class="text-inherit" when the link should blend with surrounding text
  • Suffix with ↗ for links that navigate to external apps (e.g., bsky.app ↗, profile ↗)

Optional fields #

Use {#if} blocks for conditional rendering:

{#if record.description}
	<p class="text-sm opacity-70">{record.description}</p>
{/if}

For arrays, filter empty values before checking length:

const topics = $derived((record.topics ?? []).filter((t) => t.trim() !== ''));
{#if topics.length > 0}
	<div class="flex flex-wrap gap-1">
		{#each topics as topic (topic)}
			<span class="rounded bg-current/10 px-1.5 py-0.5 text-xs">{topic}</span>
		{/each}
	</div>
{/if}

Dates #

Format with toLocaleString() and wrap in <time>:

const date = $derived(record.createdAt ? new Date(record.createdAt).toLocaleString() : null);
{#if date}<time class="text-xs opacity-40">{date}</time>{/if}

Blob / image URLs #

Bluesky CDN (only for app.bsky components):

`https://cdn.bsky.app/img/${endpoint}/plain/${did}/${cid}@jpeg`;

Where endpoint is feed_thumbnail, avatar, etc. This is faster and doesn't require context.

PDS blob endpoint (everything else):

import { getContext } from 'svelte';

const pdsCtx = getContext<{ url: string }>('pdsUrl');
const did = $derived(uri ? uri.replace(/^at:\/\//, '').split('/')[0] : null);
const cid = $derived(blobCid(record.photo));
const src = $derived(
	pdsCtx?.url && did && cid
		? `${pdsCtx.url}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${cid}`
		: null
);

In both cases:

  • Extract CID via blobCid() from $lib/lexicons/utils
  • Extract DID from the uri prop
  • Guard against null — don't render <img> if src is null

recordUrl in registry entries #

Maps a record to its canonical web URL. Signature:

recordUrl: (record: Record<string, unknown>, atUri: string) => string | null;

Common patterns:

Strategy When to use Example
Parse atUri URL structure mirrors AT URI social.grain.gallery
Extract from record Record contains its own URL place.stream.livestream
Combine both Need data from record + DID from URI sh.tangled.actor.profile

Return null when a URL can't be constructed. If the URL pattern isn't known yet, omit recordUrl and leave a // TODO comment in the registry.

uri prop usage #

Only destructure uri if you need it. Common uses:

  • DID extraction for blob URLs
  • Passing to getRecordUrl()

If your component doesn't use uri, omit it from destructuring:

let { record }: Props = $props();

Shared components (_shared/) #

Components in _shared/ are used directly by namespace components — they are not registered in the registry. Use this for record types that share the same shape across multiple namespaces (e.g., GraphFollow.svelte handles follow records from bsky, grain, and tangled).

Shared components should use getDisplayName(record.$type) to show the correct label for whichever namespace is using them.

Shared utilities #

Import from $lib/lexicons/utils — do not duplicate logic in components:

  • blobCid(blob) — extract CID string from any blob shape (CBOR, JSON, legacy)
  • atUriToBskyUrl(atUri) — parse AT URI to bsky.app URL (Bluesky-specific)

Code style #

  • Svelte 5 runes — $props(), $state(), $derived(), $effect() (no legacy export let)
  • Tabs, single quotes, no trailing commas, width=100 (enforced by Prettier — run pnpm format)
  • Tailwind v4 for styles; avoid <style> blocks unless structurally necessary
  • $lib/ alias for src/lib/

Checklist #

Before submitting, verify:

Submitting #

Open a pull request with a brief description of the record type and a link to the lexicon spec if available.