Skip to content

Commit f9aac53

Browse files
authored
docs: overhaul CLAUDE.md with architecture and project guidelines (#149)
1 parent 5da72fb commit f9aac53

File tree

2 files changed

+64
-68
lines changed

2 files changed

+64
-68
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CLAUDE.md

CLAUDE.md

Lines changed: 63 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,66 @@
33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

55
## Project Overview
6-
7-
Ftv is a browser extension for Fansly that adds emote support from popular platforms (Twitch, 7TV, BTTV, FFZ). It's built with:
8-
9-
- **WXT** - Web extension framework
10-
- **Svelte 5** - UI framework with runes
11-
- **TypeScript** - Type safety
12-
- **Tailwind CSS** - Styling
13-
- **PNPM** - Package manager
14-
15-
## Rules
16-
17-
- **ALWAYS** run `pnpm check && pnpm lint` after making changes!
18-
19-
## Architecture
20-
21-
### Content Scripts
22-
23-
The extension uses two main content scripts in `src/entrypoints/`:
24-
25-
- `chat.content.ts` - Main functionality for chat pages (emotes, UI components)
26-
- `home.content.ts` - Home page features
27-
28-
### Entry Points System
29-
30-
The `src/lib/entryPoints/` directory contains modular features that are initialized by the main content script:
31-
32-
- `chatEmotes.ts` - Parses chat messages and replaces text with emote images
33-
- `emoteMenuButton.ts` - Adds emote picker UI to chat input
34-
- `accountCard.ts` - Enhances user profile cards
35-
- `chatUsernameAutoComplete.ts` - Username autocompletion
36-
- `viewCount.ts` - View count tracking
37-
38-
### Emote System
39-
40-
Core emote functionality in `src/lib/emotes/`:
41-
42-
- `emotes.svelte.ts` - Global emote store using Svelte 5 runes
43-
- `providers.svelte.ts` - Emote provider store
44-
- `providers/` - Individual emote platform implementations (Twitch, 7TV, BTTV, FFZ)
45-
46-
### State Management
47-
48-
Uses Svelte 5 runes pattern with reactive stores:
49-
50-
- `$state` for reactive data
51-
- Global stores in `src/lib/emotes/` and `src/lib/state/`
52-
53-
### UI Components
54-
55-
Svelte components in `src/lib/components/` using:
56-
57-
- Bits UI for base components
58-
- Tailwind for styling
59-
- Lucide for icons
60-
61-
### Key Patterns
62-
63-
1. **MutationObserver-based initialization** - Handles Fansly's client-side routing
64-
2. **Provider pattern** - Each emote platform implements the `Provider` interface
65-
3. **Modular entry points** - Features are self-contained and initialized independently
66-
4. **CSS injection via WXT** - Styles are injected through the extension framework
67-
68-
### Development Notes
69-
70-
- Extension targets specific Fansly URLs with regex patterns
71-
- Uses attachment classes to prevent duplicate initialization
72-
- Emotes are fetched asynchronously and cached in reactive stores
73-
- Chat message parsing happens in real-time via MutationObserver
6+
- Name: Ftv
7+
- Description: A browser extension for Fansly that adds emote support from popular platforms (Twitch, 7TV, BTTV, FFZ) and small UI enhancements.
8+
- Key notes:
9+
- Fansly API calls require the signed session token from `localStorage` (`session_active_session`). `FanslyApi` is first constructed with real `window`/`localStorage` and must be initialized outside a shadow root. See `src/lib/api/fansly.svelte.ts`.
10+
- Content logic runs via `MutationObserver` because Fansly uses client‑side routing; only act on whitelisted paths. See `src/entrypoints/chat.content.ts` and `src/entrypoints/home.content.ts`.
11+
- Duplicate work is prevented with attachment classes (e.g., `ftv-attached`, `ftv-feed-suggestions-list-attached`). Always guard DOM injections.
12+
- External services: Fansly (`https://apiv3.fansly.com`), ZerGo0 endpoints (`https://zergo0_bot.zergo0.dev`). All requests should go through `deduplicatedFetch` and caches in `src/lib/utils/`.
13+
- CSS tweaks are injected at runtime; see `src/lib/fanslyStyleFixes.ts` and `src/assets/fanslyStyleFixes.css`.
14+
15+
## Global Rules
16+
17+
- **NEVER** use emojis!
18+
- **NEVER** try to run the dev server!
19+
- **NEVER** try to build in the project directory, always build in the `/tmp` directory!
20+
- **ALWAYS** search for existing code patterns in the codebase and follow them consistently
21+
- **NEVER** use comments in code — code should be self-explanatory
22+
23+
## High-Level Architecture
24+
- Core technologies: WXT, Svelte 5 (runes), TypeScript, Vite, Tailwind CSS.
25+
- Extension entrypoints: `src/entrypoints/chat.content.ts` (chat pages) and `src/entrypoints/home.content.ts` (home/discover).
26+
- Feature modules: `src/lib/entryPoints/*` are initialized by content scripts and attach UI/logic via WXT `createShadowRootUi` + Svelte `mount/unmount`.
27+
- Emote system: `src/lib/emotes/` with runes stores (`emotes.svelte.ts`, `providers.svelte.ts`) and provider implementations in `src/lib/emotes/providers/*` that extend `Provider` and implement `fetchEmotes()`.
28+
- State: Global reactive state in `src/lib/state/state.svelte.ts` using `$state` (runes), including throttled initialization and shared derived data.
29+
- Networking: `src/lib/api/fansly.svelte.ts` and `src/lib/api/zergo0.ts` wrap external calls; request de‑duplication and simple caches live in `src/lib/utils/requestDeduplicator.ts` and `src/lib/utils/cache.ts`.
30+
- Schema/Types source of truth: `src/lib/types.ts`.
31+
32+
## Project Guidelines
33+
34+
### Ftv Extension (root)
35+
- Language: TypeScript
36+
- Framework/Runtime: WXT + Svelte 5 (runes), Vite
37+
- Package Manager: pnpm
38+
- Important Packages: `wxt`, `@wxt-dev/module-svelte`, `svelte`, `vite`, `tailwindcss`, `bits-ui`, `lucide-svelte`, `zod`.
39+
- Checks:
40+
- Syntax Check: `pnpm check`
41+
- Lint: `pnpm lint`
42+
- Claude must run these every time after making changes
43+
- Rules / Conventions:
44+
- **ALWAYS** use Svelte 5 runes (`$state`) for reactive state files under `src/lib/**.svelte.ts`.
45+
- **ALWAYS** mount UI via WXT `createShadowRootUi` and Svelte `mount/unmount`; do not inject directly without an anchor.
46+
- **ALWAYS** guard DOM work with attachment classes to avoid double‑init.
47+
- **ALWAYS** use `deduplicatedFetch` and the simple `Cache<T>` for network/data caching; avoid raw `fetch`.
48+
- **ALWAYS** add emote platforms by subclassing `Provider` in `src/lib/emotes/providers/` and implementing `fetchEmotes()`.
49+
- **ALWAYS** keep CSS tweaks in `fanslyStyleFixes` and `cssInjectionMode: 'ui'`; do not inline arbitrary styles elsewhere.
50+
- **NEVER** assume page reloads; rely on `MutationObserver` + path whitelists.
51+
- **NEVER** scatter API URLs; use the API modules in `src/lib/api/`.
52+
- Useful files:
53+
- `wxt.config.ts` — WXT configuration, MV3/MV2 host permissions.
54+
- `src/entrypoints/chat.content.ts` — Chat page bootstrapping and feature orchestration.
55+
- `src/entrypoints/home.content.ts` — Home/discover bootstrapping.
56+
- `src/lib/entryPoints/*` — Modular feature attach points (emotes, menu button, account card, autocomplete, suggestions, view count).
57+
- `src/lib/emotes/*` — Emote stores and provider implementations.
58+
- `src/lib/state/state.svelte.ts` — Shared runes‑based state.
59+
- `src/lib/api/*` — Fansly and ZerGo0 API wrappers.
60+
- `src/lib/utils/*` — Request de‑duplication and Promise caches.
61+
- `src/assets/fanslyStyleFixes.css` — Injected CSS adjustments.
62+
63+
## Key Architectural Patterns
64+
- MutationObserver + URL whitelist for single‑page routing, with idempotent attachment via classes.
65+
- Provider pattern for emote sources; one interface, multiple platform implementations.
66+
- Svelte 5 runes for state; stores as lightweight classes with `$state` fields.
67+
- WXT UI mounting into shadow roots; CSS injected via dedicated helper and `cssInjectionMode: 'ui'`.
68+
- Request de‑duplication and Promise‑based caching to minimize redundant network calls.

0 commit comments

Comments
 (0)