{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://apps.fynncloud.ch/schemas/app-manifest-v1.json",
  "title": "FynnCloud App Manifest",
  "description": "Schema definition for FynnCloud application manifests (v1).",
  "type": "object",
  "required": [
    "id",
    "name",
    "version",
    "category",
    "compatibility"
  ],
  "additionalProperties": true,
  "properties": {
    "$schema": {
      "type": "string",
      "description": "URI to this JSON schema for IDE validation and autocompletion."
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
      "minLength": 2,
      "maxLength": 32,
      "description": "Unique app identifier in kebab-case. Used for URLs, container names, and database schemas. Only lowercase letters, numbers, and single hyphens allowed."
    },
    "name": {
      "type": "string",
      "minLength": 2,
      "maxLength": 64,
      "description": "Human-readable display name of the application."
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$",
      "description": "Semantic Version (SemVer) of this release, e.g. 1.0.0."
    },
    "description": {
      "type": "string",
      "maxLength": 280,
      "description": "A concise one-line summary of what the app does."
    },
    "author": {
      "type": "string",
      "description": "Name of the developer, organization, or community maintaining the app."
    },
    "icon": {
      "type": "string",
      "pattern": "^[a-z0-9-]+:[a-z0-9-]+$",
      "description": "Optional Iconify icon identifier fallback (e.g. \"heroicons:calendar-days-solid\"). Primary vector icon is automatically discovered from \"icon.svg\" in the app directory, which must be a monochrome SVG glyph using fill=\"currentColor\"."
    },
    "gallery": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true,
      "maxItems": 10,
      "description": "Optional ordered list of image file names inside the app's gallery/ directory. By default every image in gallery/ is published, sorted by file name."
    },
    "image": {
      "type": "string",
      "description": "Docker container image reference (e.g. \"ghcr.io/fynncloudproject/app-calendar:1.0.0\"). The ':latest' tag is disallowed; an explicit version tag or digest must be specified.",
      "pattern": "^(?:[^/]+/)*[^/:]+(?::[^/:@]+(?:@[a-zA-Z0-9_-]+:[a-fA-F0-9]+)?|@[a-zA-Z0-9_-]+:[a-fA-F0-9]+)$",
      "not": {
        "pattern": ":latest(@.+)?$"
      }
    },
    "category": {
      "type": "string",
      "enum": [
        "productivity",
        "collaboration",
        "office",
        "media",
        "ai",
        "utilities",
        "security",
        "system",
        "developer"
      ],
      "description": "Primary store category for the application."
    },
    "ui": {
      "oneOf": [
        {
          "type": "boolean",
          "description": "Set to false for headless daemons and background services without a web interface."
        },
        {
          "type": "object",
          "properties": {
            "launcher": {
              "type": "boolean",
              "default": true,
              "description": "Whether the app appears in the primary navigation and app drawer. Defaults to true."
            },
            "entrypoint": {
              "type": "string",
              "default": "/",
              "description": "Optional subpath within the app to load as the initial UI entrypoint (e.g. \"/dashboard\" or \"/web\"). Defaults to \"/\"."
            },
            "background": {
              "type": "boolean",
              "default": false,
              "description": "When true, the host warm-mounts a hidden sandboxed iframe after idle hydration so the app can receive real-time events, incoming rings, and badge updates before the user navigates to it."
            },
            "sidebar_mode": {
              "type": "string",
              "enum": [
                "integrated",
                "rail"
              ],
              "description": "Preferred host navigation layout when viewing this app ('integrated' uses the host sidebar; 'rail' collapses the host sidebar to an icon rail so the app renders its own internal sidebar)."
            },
            "sidebar": {
              "type": "array",
              "description": "Custom navigation items rendered inside FynnCloud's native host sidebar while viewing this app.",
              "items": {
                "type": "object",
                "required": [
                  "id",
                  "label",
                  "icon",
                  "position",
                  "target"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Unique identifier for this sidebar item."
                  },
                  "label": {
                    "type": "string",
                    "description": "Human-readable label shown in the sidebar."
                  },
                  "icon": {
                    "type": "string",
                    "description": "Icon identifier (e.g. Heroicons)."
                  },
                  "position": {
                    "type": "string",
                    "enum": [
                      "top_nav",
                      "bottom_nav"
                    ],
                    "description": "Section of the native sidebar where this item appears ('top_nav' above app drawer, 'bottom_nav' below app drawer)."
                  },
                  "target": {
                    "type": "string",
                    "description": "Subpath route within the app iframe (e.g. '/' or '/events')."
                  },
                  "variant": {
                    "type": "string",
                    "enum": [
                      "default",
                      "danger"
                    ]
                  },
                  "collapsible": {
                    "type": "boolean",
                    "description": "Whether this sidebar section can be collapsed."
                  },
                  "defaultOpen": {
                    "type": "boolean",
                    "description": "Whether this collapsible section is open by default."
                  },
                  "action": {
                    "type": "object",
                    "required": [
                      "id"
                    ],
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Identifier for the action button."
                      },
                      "icon": {
                        "type": "string",
                        "description": "Icon identifier (e.g. Heroicons) for the action button."
                      },
                      "title": {
                        "type": "string",
                        "description": "Tooltip title for the action button."
                      }
                    },
                    "description": "Action button rendered beside the section header."
                  },
                  "badge": {
                    "type": "object",
                    "properties": {
                      "poll_endpoint": {
                        "type": "string"
                      },
                      "color": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "additionalProperties": false
        }
      ],
      "default": true,
      "description": "UI, launcher, and native host sidebar configuration. Defaults to true (interactive app with launcher icon). Set to false for headless services."
    },
    "compatibility": {
      "type": "object",
      "required": [
        "fynncloud"
      ],
      "properties": {
        "fynncloud": {
          "type": "string",
          "pattern": "^\\s*(>=|>|<=|<|=)\\d+\\.\\d+\\.\\d+(\\s+(>=|>|<=|<|=)\\d+\\.\\d+\\.\\d+)*\\s*$",
          "examples": [
            ">=1.0.0 <2.0.0"
          ],
          "description": "Range of FynnCloud Server versions this release works with. Space-separated comparators using >=, >, <=, < or =, e.g. \">=1.0.0 <2.0.0\". FynnCloud refuses to install or serve an app whose range excludes the server version."
        },
        "apps": {
          "type": "array",
          "maxItems": 20,
          "description": "Other FynnCloud apps this app integrates with via the host's cross-app proxy (/api/apps/:id/proxy).",
          "items": {
            "type": "object",
            "required": [
              "id",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
                "minLength": 2,
                "maxLength": 32,
                "description": "Identifier of the target FynnCloud app."
              },
              "version": {
                "type": "string",
                "pattern": "^\\s*(>=|>|<=|<|=)\\d+\\.\\d+\\.\\d+(\\s+(>=|>|<=|<|=)\\d+\\.\\d+\\.\\d+)*\\s*$",
                "examples": [
                  ">=1.0.0 <2.0.0"
                ],
                "description": "Compatible semver range for the target app."
              },
              "optional": {
                "type": "boolean",
                "default": true,
                "description": "Whether this app still functions when the target app is not installed."
              },
              "access": {
                "type": "string",
                "enum": [
                  "read",
                  "write"
                ],
                "default": "read",
                "description": "Maximum proxy access level granted when the caller proxies to the target app."
              }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "database": {
      "oneOf": [
        {
          "type": "boolean"
        },
        {
          "type": "object",
          "properties": {
            "required": {
              "type": "boolean"
            },
            "engine": {
              "type": "string",
              "enum": [
                "postgres"
              ]
            }
          }
        }
      ],
      "description": "When true or required, FynnCloud automatically provisions an isolated PostgreSQL database schema and credentials for the app."
    },
    "storage": {
      "oneOf": [
        {
          "type": "boolean"
        },
        {
          "type": "object",
          "properties": {
            "volume_required": {
              "type": "boolean"
            },
            "mount_path": {
              "type": "string"
            }
          }
        }
      ],
      "description": "When true or volume_required, FynnCloud provisions an isolated persistent storage volume on the host."
    },
    "drawer": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true
        }
      },
      "description": "Configuration for the bottom app drawer."
    },
    "permissions": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "files:all:read",
          "files:all:write",
          "files:selected:read",
          "files:selected:write",
          "groups:read",
          "media:capture",
          "notifications:send",
          "presence:write",
          "realtime:push",
          "rtc:rooms",
          "user:read",
          "users:events"
        ]
      },
      "uniqueItems": true,
      "description": "List of system scopes requested by the app. `groups:read` allows backend resolution of group memberships via app-secret auth; `users:events` is required to receive `user.*` / `group.*` webhook events; `files:all:read` is required to receive `file.*` events; `media:capture` is required for microphone, camera, or screen capture via the host media relay; `presence:write` allows updating the signed-in user's Core availability mode and status message (`PUT /api/user/status`); `rtc:rooms` allows minting namespaced LiveKit SFU room tokens (and combined with `notifications:send`, permits native iOS PushKit VoIP registration); `realtime:push` allows publishing real-time events to the app's frames through the host event stream (`POST /api/apps/realtime/publish`)."
    },
    "events": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        {
          "type": "object",
          "properties": {
            "endpoint": {
              "type": "string"
            },
            "subscriptions": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      ],
      "description": "Webhooks or real-time event subscriptions the app listens for."
    },
    "hooks": {
      "type": "object",
      "description": "System-wide integration hooks outside of the app's own UI (e.g. file browser context menu actions).",
      "properties": {
        "file_actions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "label",
              "extensions",
              "icon",
              "target"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "label": {
                "type": "string"
              },
              "extensions": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "icon": {
                "type": "string"
              },
              "target": {
                "type": "string"
              },
              "mode": {
                "type": "string",
                "enum": [
                  "navigate",
                  "background",
                  "modal"
                ]
              },
              "role": {
                "type": "string",
                "enum": [
                  "open",
                  "action"
                ],
                "default": "action",
                "description": "Set to 'open' if this app is the primary handler for opening this file type (triggered when single-clicking the file and promoted to 'Open' at the top of the context menu). Defaults to 'action'."
              },
              "destination": {
                "type": "string",
                "enum": [
                  "folder"
                ],
                "description": "Set to 'folder' if the action creates new files. FynnCloud asks the user where to save before running it, and a 'files:selected:write' token may only create files in that folder."
              }
            }
          }
        },
        "new_file": {
          "type": "array",
          "description": "Hooks allowing an app to register options in FynnCloud's 'New' file creation menu.",
          "items": {
            "type": "object",
            "required": [
              "id",
              "label",
              "icon"
            ],
            "properties": {
              "id": {
                "type": "string",
                "description": "Unique identifier for this new file action."
              },
              "label": {
                "type": "string",
                "description": "Human-readable label shown in the 'New' menu (e.g. 'Diagram')."
              },
              "extension": {
                "type": "string",
                "description": "Target file extension (e.g. 'drawio')."
              },
              "default_filename": {
                "type": "string",
                "description": "Default file name when creating (e.g. 'Untitled Diagram.drawio')."
              },
              "icon": {
                "type": "string",
                "description": "Icon identifier (e.g. simple-icons:diagramsdotnet or heroicons)."
              },
              "target": {
                "type": "string",
                "description": "Subpath route within the app iframe (defaults to '/')."
              },
              "mode": {
                "type": "string",
                "enum": [
                  "navigate",
                  "modal"
                ],
                "default": "modal",
                "description": "Presentation mode for creating the file ('modal' for overlay editor, 'navigate' for full page app)."
              }
            }
          }
        }
      }
    },
    "deploy": {
      "type": "object",
      "required": [
        "image"
      ],
      "description": "Container deployment and hardware specifications for Docker/container runners.",
      "properties": {
        "image": {
          "type": "string",
          "description": "Docker container image reference (e.g. \"ghcr.io/fynncloudproject/app-calendar:1.0.0\"). The ':latest' tag is disallowed; an explicit version tag or digest must be specified.",
          "pattern": "^(?:[^/]+/)*[^/:]+(?::[^/:@]+(?:@[a-zA-Z0-9_-]+:[a-fA-F0-9]+)?|@[a-zA-Z0-9_-]+:[a-fA-F0-9]+)$",
          "not": {
            "pattern": ":latest(@.+)?$"
          }
        },
        "port": {
          "type": "integer",
          "default": 8080,
          "minimum": 1,
          "maximum": 65535,
          "description": "Internal HTTP port exposed by the container (defaults to 8080)."
        },
        "architectures": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "amd64",
              "arm64",
              "arm/v7"
            ]
          },
          "default": [
            "amd64",
            "arm64"
          ],
          "description": "Supported CPU architectures."
        },
        "resources": {
          "type": "object",
          "description": "Resource requirements and container limits.",
          "properties": {
            "memory": {
              "type": "string",
              "default": "256MB",
              "description": "Memory limit or recommendation (e.g. \"256MB\", \"512MB\", \"1GB\")."
            },
            "cpu": {
              "type": "number",
              "default": 0.5,
              "description": "CPU core limit or allocation (e.g. 0.5, 1.0)."
            }
          }
        },
        "healthcheck": {
          "type": "object",
          "description": "Container readiness probe.",
          "properties": {
            "path": {
              "type": "string",
              "default": "/health",
              "description": "HTTP endpoint path for health checks."
            },
            "interval_seconds": {
              "type": "integer",
              "default": 30
            },
            "timeout_seconds": {
              "type": "integer",
              "default": 5
            }
          }
        },
        "env": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "Default environment variables to inject into the container."
        },
        "read_only_rootfs": {
          "type": "boolean",
          "default": true,
          "description": "Run the container with a read-only root filesystem. /tmp and /run stay writable (tmpfs) and `storage` volumes stay writable. Set to false only if the image has to write elsewhere."
        },
        "user": {
          "type": "string",
          "pattern": "^[0-9]{1,10}(:[0-9]{1,10})?$",
          "description": "Numeric uid[:gid] to run the container as. Defaults to the image's own USER, which should be non-root."
        }
      }
    },
    "gateway": {
      "type": "object",
      "description": "How the FynnCloud gateway (/api/apps/<id>/proxy/**) treats requests without FynnCloud credentials. By default the gateway only forwards an app's static UI shell (GET/HEAD outside /api/**, apps with a UI only) anonymously; everything else needs a user session or the app's scoped token.",
      "properties": {
        "public_paths": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "pattern": "^/[^?]*$",
            "maxLength": 200
          },
          "description": "Path prefixes forwarded without FynnCloud authentication because the app authenticates them itself (e.g. WebDAV with HTTP Basic). Use sparingly: the app must verify credentials on every request under these paths."
        }
      },
      "additionalProperties": false
    },
    "oauth": {
      "type": "object",
      "description": "OAuth2 PKCE configuration for native mobile, desktop, or companion clients authenticating as `app:<id>` or `app:<id>:<variant>`.",
      "required": [
        "redirect_uris"
      ],
      "properties": {
        "redirect_uris": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512
          },
          "description": "Allowed OAuth2 callback URIs (custom native URI schemes like `fynncloud-talk://auth`, `https://...`, or `http://127.0.0.1/...` loopback URIs)."
        }
      },
      "additionalProperties": false
    },
    "push": {
      "type": "object",
      "description": "Zero-knowledge push notification relay configuration for native mobile and desktop companion apps.",
      "required": [
        "gateways"
      ],
      "properties": {
        "gateways": {
          "type": "array",
          "minItems": 1,
          "maxItems": 5,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512
          },
          "description": "Allowed HTTPS push relay URLs (e.g. `https://push.fynncloud.ch/v1/push`) that native clients of this app may register."
        },
        "voip": {
          "type": "boolean",
          "default": false,
          "description": "Allow native iOS clients of this app to register PushKit VoIP tokens (`apns-voip`). Requires the `notifications:send` and `rtc:rooms` permissions."
        }
      },
      "additionalProperties": false
    }
  }
}
