Fedify Framework Documentation

repository·main·Indexed 21 days ago

https://github.com/fedify-dev/fedify

A framework for building federated server applications. Fedify provides tools for ActivityPub integration, including specialized linting via @fedify/lint and official integrations for Astro (@fedify/astro), Elysia, Express, Fresh, and Cloudflare Workers. The framework supports building ActivityPub-compatible social media servers with features for content negotiation, actor and object dispatchers, and custom ActivityPub collection patterns.

Tokens
300.8K
Snippets
758
Records
1K
Agent score
73%

What's inside Fedify

  1. Overview of Fedify features

    main

    Fedify is a TypeScript library designed to simplify building federated server applications powered by ActivityPub and other fediverse standards. It handles the complex boilerplate of federation so developers can focus on business logic.

    Key features provided out of the box include:

    • Type-safe Activity Vocabulary: Support for ActivityStreams vocabulary, including common vendor extensions.
    • WebFinger: Both client and server implementations.
    • Signatures: Support for HTTP Signatures and HTTP Message Signatures.
    • Integrity & Proofs: Support for Object Integrity Proofs (FEP-8b32) and Linked Data Signatures.
    • Webhooks: Middlewares for handling incoming webhooks.
    • NodeInfo: Implementation of the NodeInfo protocol.
    • Interoperability: Enhanced compatibility with Mastodon and other popular fediverse software.
    • Framework Integration: Support for various web frameworks.
    • CLI Toolchain: Tools for testing and debugging your federated application.
  2. Overview of Fedify

    main

    Fedify is a TypeScript library designed for building federated server applications powered by ActivityPub and other fediverse standards. It aims to reduce the complexity and boilerplate associated with federated servers, allowing developers to focus on business logic and user experience.

    Key features include:

    • Type-safe objects for Activity Vocabulary (including vendor extensions).
    • WebFinger client and server support.
    • HTTP Signatures and HTTP Message Signatures.
    • Object Integrity Proofs (FEP-8b32) and Linked Data Signatures.
    • Middlewares for handling webhooks.
    • NodeInfo protocol support.
    • Enhanced interoperability with Mastodon and other fediverse software.
    • Integration with various web frameworks.
    • A CLI toolchain for testing and debugging.
  3. What is @fedify/uri-template?

    main
    @fedify/uri-template is a strict RFC 6570 URI Template implementation that provides both expansion and pattern matching with round-trip verification. It is designed to ensure that when a URI is matched against a template, the extracted values can be expanded back to the exact same input URI (expand(match(uri)) === uri). It can be used as a standalone library or as part of the Fedify framework.
  4. Explore Fedify integration examples

    main

    The examples/ directory contains various reference implementations demonstrating how to integrate Fedify with different web frameworks, runtimes, and specific ActivityPub use cases. Use these examples to understand how to serve federation through your existing application stack.

    Framework Integrations

    • H3: Serving federation through an H3 application.
    • Hono: Integration sample for the Hono framework.
    • Fastify: Integration example for Fastify.
    • Express: Integration example for Express.
    • Next.js: Multiple integration examples available for versions 14 (App Router), 15 (App Router), and 16 (using @fedify/next).
    • SolidStart: Integration example for SolidStart.
    • Cloudflare Workers: Example of running Fedify on Cloudflare Workers.

    Use Case Examples

    • Actor lookup CLI: A command-line tool for looking up actors.
    • Custom collections: Demonstrates implementing custom ActivityPub collections.
    • Federated microblog/blog: Examples of single-user federated blogging and microblogging software.
    • Monitoring: Example of how to monitor Fedify applications.
  5. Use @fedify/interaction-controls for interaction policy management

    main

    The @fedify/interaction-controls package provides helper functions for Fedify applications to manage social interactions. Use this package to:

    • Evaluate interaction policies (e.g., determining if an action is allowed).
    • Request approval for interactions.
    • Issue authorizations for specific actions.
    • Verify authorizations for common social actions such as:
      • Likes
      • Replies
      • Announces
      • Quotes
      • Featured actors

    For a detailed explanation of the request and authorization flow, refer to the interaction controls manual.

  6. Supported federation protocols and standards in Fedify

    main

    Fedify supports a variety of protocols and standards to enable federation. These include:

    • ActivityPub (S2S)
    • WebFinger
    • HTTP Message Signatures (RFC 9421)
    • HTTP Signatures (draft-cavage-http-signatures-12)
    • Linked Data Signatures
    • NodeInfo
  7. Supported Fediverse Enhancement Proposals (FEPs)

    main

    Fedify supports several FEPs to extend federation capabilities. Key supported FEPs include:

    • FEP-67ff: (Refer to FEDERATION.md)
    • FEP-f228: Backfilling conversations
    • FEP-8fcf: Followers collection synchronization across servers
    • FEP-9091: Export Actor Service Endpoint
    • FEP-f1d5: NodeInfo in Fediverse Software
    • FEP-8b32: Object Integrity Proofs
    • FEP-521a: Representing actor's public keys
    • FEP-5feb: Search indexing consent for actors
    • FEP-fe34: Origin-based security model
    • FEP-c0e0: Emoji reactions
    • FEP-e232: Object Links
    • FEP-5711: Inverse Properties for Collections
    • FEP-044f: Consent-respecting quote posts
    • FEP-7aa9: Featuring recommendations using a dedicated collection
    • FEP-0837: Federated Marketplace
    • FEP-ae0c: Fediverse Relay Protocols: Mastodon and LitePub
  8. Adapt Fedify with Deno KV

    main
    The @fedify/denokv package provides implementations of Fedify's KvStore and MessageQueue interfaces specifically for the Deno runtime. It leverages Deno's built-in Deno.openKv() API to provide persistent storage and high performance, making it suitable for production Deno applications.
  9. Integrate Fedify with Next.js

    main

    The @fedify/next package allows you to integrate Fedify into a Next.js application.

    Important Requirements

    • Initialization: It is highly recommended to use the init command of the @fedify/cli to set up your project instead of installing this package manually.
    • Next.js Version: This package requires Next.js 15.4.6 or later because it relies on Next.js request interception on the Node.js runtime.
    • Runtime Configuration:
      • For Next.js 15, use middleware.ts with runtime: "nodejs" in the exported config.
      • For Next.js 16, using proxy.ts is preferred. If you use proxy.ts, you must omit runtime: "nodejs" from the exported config because Proxies always run on the Node.js runtime.
  10. Use @fedify/interaction-controls for permission management

    main

    The @fedify/interaction-controls package provides typed helpers to manage permissions for interactions like likes, replies, announces, quotes, and featuring actors. It implements logic based on GoToSocial interaction controls, FEP-044f, and FEP-7aa9.

    Note: This package provides the logic but does not install inbox listeners for you. You must call these helpers from your own outbox, inbox, storage, moderation, and UI code.

  11. What is a MessageQueue and how to choose an implementation

    main

    The MessageQueue interface in Fedify provides an abstraction for handling asynchronous message processing. When choosing an implementation, consider your runtime environment (Deno, Node.js, Bun), scalability needs (multiple workers/servers), persistence requirements (surviving restarts), and whether you are in development or production.

    Fedify provides several built-in implementations ranging from simple in-memory queues for testing to distributed, persistent queues like Redis, PostgreSQL, or AMQP for production.

  12. What is the Context object?

    main

    The Context object is a container that holds information about the current request. It is the primary way to interact with the federation logic within callback functions (like actor dispatchers or inbox listeners) or when manually handling requests.

    Key responsibilities include:

    • Carrying custom context data (TContextData).
    • Building object URIs (actor URIs, inbox URIs, etc.).
    • Dispatching Activity Vocabulary objects.
    • Enqueuing outgoing activities.
    • Providing a DocumentLoader for fetching remote JSON-LD documents.
    • Looking up remote objects and performing WebFinger lookups.