This PR builds on the changes from PR #17433. The diff currently shows cumulative changes from both PRs. Once PR #17433 is merged, I will rebase this branch and the diff will show only the changes specific to this PR.
Part 4/4 of the config refactoring series.
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests to validate the changes?
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
BREAKING CHANGE: Significant changes that may affect compatibility
build: Changes that affect the build system or external dependencies
ci: Changes to our continuous integration processes or workflows
chore: Refactor, cleanup, or other non-functional code changes
docs: Documentation update or addition
feat: Introduces a new feature or enhancement to the codebase
fix: Bug fix or error correction
i18n: Internationalization or localization changes
perf: Performance improvement
refactor: Code restructuring for better maintainability, readability, or scalability
style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
test: Adding missing tests or correcting existing tests
WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
Implement centralized bootstrap initialization that replaces scattered app.state.config.X assignments throughout main.py with a single ConfigStateBoostrap(app).bootstrap_config_state() call. This completes the config.py refactoring series by providing a clean, maintainable initialization pattern that automatically discovers and sets all configuration values. This is the final part (4/4) of the config.py refactoring series.
Added
ConfigStateBoostrap(app) class: Centralized configuration initialization system
bootstrap_config_state() class method that systematically sets all app.state.config.X fields
Automatic configuration discovery through registry pattern
Configuration validation and error handling during bootstrap
Initialization logging and debugging support
Configuration registry system: Automatic discovery of all PersistentConfig instances
Registry automatically tracks all configuration variables across all modules
Bootstrap iterates through registry to set app.state.config.{config_name} = config_instance
New configurations automatically picked up without manual registration
Centralized initialization logic: Single point of truth for app state configuration
Changed
Simplified main.py: Replaced ~50+ scattered app.state.config.X = Y assignments with single bootstrap call
Cleaner application startup: One-line configuration initialization instead of dozens of manual assignments
Improved maintainability: All configuration initialization logic centralized in bootstrap class
Better error handling: Centralized configuration loading with proper error management
Before/After: main.py Transformation
Before (scattered assignments):
# Dozens of manual assignments throughout main.py:app.state.config.OLLAMA_BASE_URL=OLLAMA_BASE_URLapp.state.config.OPENAI_API_KEY=OPENAI_API_KEYapp.state.config.WEBUI_AUTH=WEBUI_AUTHapp.state.config.ENABLE_SIGNUP=ENABLE_SIGNUPapp.state.config.DEFAULT_USER_ROLE=DEFAULT_USER_ROLE# ... 45+ more lines of manual assignments
All scattered app.state.config.X assignments from main.py (replaced by bootstrap)
Manual configuration initialization throughout startup sequence
Duplicate configuration setup logic in various parts of main.py
Fixed
Configuration initialization reliability: Centralized bootstrap ensures no config variables are missed
Maintenance burden: Adding new configs no longer requires updating multiple places in main.py
Initialization consistency: All configurations follow the same initialization pattern
Security
None
Breaking Changes
No breaking changes - All existing app.state.config.X access patterns throughout the codebase continue to work unchanged
Configuration values are set identically to before, just through centralized bootstrap instead of manual assignments
Additional Information
This completes the config.py refactoring series (4/4) 🎉
Major architectural achievement: Transformed monolithic ~3k-line config.py into clean, modular structure
100% backward compatibility maintained - no existing code needs updates
See discussion: #17429 for the complete refactoring plan
Screenshots or Videos
[Attach any relevant screenshots or videos demonstrating the changes]
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/17436
**Author:** [@luxass](https://github.com/luxass)
**Created:** 9/14/2025
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `refactor/add-state-config-bootstrap`
---
### 📝 Commits (10+)
- [`5ee3521`](https://github.com/open-webui/open-webui/commit/5ee3521647152a91e29b4bd4c81bed221af29dea) refactor: move config.py into config/ package structure
- [`61ce6c4`](https://github.com/open-webui/open-webui/commit/61ce6c47045105ff9cb63e6e7b8368667c2eed2b) refactor(logging): move logging setup to a dedicated module
- [`c9639dd`](https://github.com/open-webui/open-webui/commit/c9639dd8bdd54de4c11345bb84d9f0618b1dda67) refactor(config): reorganize configuration modules and enhance structure
- [`d300bdf`](https://github.com/open-webui/open-webui/commit/d300bdf4bf1a2ac9b4d1bd2954e6d9d1e4d374e5) chore: format
- [`5efefcb`](https://github.com/open-webui/open-webui/commit/5efefcbad6452fa2d7e4cf44d61cd2ac25cbc3fc) Merge branch 'dev' into refactor/move-to-config-module
- [`8b67a4a`](https://github.com/open-webui/open-webui/commit/8b67a4aad31736e028ce4344c183c777c4d5a736) Merge branch 'dev' into refactor/move-to-config-module
- [`5d1ae32`](https://github.com/open-webui/open-webui/commit/5d1ae32ed9ac7bef76ca3d70c128f74ae3add1c1) chore: format
- [`56bfb79`](https://github.com/open-webui/open-webui/commit/56bfb794fac197ffccbedbd9078ba02eae9344d7) Merge branch 'refactor/move-to-config-module' into refactor/extract-core-config
- [`3b71b86`](https://github.com/open-webui/open-webui/commit/3b71b866577baee3119b527c6c813041c0d723be) refactor(config): reorganize imports and create llm module
- [`e0a2faa`](https://github.com/open-webui/open-webui/commit/e0a2faaad7f8f43053d13d0356128b1ff3ef2456) feat(config): add authentication configuration module
### 📊 Changes
**37 files changed** (+3976 additions, -4257 deletions)
<details>
<summary>View changed files</summary>
➖ `backend/open_webui/config.py` (+0 -3483)
➕ `backend/open_webui/config/__init__.py` (+8 -0)
➕ `backend/open_webui/config/core/__init__.py` (+9 -0)
➕ `backend/open_webui/config/core/auth.py` (+626 -0)
➕ `backend/open_webui/config/core/base.py` (+172 -0)
➕ `backend/open_webui/config/core/bootstrap.py` (+167 -0)
➕ `backend/open_webui/config/core/database.py` (+79 -0)
➕ `backend/open_webui/config/core/logging.py` (+15 -0)
➕ `backend/open_webui/config/features/__init__.py` (+11 -0)
➕ `backend/open_webui/config/features/admin.py` (+36 -0)
➕ `backend/open_webui/config/features/features.py` (+72 -0)
➕ `backend/open_webui/config/features/misc.py` (+98 -0)
➕ `backend/open_webui/config/features/permissions.py` (+211 -0)
➕ `backend/open_webui/config/features/static.py` (+113 -0)
➕ `backend/open_webui/config/features/tasks.py` (+311 -0)
➕ `backend/open_webui/config/features/ui.py` (+134 -0)
➕ `backend/open_webui/config/integrations/__init__.py` (+10 -0)
➕ `backend/open_webui/config/integrations/code_interpreter.py` (+133 -0)
➕ `backend/open_webui/config/integrations/llm.py` (+127 -0)
➕ `backend/open_webui/config/integrations/media.py` (+455 -0)
_...and 17 more files_
</details>
### 📄 Description
**⚠️ DEPENDS ON PR #17433**
This PR builds on the changes from PR #17433. The diff currently shows cumulative changes from both PRs. Once PR #17433 is merged, I will rebase this branch and the diff will show only the changes specific to this PR.
**Part 4/4** of the config refactoring series.
# Pull Request Checklist
### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request.
**Before submitting, make sure you've checked the following:**
- [x] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [x] **Description:** Provide a concise description of the changes made in this pull request.
- [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [x] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
- [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Have you written and run sufficient tests to validate the changes?
- [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following:
- **BREAKING CHANGE**: Significant changes that may affect compatibility
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our continuous integration processes or workflows
- **chore**: Refactor, cleanup, or other non-functional code changes
- **docs**: Documentation update or addition
- **feat**: Introduces a new feature or enhancement to the codebase
- **fix**: Bug fix or error correction
- **i18n**: Internationalization or localization changes
- **perf**: Performance improvement
- **refactor**: Code restructuring for better maintainability, readability, or scalability
- **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
- **test**: Adding missing tests or correcting existing tests
- **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
Implement centralized bootstrap initialization that replaces scattered `app.state.config.X` assignments throughout `main.py` with a single `ConfigStateBoostrap(app).bootstrap_config_state()` call. This completes the config.py refactoring series by providing a clean, maintainable initialization pattern that automatically discovers and sets all configuration values. This is the final part (4/4) of the config.py refactoring series.
### Added
- **`ConfigStateBoostrap(app)` class**: Centralized configuration initialization system
- `bootstrap_config_state()` class method that systematically sets all `app.state.config.X` fields
- Automatic configuration discovery through registry pattern
- Configuration validation and error handling during bootstrap
- Initialization logging and debugging support
- **Configuration registry system**: Automatic discovery of all `PersistentConfig` instances
- Registry automatically tracks all configuration variables across all modules
- Bootstrap iterates through registry to set `app.state.config.{config_name} = config_instance`
- New configurations automatically picked up without manual registration
- **Centralized initialization logic**: Single point of truth for app state configuration
### Changed
- **Simplified `main.py`**: Replaced ~50+ scattered `app.state.config.X = Y` assignments with single bootstrap call
- **Cleaner application startup**: One-line configuration initialization instead of dozens of manual assignments
- **Improved maintainability**: All configuration initialization logic centralized in bootstrap class
- **Better error handling**: Centralized configuration loading with proper error management
#### Before/After: main.py Transformation
**Before (scattered assignments):**
```python
# Dozens of manual assignments throughout main.py:
app.state.config.OLLAMA_BASE_URL = OLLAMA_BASE_URL
app.state.config.OPENAI_API_KEY = OPENAI_API_KEY
app.state.config.WEBUI_AUTH = WEBUI_AUTH
app.state.config.ENABLE_SIGNUP = ENABLE_SIGNUP
app.state.config.DEFAULT_USER_ROLE = DEFAULT_USER_ROLE
# ... 45+ more lines of manual assignments
```
**After (single bootstrap call):**
```python
config_bootstrap = ConfigStateBootstrap(app)
config_bootstrap.bootstrap_config_state()
```
### Deprecated
- None
### Removed
- **All scattered `app.state.config.X` assignments** from `main.py` (replaced by bootstrap)
- **Manual configuration initialization** throughout startup sequence
- **Duplicate configuration setup logic** in various parts of main.py
### Fixed
- **Configuration initialization reliability**: Centralized bootstrap ensures no config variables are missed
- **Maintenance burden**: Adding new configs no longer requires updating multiple places in main.py
- **Initialization consistency**: All configurations follow the same initialization pattern
### Security
- None
### Breaking Changes
- **No breaking changes** - All existing `app.state.config.X` access patterns throughout the codebase continue to work unchanged
- Configuration values are set identically to before, just through centralized bootstrap instead of manual assignments
---
### Additional Information
- This **completes the config.py refactoring series** (4/4) 🎉
- **Major architectural achievement**: Transformed monolithic ~3k-line config.py into clean, modular structure
- **100% backward compatibility maintained** - no existing code needs updates
- See discussion: #17429 for the complete refactoring plan
### Screenshots or Videos
- [Attach any relevant screenshots or videos demonstrating the changes]
### Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/17436
Author: @luxass
Created: 9/14/2025
Status: ❌ Closed
Base:
dev← Head:refactor/add-state-config-bootstrap📝 Commits (10+)
5ee3521refactor: move config.py into config/ package structure61ce6c4refactor(logging): move logging setup to a dedicated modulec9639ddrefactor(config): reorganize configuration modules and enhance structured300bdfchore: format5efefcbMerge branch 'dev' into refactor/move-to-config-module8b67a4aMerge branch 'dev' into refactor/move-to-config-module5d1ae32chore: format56bfb79Merge branch 'refactor/move-to-config-module' into refactor/extract-core-config3b71b86refactor(config): reorganize imports and create llm modulee0a2faafeat(config): add authentication configuration module📊 Changes
37 files changed (+3976 additions, -4257 deletions)
View changed files
➖
backend/open_webui/config.py(+0 -3483)➕
backend/open_webui/config/__init__.py(+8 -0)➕
backend/open_webui/config/core/__init__.py(+9 -0)➕
backend/open_webui/config/core/auth.py(+626 -0)➕
backend/open_webui/config/core/base.py(+172 -0)➕
backend/open_webui/config/core/bootstrap.py(+167 -0)➕
backend/open_webui/config/core/database.py(+79 -0)➕
backend/open_webui/config/core/logging.py(+15 -0)➕
backend/open_webui/config/features/__init__.py(+11 -0)➕
backend/open_webui/config/features/admin.py(+36 -0)➕
backend/open_webui/config/features/features.py(+72 -0)➕
backend/open_webui/config/features/misc.py(+98 -0)➕
backend/open_webui/config/features/permissions.py(+211 -0)➕
backend/open_webui/config/features/static.py(+113 -0)➕
backend/open_webui/config/features/tasks.py(+311 -0)➕
backend/open_webui/config/features/ui.py(+134 -0)➕
backend/open_webui/config/integrations/__init__.py(+10 -0)➕
backend/open_webui/config/integrations/code_interpreter.py(+133 -0)➕
backend/open_webui/config/integrations/llm.py(+127 -0)➕
backend/open_webui/config/integrations/media.py(+455 -0)...and 17 more files
📄 Description
⚠️ DEPENDS ON PR #17433
This PR builds on the changes from PR #17433. The diff currently shows cumulative changes from both PRs. Once PR #17433 is merged, I will rebase this branch and the diff will show only the changes specific to this PR.
Part 4/4 of the config refactoring series.
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Implement centralized bootstrap initialization that replaces scattered
app.state.config.Xassignments throughoutmain.pywith a singleConfigStateBoostrap(app).bootstrap_config_state()call. This completes the config.py refactoring series by providing a clean, maintainable initialization pattern that automatically discovers and sets all configuration values. This is the final part (4/4) of the config.py refactoring series.Added
ConfigStateBoostrap(app)class: Centralized configuration initialization systembootstrap_config_state()class method that systematically sets allapp.state.config.XfieldsConfiguration registry system: Automatic discovery of all
PersistentConfiginstancesapp.state.config.{config_name} = config_instanceCentralized initialization logic: Single point of truth for app state configuration
Changed
main.py: Replaced ~50+ scatteredapp.state.config.X = Yassignments with single bootstrap callBefore/After: main.py Transformation
Before (scattered assignments):
After (single bootstrap call):
Deprecated
Removed
app.state.config.Xassignments frommain.py(replaced by bootstrap)Fixed
Security
Breaking Changes
app.state.config.Xaccess patterns throughout the codebase continue to work unchangedAdditional Information
Screenshots or Videos
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.