8000 GitHub - romkey/comfier-ui: Simplified front end to comfyui to make it easy for hackerspace members to share instances. · GitHub
[go: up one dir, main page]

Skip to content

About

Simplified front end to comfyui to make it easy for hackerspace members to share instances.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

487 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comfier

Tests Lint Security Ruby 4.0.10 Rails 8.1 Works with ComfyUI License: MIT

A simplified front end for ComfyUI. People sign in with Authentik, type a prompt, pick a shape and get a result, without ever seeing a node graph. Admins decide what each page does by uploading ComfyUI workflows, and point the app at one or more ComfyUI servers.

The navbar has Image, Video, Audio and 3D Model (one simple form each), Results (everything you've made) and Settings (your preferences, plus backends and workflows for admins).

See docs/USER_GUIDE.md for how to use it, or docs/USER_API.md for submitting and managing generations from scripts.

AI disclosure

This README was drafted with AI assistance and edited under human guidance. Treat it as a living document: if something looks wrong or out of date, open an issue or send a pull request.

Requirements

Everything runs in Docker; you only need Docker with Compose v2 on the host.

Component Version
Ruby 4.0.10
Rails 8.1
PostgreSQL 18
Redis 8
Sidekiq 8
Node not used (importmap, vendored Bootstrap)

Setup

git clone <repo> comfier-ui && cd comfier-ui
cp .env.example .env

In .env, either fill in the Authentik settings or turn on developer sign-in, a single email/password account that needs no identity provider. It only works in development, and only once both credentials are set:

DEV_LOGIN=true
DEV_LOGIN_EMAIL=you@example.com
DEV_LOGIN_PASSWORD=...          # e.g. openssl rand -base64 12
DEV_LOGIN_NAME=Your Name        # optional, default "Developer"
DEV_LOGIN_ADMIN=true            # false to see the app as a regular user

The account is updated from these values on every sign-in, and the web container reads them at boot, so restart it after changing them.

Authentik

Create an OAuth2/OpenID Provider and an application for it:

  • Redirect URI: ${APP_URL}/auth/authentik/callback
  • Scopes: openid, email, profile, plus a scope that includes a groups claim
  • Copy the issuer URL, client ID and client secret into AUTHENTIK_ISSUER, AUTHENTIK_CLIENT_ID and AUTHENTIK_CLIENT_SECRET

Anyone in the AUTHENTIK_ADMIN_GROUP group (default comfier-admins) is an admin. This is re-checked on every sign-in.

Comfier also requests a slack scope, which links users to Slack for notifications. In Authentik, create a Scope Mapping with scope name slack and an expression that returns the user's Slack member ID and name, e.g.:

return {
    "slack": {
        "uid": request.user.attributes.get("slack_uid"),
        "name": request.user.attributes.get("slack_name"),
    }
}

Add it to the provider's selected scopes. Comfier stores uid and name on every sign-in; users without a Slack link just can't turn on Slack notifications. If the scope mapping isn't set up, sign-in still works.

Notifications

Users can choose to be told by email and/or Slack DM when a generation finishes, fails or is cancelled, optionally with the output attached. Email addresses and Slack IDs come from Authentik; users can't edit them.

  • Email: set SMTP_ADDRESS (plus port, credentials and MAIL_FROM). Email is unavailable until it's set.
  • Slack: create a Slack app with a bot user, give the bot the chat:write, im:write and files:write scopes, install it to the workspace, and put its bot token in SLACK_BOT_TOKEN. Slack is unavailable until it's set.
  • Attachments over the channel's size limit are replaced by a link. Defaults are about 500 KB for email and 5 MB for Slack, configurable under Settings → Notifications. Oversized JPEG, PNG and WebP outputs are re-encoded smaller until they fit; other file types are attached as-is or linked.

Environment variables

Variable Purpose
APP_URL Public URL of the app
APP_HOST Hostname allowed by Rails host authorization
AUTHENTIK_ISSUER, AUTHENTIK_CLIENT_ID, AUTHENTIK_CLIENT_SECRET OIDC provider
AUTHENTIK_ADMIN_GROUP Authentik group whose members are admins
DEV_LOGIN true enables developer sign-in (development only)
DEV_LOGIN_EMAIL, DEV_LOGIN_PASSWORD The developer sign-in credentials; both required
DEV_DNS Development only: LAN DNS server for resolving private ComfyUI hostnames
DEV_LOGIN_NAME, DEV_LOGIN_ADMIN The developer account's display name, and whether it's an admin (default true)
SECRET_KEY_BASE Production only; bin/rails secret
ACTIVE_RECORD_ENCRYPTION_* Production only; bin/rails db:encryption:init. Encrypts backend API tokens
POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USERNAME, POSTGRES_PASSWORD PostgreSQL connection
POSTGRES_DATABASE, POSTGRES_DATABASE_TEST, POSTGRES_DATABASE_PRODUCTION Database name per environment
POSTGRES_HOST_PORT Dev only: host port when compose publishes Postgres
TIME_ZONE, SIDEKIQ_CONCURRENCY, FORCE_SSL, ASSUME_SSL Optional tuning
MODEL_DOWNLOAD_TIMEOUT_HOURS How long a model download may run before it's marked failed (default 12)
METRICS_TOKEN Turns on GET /metrics for Prometheus and is the bearer token it must send; unset, the endpoint is off. See docs/METRICS.md
SMTP_ADDRESS, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD Outgoing mail server for email notifications
SMTP_AUTHENTICATION, SMTP_ENABLE_STARTTLS, SMTP_DOMAIN SMTP options (defaults plain, true, APP_URL host)
MAIL_FROM Sender address for notification emails
SLACK_BOT_TOKEN Slack bot token (xoxb-…) for Slack DM notifications
NOTIFICATION_ATTACHMENT_MAX_MB Fallback attachment limit for both channels when the database is first created
NOTIFICATION_EMAIL_ATTACHMENT_MAX_MB Default email attachment limit (about 0.488 MB / 500 KB); falls back to NOTIFICATION_ATTACHMENT_MAX_MB
NOTIFICATION_SLACK_ATTACHMENT_MAX_MB Default Slack attachment limit (5 MB); falls back to NOTIFICATION_ATTACHMENT_MAX_MB
LITELLM_URL, LITELLM_API_KEY, LITELLM_MODEL LiteLLM proxy for Chat and the workflow placeholder assistant (Settings → Chat / Workflow assistant)
LITELLM_TIMEOUT_SECONDS Optional read timeout for LiteLLM requests (default 180)

Running locally

docker compose -f docker-compose.dev.yml up

This starts Postgres, Redis, the web server and Sidekiq, with the code bind-mounted and gems cached in a shared volume. The web container runs db:prepare. No workflows are seeded, so the Image, Video, Audio and 3D Model pages stay empty until an admin adds workflows under Settings → Workflows. Open http://localhost:3000.

To try the whole flow without a GPU, start the fake ComfyUI server and add a backend with URL http://fake-comfyui:8188 under Settings → Backends. It finishes every prompt after three seconds with a generated PNG. It also pretends to have the Comfier downloader node and starts with only the Stable Diffusion 1.5 checkpoint, so model installs can be tried out too (downloads "finish" without fetching anything, and are forgotten when it restarts).

docker compose -f docker-compose.dev.yml --profile fake up

A real ComfyUI server on your network is added by URL the same way. Remember the URL is used from inside the containers: localhost means the container itself (use host.docker.internal for a ComfyUI running on your Mac). If the server has a private hostname that only your LAN DNS knows, Docker Desktop won't resolve it; set DEV_DNS in .env to your LAN DNS server and run docker compose -f docker-compose.dev.yml up -d to recreate the containers.

Useful extras:

docker compose -f docker-compose.dev.yml --profile tools run --rm migrate   # run migrations
docker compose -f docker-compose.dev.yml run --rm web bin/rails console

The Sidekiq dashboard is at /admin/sidekiq (admins only).

Testing

docker compose -f docker-compose.test.yml run --rm test

Runs the Minitest suite against a throwaway Postgres on tmpfs. ComfyUI and Authentik are always stubbed (WebMock and OmniAuth test mode); the tests never touch the network. Don't run bin/rails test inside the dev web container: its DATABASE_URL points at the development database, and loading fixtures there would replace your data. The suite refuses to start unless the database name ends in _test.

The ComfyUI downloader node has its own tests, which need only Python 3.8+ (no ComfyUI):

python3 -m unittest discover -s comfyui/tests

The Comfier Agent has a pytest suite that runs the agent against a fake Comfier and a fake ComfyUI, checking every message against protocol/agent-v1.schema.json (Python 3.10+):

python3 -m venv /tmp/comfier-venv
/tmp/comfier-venv/bin/pip install -e "comfyui/comfier_agent[test]" ruff
cd comfyui/comfier_agent && /tmp/comfier-venv/bin/ruff check comfier_agent tests && /tmp/comfier-venv/bin/pytest -q

An end-to-end test runs the real pieces together: Rails (Puma), Sidekiq, Redis, the real agent and a fake ComfyUI (test/e2e/fake_comfyui.py). It submits a job and waits for its output, then kills the agent mid-job, restarts it, and checks the job still finishes exactly once:

docker compose -f docker-compose.test.yml run --rm e2e

Logs from each process land in tmp/e2e/.

Browser tests in test/system play a real H.264 clip in Chromium every way a viewer reaches a video: from Results, after Back and Forward, after the page refreshes itself, on Shared, and from a public link. They also check a video that won't load shows Reload and is logged. Chromium runs in its own container (selenium/standalone-chromium); in CI the runner's Chrome is used instead:

docker compose -f docker-compose.test.yml run --rm system

Screenshots of failures land in tmp/screenshots/. The first run builds clips with ffmpeg into tmp/video_fixtures/. If tests that need ffmpeg are skipped, rebuild the image with docker compose -f docker-compose.test.yml build test.

Linting

docker compose -f docker-compose.lint.yml run --rm rubocop
docker compose -f docker-compose.lint.yml run --rm brakeman

Deployment

Dockerfile builds the production image (multi-stage, non-root, assets precompiled). The version is baked in at build time with --build-arg APP_VERSION=... and read through AppVersion. The newest v* git tag is the canonical version; there is no VERSION file.

docker-compose.production.yml runs the image as web, sidekiq and a migrate tool, with bundled Postgres and Redis. Set COMFIER_IMAGE to choose the image, and fill in the production secrets in .env.

docker compose -f docker-compose.production.yml --profile tools run --rm migrate
docker compose -f docker-compose.production.yml up -d

Uploaded inputs and generated outputs are stored with Active Storage on local disk. Back them up along with the database. Both web and sidekiq must mount the same path (Docker volume or bind mount) — Sidekiq writes generated files during background jobs; the web process serves them. If only one container has the mount, images 404 with ActiveStorage::DiskController in the logs.

Background jobs run in the sidekiq container, not web. Tail Sidekiq separately:

docker compose logs -f sidekiq

On startup Sidekiq logs the Redis URL it connected to. Web and Sidekiq must share the same REDIS_URL (compose default: redis://redis:6379/0, using the compose service name redis).

To debug missing images or stuck jobs:

docker compose ps                                           # sidekiq must be running
docker compose exec sidekiq printenv REDIS_URL
docker compose exec web printenv REDIS_URL                # must match sidekiq
docker compose exec redis redis-cli LLEN queue:default    # pending jobs, if any
docker compose exec sidekiq ls -la /rails/storage
docker compose exec web ls -la /rails/storage

Both containers should list the same blob directories under /rails/storage. If neither has files, regenerate after fixing storage — old blob records in Postgres won't recover.

Monitoring

8000

Set METRICS_TOKEN to serve Prometheus metrics at /metrics: users, generations by kind, workflow and status, failures, run times, servers, model downloads and the background job queue. Requests must send the token as a bearer token; without METRICS_TOKEN the endpoint answers 404. docs/METRICS.md lists every metric, with a scrape config, example queries and alerts.

Agent servers

The recommended way to connect a ComfyUI server is the Comfier Agent (comfyui/comfier_agent). The agent connects out to Comfier over a WebSocket, so ComfyUI needs no open port, and servers can belong to members as well as admins. Add one under Servers → + Add a server; the setup page shows the key once and the install steps. See comfyui/comfier_agent/README.md for configuration.

Agents fetch inputs from, and upload outputs to, APP_URL, so it must be reachable from every ComfyUI machine. Your reverse proxy must pass WebSocket upgrades for /api/agent/ws (and allow connections to stay open), for example in nginx:

location /api/agent/ws {
  proxy_pass http://comfier;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_read_timeout 1h;
}

Serving results

Result files are served by Comfier itself at /results/:id/outputs/..., to people allowed to see the result, at URLs that don't expire, with byte ranges (browsers fetch video in pieces). The Docker image runs Thruster in front of Puma: Rails answers with X-Sendfile and Thruster sends the file from disk, so a playing video doesn't hold one of Puma's threads (RAILS_MAX_THREADS, default 3).

  • Behind nginx without Thruster, set SENDFILE_HEADER=X-Accel-Redirect and map the storage folder:

    proxy_set_header X-Sendfile-Type X-Accel-Redirect;
    proxy_set_header X-Accel-Mapping /rails/storage/=/_storage/;
    location /_storage/ { internal; alias /path/to/storage/; }
  • With Puma facing the network directly, leave SENDFILE_HEADER empty and raise RAILS_MAX_THREADS to 5.

  • Finished videos are made browser-safe on arrival: H.264 (yuv420p) with AAC in an MP4 whose index comes first. A file that only has the wrong container or its index at the end is remuxed without re-encoding; anything else is re-encoded at CRF 18. Set VIDEO_NORMALIZE=remux to never re-encode, or off to keep files exactly as they arrive. Sidekiq needs ffmpeg and ffprobe, which the Docker image includes.

  • Any proxy in front must pass Range through and answer it with 206. Buffering is fine; turning a range request into a full 200 stops video in Chrome. Check from a machine outside, with a session cookie copied from the browser and the URL of a video result's file (its Download link without ?download=1):

    curl -sI -H "Cookie: $COOKIE" "$URL"                          # 200, Accept-Ranges: bytes, video/mp4
    curl -sI -H "Cookie: $COOKIE" -H 'Range: bytes=0-1' "$URL"    # 206, Content-Range: bytes 0-1/<size>
    curl -sI -H "Cookie: $COOKIE" -H 'Range: bytes=-1024' "$URL"  # 206

Web and Sidekiq talk to connected agents through Redis, so both need the same REDIS_URL. Sidekiq also runs the periodic jobs in config/schedule.yml (sidekiq-cron), which mark silent servers offline and recover their jobs.

Macs. On Apple Silicon the agent can run image jobs with mflux and video jobs with mlx-video instead of ComfyUI, installed as a login service with uv tool install and comfier-agent service install (the setup page shows the commands). A Mac can run these alone or alongside ComfyUI; either way it runs one job at a time and hands memory between them. Native MiniMax Music 3 and YuE2 audio run through the mlx_audio engine; see MiniMax setup and YuE2 setup. Admins add native styles under Settings → Workflows → Runs on. See docs/mlx-engines-plan.md for the design.

Directly connected servers (added by URL under Settings → Backends) keep working. An admin can convert one with Switch to the Comfier Agent from its ⋯ menu.

Preparing ComfyUI servers for model installs

This section is about directly connected servers; agent servers download models themselves.

Comfier checks which models each backend has through ComfyUI's own /models API; that needs nothing extra. To install missing models from the workflow page, a backend needs one of these:

The Comfier downloader node (recommended). It downloads any direct link into the right models folder. Copy comfyui/comfier_downloader into ComfyUI's custom_nodes folder and restart ComfyUI:

docker cp comfyui/comfier_downloader <comfyui-container>:/path/to/ComfyUI/custom_nodes/   # or copy it onto the volume
docker restart <comfyui-container>

If ComfyUI runs with --base-directory, custom_nodes lives under that directory. Files go into the first path ComfyUI lists for each folder (normally models/<folder> under ComfyUI's base directory). For gated Hugging Face repos or CivitAI files, set HF_TOKEN and/or CIVITAI_TOKEN in ComfyUI's environment; each token is only sent to its own site. To route Hugging Face downloads through a caching proxy or mirror (same idea as huggingface_hub's HF_ENDPOINT), set HF_ENDPOINT on the ComfyUI machine, for example https://cache.lan or https://cache.lan/hf. The Comfier downloader node and Comfier Agent rewrite huggingface.co / hf.co links to that base URL and still send the Hugging Face token as Authorization: Bearer … so the proxy can identify users and fetch gated files upstream. Optional HF_PROXY_TOKEN is sent in X-Proxy-Token (or HF_PROXY_TOKEN_HEADER) when the cache expects its own credential. CDN redirects drop both tokens so nothing leaks to signed URLs. Use Re-check on the backend (or save it) so Comfier notices the node.

ComfyUI-Manager 4 (fallback). When the node isn't installed, Comfier asks Manager instead, which only downloads files that are in Manager's own model catalog, at exactly the folder and file name the workflow uses. Comfier reads the catalog when it checks the backend, and only offers Install for files that are in it; the workflow page lists the rest and why. Many workflows use files Manager doesn't have, so the node is the practical choice. Manager refuses downloads from other machines unless network_mode = personal_cloud (and security_level is normal or lower) in <base directory>/user/__manager/config.ini; restart ComfyUI after changing it. Only do this if the ComfyUI port isn't reachable from untrusted networks.

GitHub Actions runs on every pull request and on pushes to staging and main: Tests (Rails, the ComfyUI downloader node, the Comfier Agent, and the agent end-to-end test), Lint (RuboCop), and Security (Brakeman, bundler-audit, importmap audit). Work branches target staging; see the deployment rules in .cursor/rules/deployment-rules.mdc.

Docker images are built on GitHub and published to ghcr.io/<owner>/comfier-ui:

Workflow When Image tags
Staging Push to staging :staging
Release Manual run on main :latest, :X.Y.Z, :MAJOR

Cut a production release from main with Actions → Release → Run workflow (choose patch, minor, or major), or:

gh workflow run release.yml -f bump=patch
gh workflow run release.yml -f bump=minor -f dry_run=true   # preview only

Set COMFIER_IMAGE=ghcr.io/<owner>/comfier-ui:latest (or :staging on staging) in production .env. The first push to GHCR may require making the package public under the repo's Packages settings.

Architecture

Path What lives there
app/models/generation_kind.rb The four media kinds (label, icon, route), which drive the navbar and studios
app/models/workflow.rb An admin-supplied ComfyUI graph (API format) with {{placeholders}}
app/models/generation.rb One request: prompt, resolved parameters, status, attached outputs
app/models/backend.rb A ComfyUI server; its API token is encrypted at rest
app/services/comfyui/ HTTP client for ComfyUI's API (/prompt, /history, /view, /upload/image, /queue)
app/services/workflow_renderer.rb Substitutes form values into a workflow graph
app/services/backend_selector.rb Picks a backend: the user's preferred one, otherwise the least busy reachable one
app/jobs/submit_generation_job.rb Uploads inputs, renders the graph and queues it on ComfyUI
app/jobs/poll_generation_job.rb Polls history, downloads outputs into Active Storage, times out stuck jobs
app/services/workflow_models.rb Works out which model files a workflow loads, and reads links from UI-format exports
app/services/model_installer.rb, app/jobs/*_model_download_job.rb Queue, start and follow model downloads
comfyui/comfier_downloader/ The ComfyUI custom node that performs downloads on directly connected servers
comfyui/comfier_agent/ The Comfier Agent: a ComfyUI custom node that connects out to Comfier, runs jobs and downloads models
protocol/agent-v1.schema.json JSON Schema for every agent WebSocket message; both sides validate against it
app/services/agent/ The agent WebSocket endpoint, routing, dispatch, job and download lifecycles, reconciliation
app/services/perf/ Run-time samples, statistics, the predictor and per-server speed index used for ETAs and routing
app/services/backend_policy.rb Who can see, use and manage each server
config/schedule.yml sidekiq-cron jobs: offline and lease sweeps, rebalancing, speed index, load rollups
app/models/privacy_notice.rb Code of conduct and privacy notice text, links and version; users must agree before using the app
app/services/queue_estimator.rb Estimates wait times from recent run durations and queue position
app/controllers/shared_controller.rb Gallery of results members chose to share
app/jobs/notify_generation_job.rb Sends finished/failed/cancelled notifications, one retried job per channel
app/mailers/generation_mailer.rb, app/services/slack_notifier.rb Email and Slack DM delivery

How a generation flows

  1. A user submits a studio form. A Generation is saved as queued and SubmitGenerationJob is enqueued.
  2. The job picks a backend, uploads any input image, fills the workflow's placeholders and POSTs to /prompt.
  3. PollGenerationJob checks /history/{id} every two seconds. When ComfyUI finishes, it downloads each output through /view and attaches it.
  4. Every status change is broadcast over Turbo Streams (Action Cable on Redis), so result cards update live.
  5. When it finishes, fails or is cancelled, NotifyGenerationJob emails and/or Slack-messages the owner if they turned notifications on.

Workflow placeholders

Admins export a workflow from ComfyUI with Export (API) and replace literal values with placeholders. The studio form only shows fields for the placeholders a workflow uses.

Placeholder Filled with
{{prompt}}, {{negative_prompt}} What the user typed
{{seed}} The user's seed, or a random one
{{width}}, {{height}} The chosen shape at the workflow's base resolution, rounded to multiples of 64
{{duration}}, {{frames}} Seconds requested, and seconds × frame rate + 1
{{fps}} The workflow's frame rate, so a video is written at the rate its frames were counted for
{{image}} The name of the uploaded input image on the backend

A string that is exactly one placeholder ("{{seed}}") becomes the typed value (an integer here), so numeric inputs stay numeric.

License

MIT. See LICENSE.

About

Simplified front end to comfyui to make it easy for hackerspace members to share instances.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0