# System map — AUTOMATIC1111/stable-diffusion-webui

> Canonical page: https://codevetter.com/unpack/stable-diffusion-webui/system-map

# System map — AUTOMATIC1111/stable-diffusion-webui

Scanned commit 82a973c04367123ae98bd9abdf80d9eda9b910e2 (2024-07-27). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

A single-process Python application with a thin shell launcher (webui.sh/webui.bat) that runs launch.py, which delegates to modules/launch_utils.py to install torch/pip requirements, git-clone pinned dependency repos into repositories/, then imports webui.py. webui.py either builds a Gradio Blocks UI (modules/ui.py create_ui) plus optional REST routes (modules/api/api.py, mounted only with --api/--nowebui), or runs FastAPI-only mode on port 7861. All generation state lives in module-level globals in modules/shared.py (shared.sd_model, shared.opts, shared.state). Checkpoints are loaded by modules/sd_models.py through modules/safe.py's monkeypatched torch.load; settings persist to config.json via modules/options.py; user data roots are computed in modules/paths_internal.py.
- launch.py is the real entrypoint: main() optionally dumps sysinfo, calls launch_utils.prepare_environment() (pip installs, repo clones, extension installers) unless --skip-prepare-environment, optionally configure_for_tests() for --test-server, then start() which imports webui and calls webui() or api_only(). — [launch.py#L27-44](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/launch.py#L27-L44) [modules/launch_utils.py#L463-469](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/launch_utils.py#L463-L469)
- webui.py's webui() runs an outer while-loop that calls initialize.initialize() once, then repeatedly: ui_tempdir.cleanup_tmpdr(), script_callbacks.before_ui_callback(), shared.demo = ui.create_ui(), shared.demo.queue(64), shared.demo.launch(...), then blocks on shared.state.wait_for_server_command(timeout=5) for 'stop'/'restart' to support in-process UI restart. — [webui.py#L48-153](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/webui.py#L48-L153)
- The REST API is an APIRouter-free design: modules/api/api.py's Api class registers ~40 /sdapi/v1/* routes directly on the FastAPI app inside webui.create_api(app), gated behind --api (alongside UI) or --nowebui (api_only, port default 7861). — [webui.py#L18-45](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/webui.py#L18-L45) [modules/api/api.py#L199-251](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/api/api.py#L199-L251) [modules/cmd_args.py#L101-104](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/cmd_args.py#L101-L104)
- modules/shared.py is a global state bag: it holds cmd_opts, opts (Options), sd_model, state (shared_state.State), demo (gr.Blocks), prompt_styles, total_tqdm, mem_mon, and re-exports paths/constants; nearly every module reads/writes these globals. — [modules/shared.py#L14-94](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/shared.py#L14-L94)
- modules/paths_internal.py computes all storage roots at import time: script_path (repo root), data_path (--data-dir, default repo root), models_path (--models-dir or data_path/models), extensions_dir (data_path/extensions), extensions_builtin_dir (script_path/extensions-builtin), and reads COMMANDLINE_ARGS env var into sys.argv. — [modules/paths_internal.py#L12-36](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/paths_internal.py#L12-L36)
- launch_utils.prepare_environment() installs torch (TORCH_COMMAND/TORCH_INDEX_URL env overridable, default cu121 wheels torch==2.1.2), verifies CUDA unless --skip-torch-cuda-test, installs clip/open_clip/xformers, and git-clones five pinned dependency repos (assets, stablediffusion, generative-models, k-diffusion, BLIP) into repositories/ at pinned commit hashes. — [modules/launch_utils.py#L318-431](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/launch_utils.py#L318-L431)
- initialize.initialize() (modules/initialize.py) is the heavyweight boot: fix_torch_version/tls/sigint utils, sd_models.setup_model(), codeformer and gfpgan model dirs, then initialize_rest() which sets samplers, lists extensions, restores config state, lists models/localizations, calls scripts.load_scripts(), loads upscalers/VAEs/embeddings, registers extra networks, and spawns a background Thread to load the SD model via shared.sd_model. — [modules/initialize.py#L51-169](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/initialize.py#L51-L169)
- The Gradio UI is built in modules/ui.py create_ui() which constructs gr.Blocks for txt2img, img2img (with sub-tabs: img2img/Sketch/Inpaint/Inpaint sketch/Inpaint upload/Batch), Extras, PNG Info, Train, Checkpoint Merger, then appends script-provided tabs via script_callbacks.ui_tabs_callback() plus built-in Settings and Extensions tabs, sorted by opts.ui_tab_order. — [modules/ui.py#L253-268](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/ui.py#L253-L268) [modules/ui.py#L537-593](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/ui.py#L537-L593) [modules/ui.py#L1110-1148](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/ui.py#L1110-L1148)
- Generation work is serialized through a single modules/call_queue.py queue_lock (a FIFOLock): wrap_gradio_gpu_call wraps every GPU-bound gradio handler and the API shares the same lock via Api(app, queue_lock), so only one generation job runs at a time. — [modules/call_queue.py#L8-46](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/call_queue.py#L8-L46) [webui.py#L18-23](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/webui.py#L18-L23)
- Settings are owned by modules/options.py Options class (data_labels OptionInfo registry defined in modules/shared_options.py) persisted as JSON to shared.config_filename (--ui-settings-file, default data_path/config.json); Options.load() contains migration code for legacy keys (sd_vae_as_default, quicksettings, ui_reorder). — [modules/options.py#L82-228](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/options.py#L82-L228) [modules/shared_options.py#L9-12](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/shared_options.py#L9-L12) [modules/shared.py#L20](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/shared.py#L20)
- modules/sd_models.py manages the checkpoint registry (checkpoints_list of CheckpointInfo), list_models() scans ckpt dirs, load_model() builds the model via instantiate_from_config + LoadStateDictOnMeta, applies fp16 conversion, and calls sd_hijack.model_hijack.hijack(sd_model); torch.load is globally monkeypatched by modules/safe.py to run a pickle-safety scan (check_pt) unless --disable-safe-unpickle. — [modules/sd_models.py#L786-860](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/sd_models.py#L786-L860) [modules/sd_models.py#L318-323](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/sd_models.py#L318-L323) [modules/safe.py#L194-195](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/safe.py#L194-L195)
- Deployment is user-run local install: webui.sh/webui.bat create/activate a venv (venv_dir configurable in webui-user.sh) and exec launch.py; there is no packaging, docker, or service config in the repo — CI runs it as a plain process on port 7860. — [webui.sh](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/webui.sh) [.github/workflows/run_tests.yaml](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/.github/workflows/run_tests.yaml)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
