This file contains instructions for LLM coding agents working with the Fedify codebase.
Fedify is a TypeScript library for building federated server applications powered by ActivityPub and related standards, facilitating integration with the Fediverse. The project aims to eliminate complexity and boilerplate code when implementing federation protocols.
Main features:
- Type-safe ActivityPub vocabulary implementation
- WebFinger client and server
- HTTP Signatures and Linked Data Signatures
- Object Integrity Proofs
- Federation middleware for handling webhooks
- NodeInfo protocol support
- Interoperability with Mastodon and other fediverse software
- Integration with various web frameworks (Express, h3, Hono, SvelteKit)
- Database adapters (PostgreSQL, Redis, AMQP/RabbitMQ)
- CLI toolchain for testing and debugging
- Primary development environment: Deno
- Additional test environments: Node.js and Bun
- Recommended editor: Visual Studio Code with Deno extension
- Important: Run
deno task codegenbefore working with the codebase (for code generation)
The repository is organized as a monorepo with the following packages:
- fedify/: Main Fedify library (@fedify/fedify)
- codegen/: Code generation scripts
- compat/: Compatibility layer
- federation/: Core federation functionality
- nodeinfo/: NodeInfo protocol implementation
- runtime/: Runtime utilities
- shim/: Platform abstraction layer
- sig/: Signature implementation
- testing/: Testing utilities
- vocab/: ActivityPub vocabulary implementation
- webfinger/: WebFinger protocol implementation
- x/: Framework integrations
- cli/: Fedify CLI implementation (@fedify/cli, built with Deno)
- amqp/: AMQP/RabbitMQ driver (@fedify/amqp)
- express/: Express.js integration (@fedify/express)
- h3/: h3 framework integration (@fedify/h3)
- postgres/: PostgreSQL drivers (@fedify/postgres)
- redis/: Redis drivers (@fedify/redis)
- docs/: Documentation built with Node.js and VitePress
- examples/: Example projects demonstrating Fedify usage
-
Builder Pattern: The
FederationBuilderclass follows a fluent builder pattern for configuring federation components. -
Dispatcher Callbacks: Use function callbacks for mapping routes to handlers, following the pattern in existing dispatchers.
-
Type Safety: Maintain strict TypeScript typing throughout. Use generics like
<TContextData>to allow applications to customize context data. -
Testing: Follow the existing test patterns using Deno's testing framework. Use in-memory stores for testing.
-
Framework Agnostic: Code should work across Deno, Node.js, and Bun environments.
-
ActivityPub Objects: All vocabulary objects follow the class pattern established in the vocab/ directory.
-
Code Generation: Run
deno task codegenwhenever vocabulary YAML files or code generation scripts change. -
Checking Code: Before committing, run
deno task check-allfrom the root directory to check all packages. -
Running Tests: Use
deno task testfor basic tests ordeno task test-allto test across all environments and packages. -
Documentation: Follow the Markdown conventions in CONTRIBUTING.md:
- 80 characters per line (except for code blocks and URLs)
- Use reference links over inline links
- Use setext headings over ATX headings
- Two new lines before H1/H2 headings
- Wrap file paths in asterisks
- Code blocks should use quadruple tildes with language specified
When working with federation code:
- Use the builder pattern following the
FederationBuilderclass - Implement proper HTTP signature verification for security
- Keep ActivityPub compliance in mind for interoperability
- Follow existing patterns for handling inbox/outbox operations
- Use the queue system for background processing of federation activities
- Create a new YAML file in fedify/vocab/ following existing patterns
- Run
deno task codegento generate TypeScript classes - Export the new types from appropriate module files
- Add new integrations in the fedify/x/ directory
- Follow pattern from existing integrations (hono.ts, sveltekit.ts)
- Use standard request/response interfaces for compatibility
- Consider creating a dedicated package for substantial integrations
- For core KV/MQ interfaces: implement in fedify/federation/kv.ts and fedify/federation/mq.ts
- For specific database adapters: create dedicated packages (postgres/, redis/, amqp/)
- Follow the pattern from existing database adapter packages
- Implement both KV store and message queue interfaces as needed
- HTTP Signatures: Always verify HTTP signatures for incoming federation requests
- Object Integrity: Use Object Integrity Proofs for content verification
- Key Management: Follow best practices for key storage and rotation
- Rate Limiting: Implement rate limiting for public endpoints
- Input Validation: Validate all input from federated sources
- Write unit tests for all new functionality
- Follow the pattern of existing tests
- Use the testing utilities in fedify/testing/
- Consider interoperability with other fediverse software
- For package-specific tests, follow the testing patterns in each package
- Include JSDoc comments for public APIs
- Update documentation when changing public APIs
- Follow Markdown conventions as described in CONTRIBUTING.md
- Include examples for new features
Fedify follows a structured branching strategy for managing releases and maintenance:
- main: Contains unreleased development for the next major/minor version
- x.y-maintenance: Maintenance branches for released major/minor versions
(e.g.,
1.5-maintenance,1.6-maintenance)
- New features: Always target the
mainbranch - Bug fixes: Target the oldest applicable maintenance branch that contains the bug
When a bug is fixed in a maintenance branch:
- Fix the bug in the oldest affected maintenance branch (e.g.,
1.5-maintenance) - Create a new patch release tag (e.g.,
1.5.1) - Merge the fix into the next maintenance branch (e.g.,
1.6-maintenance) - Create a new patch release tag for that branch (e.g.,
1.6.1) - Continue merging forward through all subsequent maintenance branches
- Finally merge into
main
This ensures that all maintenance branches and the main development branch include the fix.
When fixing bugs:
- Add regression tests that demonstrate the bug
- Fix the bug
- Update CHANGES.md with the issue number, PR number, and your name
- Target the oldest applicable maintenance branch
When adding features:
- Add unit tests for the new feature
- Implement the feature
- Update documentation for API changes
- Verify examples work with the change
- Update CHANGES.md with details
- Target the main branch
The monorepo uses different build processes for different packages:
-
@fedify/fedify: Uses a custom build process to support multiple environments:
- Deno-native modules
- npm package via dnt (Deno to Node Transform)
- JSR package distribution
-
@fedify/cli: Built with Deno, distributed via JSR and npm
-
Database adapters and integrations: Use tsdown for TypeScript compilation:
- amqp/, express/, h3/, postgres/, redis/
- Built to support Node.js and Bun environments
Ensure changes work across all distribution formats and target environments.