Fizzy Documentation

repository·main·Indexed 27 days ago

https://github.com/basecamp/fizzy

Documentation for Fizzy, including API guides for authentication, pagination, and file uploads, as well as deployment and development instructions using Docker, Kamal, and the fizzy-saas Rails engine.

Tokens
23.8K
Snippets
93
Records
151
Agent score
87%

What's inside Fizzy

  1. About the fizzy-saas gem

    main

    The fizzy-saas gem is a companion gem used by 37signals to bundle Fizzy with their billing system and production setup.

    Note: This gem depends on private git repositories and is not intended for use by third parties, though it is provided as inspiration for those running Fizzy on their own infrastructure.

  2. Authenticate using Personal Access Tokens

    main

    Personal access tokens are long-lived tokens suitable for scripts and integrations. To use them, include the token in the Authorization header as a Bearer token.

    To generate a token manually:

    1. Go to your profile.
    2. Navigate to the API section.
    3. Click Personal access tokens.
    4. Click Generate new access token.
    5. Provide a description and select a permission level:
      • Read: Allows reading data from your account.
      • Read + Write: Allows reading and writing data on your behalf.

    Warning: Treat access tokens like passwords. Anyone with the token can perform actions on your behalf.

    curl -H "Authorization: Bearer put-your-access-token-here" -H "Accept: application/json" https://app.fizzy.do/my/identity
  3. Use Rich Text fields

    main
    Certain fields in the Fizzy API accept rich text content via HTML input. The API sanitizes this input to remove unsafe tags and attributes. For details on attaching files to rich text fields via the direct upload flow, see the rich text guide.
  4. Use expanded conditionals instead of guard clauses

    main

    Prefer expanded if/else conditionals over guard clauses to improve readability, especially when nesting is involved.

    Exceptions: Use guard clauses only when:

    • The return is at the very beginning of the method.
    • The main method body is non-trivial and spans several lines.
    # Bad
    def todos_for_new_group
      ids = params.require(:todolist)[:todo_ids]
      return [] unless ids
      @bucket.recordings.todos.find(ids.split(,","))
    end
    
    # Good
    def todos_for_new_group
      if ids = params.require(:todolist)[:todo_ids]
        @bucket.recordings.todos.find(ids.split(","))
      else
        []
      end
    end
  5. Deploy Fizzy environments with Kamal

    main

    Fizzy is deployed using Kamal. Ensure the 1Password CLI is configured to access deployment secrets.

    General deployment command:

    bin/kamal deploy
  6. Upload a file via direct upload URL

    main

    Once you have obtained the direct upload URL and headers from the direct_uploads request, upload the file binary using a PUT request to the provided URL. You must include the Content-MD5 header matching the checksum provided in the initial request.

    curl -X PUT \
      -H "Content-Type: image/png" \
      -H "Content-MD5: GQ5SqLsM7ylnji0Wgd9wNA==" \
      --data-binary @screenshot.png \
      "https://storage.example.com/..."
  7. Configure Fizzy storage volumes

    main

    Fizzy stores all data in /rails/storage. Because Docker containers are ephemeral, you must mount a persistent volume to this path to ensure your database and files survive restarts. You can use a named volume with the --volume flag.

    docker run --volume fizzy:/rails/storage ghcr.io/basecamp/fizzy:main
  8. Order methods in classes and vertically by invocation

    main

    Follow these ordering rules to maintain consistent code flow:

    Class Method Ordering:

    1. class methods
    2. public methods (with initialize at the top)
    3. private methods

    Vertical Method Ordering: Order methods based on their invocation order. If method_a calls method_b, method_b should appear after method_a in the file.

    class SomeClass
      def some_method
        method_1
        method_2
      end
    
      private
        def method_1
          method_1_1
          method_1_2
        end
      
        def method_1_1
          # ...
        end
        # ...
        def method_2
          method_2_1
        end
    end
  9. Set up the Fizzy development environment

    main

    To install and configure the Fizzy application, run the setup script. Use the --reset flag to reset the database and re-seed it. Once configured, start the development server using bin/dev.

    Access the application at http://app.fizzy.localhost:3006.

    Login Instructions: Use david@example.com as the email address. To complete the sign-in, retrieve the verification code from the browser console.

    bin/setup
    bin/setup --reset # Reset the database and seed it
    
    # Start the server
    bin/dev
  10. Format rich text fields with HTML

    main

    Rich text fields in Fizzy accept HTML input. The input is automatically sanitized to remove unsafe tags and attributes. When sending data for a rich text field, provide the HTML string as the value for the corresponding key.

    {
      "card": {
        "title": "My card",
        "description": "<p>This is <strong>bold</strong> and this is <em>italic</em>.</p><ul><li">Item 1</li><li">Item 2</li></ul>"
      }
    }