nyxxworks / docs /ARCHITECTURE.md
Kazzze's picture
Update to current version
e94c49d verified
|
Raw History Blame Contribute Delete
6.79 kB

Architecture

NyxxWorks is one folder that two kinds of host load: the A1111 family (AUTOMATIC1111, Forge, reForge) as an extension, ComfyUI as a custom node pack. Both get the same core and the same page.

Layers

Layer Where What it is
Core nyxxworks/ The library of pictures, the job queue, cards, axes, recipes, reference cards, detailing, the routes. Plain Python 3.9, imports no host module
Host interface nyxxworks/host.py Host: what the core asks of the program it runs in. FakeHost draws pictures instead of generating them
A1111-family host scripts/nyxxworks_script.py WebUIHost, and the routes added to the host's FastAPI app
ComfyUI host __init__.py, nyxxworks/comfy.py ComfyHost, the routes added to ComfyUI's aiohttp server, and the one node passes run through
Tools nyxxworks/tools/ Copies of the author's other tools and of third-party code, not edited here: anatomy, textfix, lettering, stylegrid, animaip. See SOURCES.md
Page ui/ React, Vite, TypeScript, Zustand, Tailwind. Built into ui/dist, which is committed
Openers javascript/nyxxworks.js, comfy_web/nyxxworks.js One button on the A1111-family page; one command in ComfyUI's menu. Both only open /nyxxworks/ui in a tab

The page is not Gradio and is not shown over the host page: it is a page of its own, served by the host's web server, and it is there also when an A1111-family host runs with --nowebui.

The core

Module What it holds
library.py Every picture as a record in one index file and a PNG beside it, with a small JPEG for the sheet. Sheets, picks, rejections, the tray
jobs.py The queue: one job at a time on the graphics card, progress, cancel
cards.py Styles CSV packs read as cards; the prompt put together by Style Grid's rules
axes.py Sheets varied along one or two axes
recipes.py Recipes as plain JSON files
references.py Reference cards, and which IP-Adapter a style is followed with on the A1111 family
detail.py Going over faces, hands and parts after finishing
shared.py Guard: one index file kept by two programs at once; reading the header of a .safetensors file
web.py Works, whose answer_* functions are everything a route does, and routes(), the route table free of any web framework

web.py gives each route as (method, path, kind, handler). add_fastapi() serves that table on the A1111 family, add_aiohttp() in ComfyUI; register() and register_aiohttp() put the whole of NyxxWorks, its tools included, onto a host's server. A handler is a plain function that returns (status, body), so the tests call it directly.

What a host gives

One object with these methods (nyxxworks/host.py):

Method What it answers
model(), models(), loras(), samplers(), schedulers(), upscalers() What the host has
model_defaults() Settings a model starts the form with (ComfyUI's models loaded in parts)
detectors() The detector files for detailing
style_files() Where packs of cards are
references(model) Which kinds of reference the host can follow with that model, and with what
generate(request, count, on_image, stopped) Make the pictures of a sheet
finish(image, params, how) Enlarge a picture and go over it
repaint(image, mask, params, how) Repaint a spot, nothing outside it
progress(), interrupt() How far the pass is; stop it
anatomy(), text() The host objects the copied tools ask for

How a job travels

  1. The page posts a request to /nyxxworks/sheet (or /matrix, /finish, /fix/repaint).
  2. Works cleans the request, settles a seed of -1, makes a sheet record in the library and puts a job into the queue.
  3. The queue's worker thread calls the host: generate() for a sheet, finish() and then detail.run() for finishing, repaint() for a spot.
  4. The host hands each picture back as it is made. The library writes the PNG with its parameters and the thumbnail, and adds the record to the index.
  5. The page asks /nyxxworks/jobs while a job runs and /nyxxworks/library when one ends.

On the A1111 family the pass runs under the host's own queue lock, with a script runner of its own, so the host's other extensions do not take part in it. In ComfyUI the pass is queued as one node, NyxxWorks (internal), through ComfyUI's own /prompt, so it waits its turn with the user's workflows.

The tools

The Fix station's anatomy and text tools and the Letter station are whole tools copied from their own repositories. Their Python is byte for byte the same as there; their address, settings files and fonts folder are set from outside, in web.py (attach_anatomy(), attach_textfix(), attach_lettering()). Their editors are in ui/src/stations/ with only the import paths and the bridge changed: each talks to the rest of the page by a call inside the page, where the original talks to a page around an iframe.

SOURCES.md says what came from which commit, so a fix made there can be carried over by hand.

The data folder

data/ inside the extension folder, or the folder the environment variable NYXXWORKS_DATA names.

In it What
index.json The library: sheets, pictures, marks, the tray
images/ Each picture as <id>.png, with its thumbnail
settings.json The forms as they were last
names.json Which names ComfyUI has for the samplers and schedules of the A1111 family, written by a host of that family from its own lists (recipes.same_names). The statistics count such a value under one name on both hosts
recipes/ One JSON file for each recipe; Download gives it as .nyxx.json
references/ The reference cards
letter-settings.json, text-settings.json, anatomy-settings.json The settings of the Letter station, the text tool and the anatomy tool

The library keeps the drafts of the newest KEEP_SHEETS sheets (12, what Pick shows; library.newest_first is the one order both use). When it is opened and each time a new sheet begins, the other drafts lose their files; their records stay in the index marked "gone", so that Statistics counts them, and are left out of everything else. A draft that is picked, or that is the parent of a final or a variant, is never thrown away.

Two hosts given the same folder keep one library. Every reading and change of an index goes through a Guard (shared.py): one writer at a time across both programs, and the index is read again when the other program has changed the file.