forked from coracle/flotilla
Add AGENTS.md
This commit is contained in:
@@ -0,0 +1,254 @@
|
||||
## Project Overview
|
||||
|
||||
Flotilla is a Nostr "relays as groups" community chat client. It implements NIP-29 (relay-based groups) to create Discord-like spaces (servers) and rooms (channels).
|
||||
|
||||
**Tech Stack:**
|
||||
|
||||
- SvelteKit 5.48+ with TypeScript 5.9+
|
||||
- Capacitor for cross-platform (Web/PWA, Android, iOS)
|
||||
- TailwindCSS + DaisyUI for styling
|
||||
- Welshman library suite for Nostr protocol
|
||||
- IndexedDB for local storage
|
||||
- Vite for building
|
||||
|
||||
**Key Concepts:**
|
||||
|
||||
- **Spaces** - Relays used as community groups (like Discord servers)
|
||||
- **Rooms** - NIP-29 groups within spaces (like Discord channels), identified by `h`
|
||||
- **Chats** - Direct message conversations (NIP-04/NIP-44 encrypted)
|
||||
|
||||
## Architecture & Dependency Graph
|
||||
|
||||
The project follows a **strict acyclic dependency hierarchy**:
|
||||
|
||||
```
|
||||
routes/ (top layer - can depend on anything)
|
||||
↓
|
||||
app/components/ (can depend on app/* and lib/*)
|
||||
↓
|
||||
app/core/ & app/util/ (can only depend on lib/*)
|
||||
↓
|
||||
lib/ (can only depend on external libraries)
|
||||
↓
|
||||
external libraries (bottom layer)
|
||||
```
|
||||
|
||||
**Import Ordering Convention (CRITICAL):**
|
||||
Always sort imports by dependency level:
|
||||
|
||||
1. Third-party libraries first
|
||||
2. Then `lib/` imports
|
||||
3. Then `app/` imports
|
||||
|
||||
Example:
|
||||
|
||||
```typescript
|
||||
import {derived} from "svelte/store"
|
||||
import {throttle} from "throttle-debounce"
|
||||
import {Dialog} from "$lib/components"
|
||||
import {repository} from "$app/core/state"
|
||||
```
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
src/
|
||||
├── lib/ # Generic reusable code
|
||||
│ ├── components/ # 38 UI components (Button, Dialog, etc.)
|
||||
│ ├── html.ts # DOM utilities
|
||||
│ ├── indexeddb.ts # IndexedDB helpers
|
||||
│ └── util.ts # Generic utilities
|
||||
│
|
||||
├── app/
|
||||
│ ├── core/
|
||||
│ │ ├── state.ts # State management, stores, constants (687 lines)
|
||||
│ │ ├── commands.ts # Publishing events and other write operations (440+ lines)
|
||||
│ │ ├── requests.ts # Loading data from network (191 lines)
|
||||
│ │ ├── sync.ts # Data synchronization (296 lines)
|
||||
│ │ └── storage.ts # IndexedDB setup
|
||||
│ │
|
||||
│ ├── util/
|
||||
│ │ ├── notifications.ts # Push notifications (731 lines)
|
||||
│ │ ├── policies.ts # Relay policies
|
||||
│ │ ├── routes.ts # Routing helpers
|
||||
│ │ ├── modal.ts # Modal management
|
||||
│ │ ├── toast.ts # Toast notifications
|
||||
│ │ ├── theme.ts # Theme switching
|
||||
│ │ └── keyboard.ts # Keyboard handling
|
||||
│ │
|
||||
│ ├── editor/ # Rich text editor config
|
||||
│ │ ├── index.ts # TipTap setup with Nostr integration
|
||||
│ │ ├── EditorContent.svelte
|
||||
│ │ └── MentionNodeView.ts
|
||||
│ │
|
||||
│ └── components/ # 188 app-specific components
|
||||
│ ├── Space*.svelte # Space/relay management
|
||||
│ ├── Room*.svelte # Room/channel management
|
||||
│ ├── Chat*.svelte # Direct messaging
|
||||
│ ├── Profile*.svelte # User profiles
|
||||
│ ├── Thread*.svelte # Threaded posts
|
||||
│ └── ...
|
||||
│
|
||||
├── routes/ # SvelteKit file-based routing
|
||||
│ ├── +layout.svelte # Root layout (sync logic here)
|
||||
│ ├── spaces/ # Space management
|
||||
│ │ └── [relay]/ # Specific space
|
||||
│ │ ├── chat/ # Space chat
|
||||
│ │ ├── threads/ # Thread posts
|
||||
│ │ ├── calendar/ # Events
|
||||
│ │ └── [h]/ # Specific room (h = room id)
|
||||
│ ├── chat/ # Direct messages
|
||||
│ ├── settings/ # User settings
|
||||
│ └── [bech32]/ # Bech32 entity viewer
|
||||
│
|
||||
├── assets/icons/ # ~1,277 SVG icons
|
||||
├── app.html # HTML template
|
||||
├── app.css # Global styles
|
||||
└── types.d.ts # Type definitions
|
||||
```
|
||||
|
||||
## State Management
|
||||
|
||||
**Core Principles:**
|
||||
|
||||
- Use Svelte 4 **stores** for all state (NOT runes outside UI components)
|
||||
- Most global state flows through Welshman's `repository` (unidirectional)
|
||||
- Query state using `deriveEventsMapped` or `deriveProfile` etc
|
||||
- Update state by publishing events via `publishThunk`
|
||||
|
||||
**Thunks:**
|
||||
|
||||
- Reduce UI latency by handling signatures and sending in background
|
||||
- Return status that should be displayed to user
|
||||
- Allow cancellation and error handling
|
||||
- Immediately publish to local repository for optimistic updates
|
||||
|
||||
## Nostr Integration
|
||||
|
||||
**Welshman Library Suite:**
|
||||
|
||||
- `@welshman/app` - High-level state (pubkey, signer, repository, tracker)
|
||||
- `@welshman/net` - Network layer (Pool, Socket, load, pull, request)
|
||||
- `@welshman/store` - Svelte integration (deriveEventsMapped, etc.)
|
||||
- `@welshman/util` - Event utilities (kinds, tags, validation)
|
||||
- `@welshman/signer` - Signing abstraction (NIP-01, NIP-07, NIP-46)
|
||||
- `@welshman/router` - Relay routing (inbox/outbox model)
|
||||
- `@welshman/editor` - Rich text editor with Nostr
|
||||
- `@welshman/content` - Content parsing
|
||||
- `@welshman/feeds` - Feed management
|
||||
|
||||
**Key NIPs Implemented:**
|
||||
|
||||
- NIP-01: Basic protocol
|
||||
- NIP-44/59/17: Encrypted DMs
|
||||
- NIP-07: Browser extension signing
|
||||
- NIP-19: Bech32 encoding
|
||||
- NIP-29: Relay-based Groups
|
||||
- NIP-42: Relay authentication
|
||||
- NIP-43: Relay membership
|
||||
- NIP-46: Nostr Connect (remote signing)
|
||||
- NIP-57: Lightning Zaps
|
||||
|
||||
## Development Conventions
|
||||
|
||||
**Component Parameterization:**
|
||||
|
||||
- Only pass entity identifiers (`url` for spaces, `h` for rooms)
|
||||
- Derive all other data inside the component from identifiers
|
||||
- Example: Don't pass `members` prop, derive it from `h` inside component
|
||||
|
||||
**Code Style:**
|
||||
|
||||
- **No `null`** - only use `undefined`
|
||||
- Svelte 5 runes (`$state`, `$derived`, `$effect`) only in UI components
|
||||
- TailwindCSS and DaisyUI styling
|
||||
- Only add comments for really weird stuff
|
||||
- Do not call functions in components unless a parameter is reactive. Instead, use a svelte store or rune to make it reactive.
|
||||
- Do not use `any`. If there are type errors related to `unknown`, they are likely because the upstream definition of the data is incorrect.
|
||||
|
||||
## Common Tasks
|
||||
|
||||
### Adding a New Component
|
||||
|
||||
1. Determine if it's generic (`lib/components/`) or app-specific (`app/components/`)
|
||||
2. Follow naming convention: `PascalCase.svelte`
|
||||
3. Import in dependency order (3rd party → lib → app)
|
||||
4. Use stores for state, runes only for UI reactivity
|
||||
|
||||
### Creating a New Route
|
||||
|
||||
1. Add to `src/routes/` following SvelteKit conventions
|
||||
2. Use `+page.svelte` for page component
|
||||
3. Use `+layout.svelte` for shared layouts
|
||||
4. Top-level sync logic goes in root `+layout.svelte`
|
||||
|
||||
### Loading Data from Network
|
||||
|
||||
1. Use utilities from `app/core/requests.ts`
|
||||
2. Or create derived stores in `app/core/state.ts`
|
||||
3. Use `load`, `pull`, or `request` from `@welshman/net`
|
||||
|
||||
### Publishing Events
|
||||
|
||||
1. Create `make*` function to build event template
|
||||
2. Create `publish*` function using `publishThunk`
|
||||
3. Display thunk status to user (for cancel/error handling)
|
||||
4. These go in in `app/core/commands.ts`
|
||||
|
||||
### Managing Modals/Toasts
|
||||
|
||||
- Import from `app/util/modal.ts` or `app/util/toast.ts`
|
||||
- Pass component objects with parameters
|
||||
- Use `$state.snapshot` if calling component might unmount
|
||||
|
||||
## Development Workflow
|
||||
|
||||
Agents should not run the dev server or build the app. Instead, use the following commands:
|
||||
|
||||
```bash
|
||||
pnpm run format # Format changed files
|
||||
pnpm run lint # Check formatting and linting
|
||||
pnpm run check # Type check
|
||||
```
|
||||
|
||||
**Welshman Development:**
|
||||
|
||||
- Clone welshman to parent directory
|
||||
- Use `./link_deps` script to link local welshman packages
|
||||
- Avoid committing `pnpm.overrides` changes
|
||||
|
||||
**Git Workflow:**
|
||||
|
||||
- `master` branch auto-deploys to production
|
||||
- Work on feature branches based on `dev` branch
|
||||
- Pre-commit hooks run lint/typecheck automatically
|
||||
|
||||
## Environment Variables
|
||||
|
||||
See `.env.template` for all options.
|
||||
|
||||
## Important Files to Reference
|
||||
|
||||
- **src/app/core/state.ts** - All stores and constants
|
||||
- **src/app/core/sync.ts** - Data synchronization
|
||||
- **src/app/core/requests.ts** - Utilities for requesting data
|
||||
- **src/app/core/commands.ts** - Publishing patterns
|
||||
- **src/app/util/notifications.ts** - Notification badges and push notifications
|
||||
- **src/routes/+layout.svelte** - Top-level sync logic
|
||||
|
||||
## Mobile Development
|
||||
|
||||
**Capacitor Integration:**
|
||||
|
||||
- Android: Full support, APK builds via `pnpm run release:android`
|
||||
- iOS: Full support (zaps disabled due to App Store policy)
|
||||
- PWA: Progressive Web App with service worker
|
||||
|
||||
**Native Features:**
|
||||
|
||||
- Push notifications (FCM/APNs)
|
||||
- Deep linking (nostr: and https: URLs)
|
||||
- Native signing plugin
|
||||
- Keyboard management
|
||||
- Safe area handling
|
||||
- Badge management
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
# Flotilla - AI Assistant Context
|
||||
|
||||
## Project Overview
|
||||
|
||||
Flotilla is a Discord-like Nostr client based on the concept of "relays as groups". It's built with SvelteKit, TypeScript, and Capacitor for cross-platform support (web, Android, iOS).
|
||||
|
||||
On boot, please run `tree -I assets src` to get an idea of the project structure.
|
||||
|
||||
## Key Dependencies
|
||||
|
||||
`@welshman/*` libraries contain the majority of nostr-related functionality.
|
||||
`@app/core/*` contains additional app-specific data stores and commands.
|
||||
|
||||
When creating an import statement, first identify what functionality you need. Search the codebase for components with similar functionality, and imitate their imports.
|
||||
|
||||
## Dependency Graph (Acyclic)
|
||||
|
||||
The project follows a strict dependency hierarchy:
|
||||
1. **External libraries** (bottom layer)
|
||||
2. **`lib/`** - Only depends on external libraries
|
||||
3. **`app/core/`** and **`app/util/`** - Can depend on `lib` only
|
||||
4. **`app/components/`** - Can depend on anything in `app` or `lib`
|
||||
5. **`routes/`** - Can depend on anything (top layer)
|
||||
|
||||
**Import Ordering Convention:** Always sort imports by dependency level:
|
||||
1. Third-party libraries first
|
||||
2. Then `lib` imports
|
||||
3. Then `app` imports
|
||||
|
||||
## Development Conventions
|
||||
|
||||
When creating components related to a given space or room, parameterize them only with the entity's identifier (i.e., `url` and `h`). Only pass additional props if they can't be derived from the identifiers. For example, a room's `members` should be derived inside the child component, not passed in by the parent.
|
||||
|
||||
Do not use null, only undefined.
|
||||
@@ -1,96 +0,0 @@
|
||||
# Contributing guidelines
|
||||
|
||||
## Project Overview
|
||||
|
||||
Flotilla is a svelte/typescript/capacitor project. It's intended to be an alternative to Discord for Nostr users. A high-quality UX is a priority, with an emphasis on well-tested, intuitive designs, and robust implementations.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Run `pnpm run dev` to get a dev server, and `pnpm run check:watch` to watch for typescript errors. When you're ready to commit, a pre-commit hook will run to lint and typecheck your work. To run the project on Android or iOS, use Android Studio or Xcode.
|
||||
|
||||
The `master` branch is automatically deployed to production, so always work on feature branches based on the `dev` branch. This project frequently uses unreleased versions of [welshman](https://welshman.coracle.social), using `pnpm` link to hotlink a local copy of the code. To set that up, clone welshman to the parent directory of your `coracle` client, then add `link:../welshman/packages/packagename` to the `pnpm.overrides` section of your `package.json`. Below is a nodejs script that will do that automatically for you:
|
||||
|
||||
```javascript
|
||||
#!/usr/bin/env node
|
||||
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
|
||||
|
||||
packageJson.pnpm.overrides = Object.keys(packageJson.dependencies)
|
||||
.filter(pkg => pkg.startsWith('@welshman/'))
|
||||
.reduce((acc, pkg) => {
|
||||
const packageName = pkg.split('/')[1]
|
||||
acc[pkg] = `link:../welshman/packages/${packageName}`
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2) + '\n')
|
||||
|
||||
console.log('Added welshman package overrides.')
|
||||
```
|
||||
|
||||
Be sure to avoid committing overrides to either `package.json` or `pnpm-lock.yaml`. These overrides can generally be added, installed, and removed, and will persist until another `pnpm install` command gets run.
|
||||
|
||||
## File Structure
|
||||
|
||||
The main parts of the application are as follows:
|
||||
|
||||
- `static` - static assets like fonts, images, etc.
|
||||
- `src/assets` - svgs for use as icons.
|
||||
- `src/lib` - general purpose components and utilities.
|
||||
- `src/app/core/state` - environment variables, constants, custom stores, and some utilities derived from them.
|
||||
- `src/app/core/requests` - utilities related to loading data from the nostr network.
|
||||
- `src/app/core/commands` - utilities related to publishing nostr events and uploading media to blossom servers.
|
||||
- `src/app/utils` - other application logic, including stuff related to modals, routing, etc.
|
||||
- `src/app/editor` - configuration for `@welshman/editor` for use in various app views.
|
||||
- `src/app/components` - reusable components that depend on other `app` stuff.
|
||||
- `src/routes` - file-based routing interpreted by sveltekit.
|
||||
|
||||
Application organization is based on an acyclic dependency graph:
|
||||
|
||||
- `routes` can depend on anything
|
||||
- `app/components` can depend on anything in `app` or `lib`
|
||||
- `app/utils` and `app/core` can only depend on `lib`
|
||||
- `lib` (and everything else) can depend only on external libraries
|
||||
|
||||
The main stylistic/organizational rule when working in this project is that imports should be sorted based on the dependency graph. Third-party libraries should come first, then `lib`, then `app`.
|
||||
|
||||
## System Architecture
|
||||
|
||||
Flotilla's architecture generally mirrors the file structure. State is stored using Svelte `store`s provided either by `@welshman/app` or by `app/core/state`, allowing for idiomatic svelte 4 usage (svelte 5 runes are [ghey](https://habla.news/u/hodlbod@coracle.social/1739830562159) and not allowed outside of UI components).
|
||||
|
||||
State is then synchronized to local storage or indexeddb using storage helpers provided by welshman in `routes/+layout.svelte`. Other top level synchronization logic generally belongs there.
|
||||
|
||||
`app/core/state` contains all environment variables, constants, custom stores, and utilities derived from them. Most stores are `derived` from our event `repository` using `deriveEventsMapped`, which efficiently queries the repository and maps events to custom data structures. Some of these data structures are provided by `welshman`, and some are defined in `app/core/state`. In either case, they can always be mapped back to an event, which is important for updating replaceables without dropping unknown data.
|
||||
|
||||
Here are a few important domain objects:
|
||||
|
||||
- Spaces are relays used as community groups. Their `url`s are core to a lot of data and components, and are frequently passed around from place to place.
|
||||
- Chats are direct message conversations. There is currently some ambiguity in routing, since relays that don't support NIP 29 also have a "chat" tab, which uses vanilla NIP-C7.
|
||||
- NIP 29 groups are called "rooms". Conventionally, "h" is a group id, while a "room" as an object representing the group's metadata.
|
||||
- "Alerts" are records of requests the user has made to be notified, following [this NIP](https://github.com/nostr-protocol/nips/pull/1796)
|
||||
|
||||
`app/core/requests` contains utilities related to loading data from the nostr network. This might include feed manager utilities, loaders, or listeners.
|
||||
|
||||
`app/core/commands` contains utilities related to publishing nostr events and uploading media to blossom servers. This also includes utilities related to sending lighting payments, authenticating with relays, or probing relay policy. Event creation should generally be split into `make` functions which build the event, and `publish` functions which publish the event using `publishThunk`.
|
||||
|
||||
Any of these utilities can be included either in `app/components` or `routes`. Crucial to keep in mind is that nearly all global state runs through welshman's `repository` in a unidirectional way. To update state, run `publishThunk`, which immediately publishes the event to the local repository. State can be read from the repository using `deriveEventsMapped` or other utilities provided by welshman like `deriveProfile`.
|
||||
|
||||
Thunks are designed to reduce UI latency, handling signatures and delayed sending the background. In most cases, thunk status should be displayed to the user so that they can cancel sending or address errors.
|
||||
|
||||
Toast, modals, and sidebar dialogs are controlled in `app/util/modal` and `app/util/toast`. In both cases, component objects can be passed along with parameters, but care has to be taken that the calling component either doesn't unmount before the modal (as when one modal replaces another), or that `$state.snapshot` is appropriately called on any state runes. These components frequently run into weird svelte compiler bugs too, in which case you may have to do some silly things to cope.
|
||||
|
||||
## Issues and Pull Requests
|
||||
|
||||
All work by contributors should be done against an issue. If there is no issue for the work you're doing, please open one or ask the project owner to open one. All PRs should be opened against the `dev` branch (unless for hotfixes).
|
||||
|
||||
## Communication
|
||||
|
||||
Discussion about development is done [on Flotilla](https://app.flotilla.social/spaces/internal.coracle.social). The group is currently closed, so please let me know if you'd like access.
|
||||
|
||||
## Project License
|
||||
|
||||
This project is licensed under the MIT license. By contributing, you agree to waive all intellectual property rights to your contributions to this project.
|
||||
|
||||
Reference in New Issue
Block a user