feat(ui): modularize admin scope into independent modules#3137
Merged
Conversation
10 tasks
9b2fbe3 to
d8b8aaa
Compare
d8b8aaa to
81c8271
Compare
59319b4 to
0c9f317
Compare
ca9317f to
53477a6
Compare
4802832 to
f1e5e15
Compare
c4ace4e to
9904982
Compare
581bdf2 to
a114e4c
Compare
vishu-bh
previously approved these changes
Apr 2, 2026
Collaborator
vishu-bh
left a comment
There was a problem hiding this comment.
LGTM
Ran admin UI locally and all looks okay.
Collaborator
|
@vishu-bh Rebased and resolved the secrets baseline conflict. |
3887fda to
aaa7b65
Compare
Signed-off-by: Gabriel Costa <gabrielcg@proton.me>
aaa7b65 to
7369c61
Compare
This was referenced Apr 3, 2026
This was referenced Apr 5, 2026
This was referenced Apr 7, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Admin UI Modularisation
The Problem
The original
mcpgateway/static/admin.jswas a 33,812-line monolithic file — all UI logic, state management, API calls, validation, and event handling in one place. It was untestable in isolation, slow to load, and impossible to maintain at scale.What Was Done
1. Decomposition into 44 ES Modules (
mcpgateway/admin_ui/)The monolith was split into focused, single-responsibility modules across four conceptual layers:
bootstrap.js,appState.js,utils.js,constants.js,security.jstools.js,servers.js,teams.js,gateway.js,tokens.js,llmModels.js,llmChat.js,prompts.js,resources.js,users.js,roots.js,a2aAgents.jsauth.js,filters.js,search.js,tabs.js,pagination.js,modals.js,logging.js,metrics.js,plugins.js,monitoring.js, etc.initialization.js,events.js,app.js,formSubmitHandlers.js2. Facade Pattern (
admin_ui/admin.js)A single facade aggregates all 35+ module exports and exposes them onto the
window.Adminnamespace — preserving the existing HTML contract where HTMX/Alpine templates callAdmin.editTool(...),Admin.showTab(...), etc. No template changes required.3. Vite Build Pipeline
A new Vite configuration (
vite.config.js) bundlesadmin_ui/index.jsinto an IIFE format output atmcpgateway/static/bundle-[HASH].js. The hash changes on every rebuild, providing automatic cache busting. External libraries (HTMX, Alpine, Chart.js, CodeMirror, DOMPurify) remain CDN-loaded and are declared as globals — not bundled.Python's
mcpgateway/admin.pyreads the Vite manifest at startup to resolve the hashed filename, injecting it into the admin template as{{ bundle_js }}.4. Test Suite: 20% → 70%+ Coverage
44 new Vitest unit test files in
tests/unit/js/, one per module, using:jsdomenvironment to simulate the browser DOMvi.mock()for clean module isolationAppState.reset()inafterEachto prevent test pollutionThe
vitest.config.jsinstruments onlymcpgateway/admin_ui/**/*.js(not the compiled bundle), giving accurate per-module coverage.5. Playwright Tests Maintained
End-to-end Playwright tests continue to pass at the same success rate — the public API (
window.Admin.*) is unchanged, so browser-level test contracts were not broken by the refactor.Key Design Decisions
bootstrap.jsmust initialisewindow.Adminbefore any module tries to write to it.events.js,app.js): modules that need to self-register event listeners at load time use the IIFE pattern rather than pure ES module exports.appState.jsacts as the shared hub;utils.jsandconstants.jshave zero app-level dependencies; domain modules only import from the foundation layer.emptyOutDir: falsein Vite config: preserves vendor files, images, and other static assets alongside the bundle.File Map
mcpgateway/admin_ui/*.jsmcpgateway/admin_ui/index.jsmcpgateway/admin_ui/admin.jswindow.Adminmcpgateway/admin.pyget_bundle_js_filename()— resolves hashed name at startupmcpgateway/templates/admin.html{{ bundle_js }}vite.config.jsvitest.config.jspackage.jsontests/unit/js/*.test.js