# Refactor map: init deps and app.js

Used for the **smart refactor** (branch `refactor/smart-extract`). Do not remove code that provides a dep without moving it or re‑wiring the contract.

## Entry point

- **`Blueprint.init.runInit(deps)`** is called from **app.js** inside `function init()` (around line 6496). The `deps` object is built inline and passed once. Script order: **app-init.js** loads first, then **app.js** runs and calls `init()` on DOMContentLoaded or immediately.

## Bootstrap (tail of app.js)

- **Lines ~6496–end:** `function init() { ... Blueprint.init.runInit({ ... }); }` plus the `if (document.readyState === 'loading') ... else init();` and the closing `})();` of the main IIFE.
- **Risk:** If app.js is truncated or the end is lost, the app never starts. **Step 2:** Extract this bootstrap into `js/app-bootstrap.js` (load after app.js) so the tail is not inside the large file.

## Init deps: full list and where defined

`app-init.js` expects these symbols on `deps`. Source is either **app.js** (with line number) or **other** (Blueprint/window/other script – must be in scope when app.js builds the deps object).

| dep | type | location |
|-----|------|----------|
| CONFIGS | var | app.js:266 |
| TEST_SUITE_CODE | var | app.js:296 |
| VALID_SECTIONS | var | app.js:1659 |
| bindGuideStepOrderButtons | function | app.js:5518 |
| bindStepCodeEvents | function | app.js:5288 |
| bindStepImageEvents | function | app.js:5388 |
| buildStepCodeBlockHtml | function | app.js:5267 |
| buildStepImageBlockHtml | function | app.js:5255 |
| canAddProject | function | app.js:6800 |
| closeAuthModal | function | app.js:15 |
| closeRowEditModal | function | app.js:6364 |
| closeStakeholderTakeawaysModal | function | app.js:4840 |
| closeTemplateDropdown | function | app.js:5738 |
| closeUserChecklistModal | function | app.js:6389 |
| closeUserInterviewsModal | function | app.js:6413 |
| copyStakeholderTakeawaysToProjectNotes | function | app.js:4859 |
| copyToClipboard | function | app.js:1441 |
| createFromTemplate | function | app.js:5705 |
| currentProjectId | var | app.js:1063 |
| downloadFile | function | app.js:1483 |
| escapeHtml | ? | other (e.g. app-core.js / Blueprint) |
| exportBrief | function | app.js:4895 |
| exportGuideMarkdown | function | app.js:5791 |
| extractEventsFromFramework | function | app.js:1546 |
| fetchAppNotice | function | app.js:4615 |
| fetchChecklistContent | function | app.js:674 |
| fetchGa4TrackingConfig | function | app.js:97 |
| fetchGaAuditStandardChecklist | function | app.js:733 |
| fetchGetStartedSlides | function | app.js:992 |
| fetchGuideTemplatesContent | function | app.js:1032 |
| fetchInterviewContent | function | app.js:931 |
| fetchPlansFromDB | function | app.js:1912 |
| fetchPromoTipsContent | function | app.js:973 |
| fetchUserGuideContent | function | app.js:248 |
| fetchValuedResourcesContent | function | app.js:960 |
| formatDomainsForCode | function | app.js:1238 |
| formatEventAsCode | function | app.js:1173 |
| formatEventAsGtag | function | app.js:1176 |
| formatExternalDomainsForCode | function | app.js:1254 |
| generateGtmExport | function | app.js:1615 |
| getBriefQuestions | function | app.js:4883 |
| getCheckEntry | function | app.js:1386 |
| getChecklistAsMarkdown | function | app.js:4697 |
| getChecklistIds | function | app.js:666 |
| getCrossDomainTabFromPathname | function | app.js:1836 |
| getCurrentEventFromBuilder | function | app.js:1200 |
| getCurrentFrameworkRows | function | app.js:5860 |
| getCurrentSection | ? | other (e.g. app-core.js) |
| getCurrentUserId | ? | other / getter in app.js |
| getCurrentUserPlanSlug | ? | other / getter |
| getCurrentUserRole | ? | other / getter |
| getDatalayerConfig | function | app.js:50 |
| getFrameworkBrief | function | app.js:6294 |
| getFrameworkEventNamesForAudit | function | app.js:5886 |
| getFrameworkGridCSV | function | app.js:6272 |
| getFrameworkGridMarkdown | function | app.js:6284 |
| getFrameworkGridText | function | app.js:6263 |
| getFrameworkOptions | function | app.js:5809 |
| getFrameworkRows | function | app.js:5840 |
| getGaAuditChecklistDataReady | ? | other (e.g. ga-audit) |
| getGtmTagEventHint | function | app.js:1524 |
| getGuideFromForm | function | app.js:5223 |
| getImplementationToolsTabFromPathname | function | app.js:1842 |
| getProfileCache | ? | other / getter |
| getProjectApiSecret | function | app.js:1265 |
| getProjectDomains | function | app.js:1231 |
| getProjectMeasurementId | function | app.js:1260 |
| getProjectServerEvents | function | app.js:1090 |
| getQuestionsAsMarkdown | function | app.js:4755 |
| getSectionIdFromPathname | function | app.js:1831 |
| getServerSideCodeWithPlaceholders | function | app.js:1216 |
| getStakeholdersAsMarkdown | function | app.js:4767 |
| getStoredChecks | function | app.js:1350 |
| getStoredProjects | ? | other / app.js under different name |
| getStoredTheme | function | app.js:1323 |
| getSupabaseClient | function | app.js:25 |
| getWorkingCopyRows | ? | other / getter |
| hideSyncStatus | function | app.js:5025 |
| initializeImplementationTools | function | app.js:1952 |
| invalidateImplementationChecklistCache | function | app.js:607 |
| isChecked | function | app.js:1399 |
| isUuid | function | app.js:1082 |
| loadAdminGaAuditChecklist | function | app.js:2728 |
| loadFromSupabase | function | app.js:5045 |
| loadGuide | function | app.js:5564 |
| mergeFrameworkRows | function | app.js:6056 |
| newGuide | function | app.js:5694 |
| normalizeRow | function | app.js:1311 |
| openAuthModal | function | app.js:8 |
| openDeliverableExportModal | ? | other (e.g. app-deliverable-export.js) |
| openRowAdd | function | app.js:6341 |
| openStakeholderTakeawaysModal | function | app.js:4825 |
| openUserChecklistModal | function | app.js:6383 |
| openUserInterviewsModal | function | app.js:6407 |
| parseGtmExport | function | app.js:1495 |
| pathnameForSection | function | app.js:1848 |
| persistSelectedProjectIdToServer | function | app.js:1131 |
| populateFrameworkSelect | function | app.js:6438 |
| populateGuideSelect | function | app.js:5549 |
| pushToDataLayer | ? | other (e.g. app-core / tracking) |
| refreshInterviewsUI | function | app.js:4922 |
| refreshUIAfterSupabaseLoad | function | app.js:6664 |
| renderGetStartedCarousel | function | app.js:4147 |
| renderGtmComparison | function | app.js:1585 |
| renderGtmImportSummary | function | app.js:1555 |
| renderPricingTable | function | app.js:2322 |
| renderSnippetList | var | app.js:1880 |
| resetUserChecklist | function | app.js:4536 |
| resetUserInterviewContent | function | app.js:4593 |
| saveCurrentGuide | function | app.js:5582 |
| saveCurrentProjectIfAny | function | app.js:6468 |
| saveGuideAsUserTemplate | function | app.js:5717 |
| saveProfile | function | app.js:214 |
| saveRowFromForm | function | app.js:6418 |
| saveStakeholderTakeawaysModal | function | app.js:4845 |
| saveUserChecklistFromForm | function | app.js:4503 |
| saveUserInterviewContentFromForm | function | app.js:4555 |
| setChecklistState | function | app.js:1429 |
| setCurrentFrameworkRows | function | app.js:5918 |
| setCurrentFrameworkSourceUrl | ? | other |
| setCurrentUserId | ? | other / setter |
| setCurrentUserPlanSlug | ? | other / setter |
| setCurrentUserRole | ? | other / setter |
| setGuideToForm | function | app.js:5445 |
| setProfileCache | ? | other / setter |
| setProjectBriefQuestions | function | app.js:1154 |
| setStoredChecks | function | app.js:1367 |
| setSupabaseFrameworks | ? | other |
| setSupabaseGuides | ? | other |
| setSupabaseProjects | ? | other |
| setTheme | function | app.js:1337 |
| setUserChecklistSectionsOverride | ? | other |
| setUserGuideTemplatesOverride | ? | other |
| setUserInterviewQuestionBankOverride | ? | other |
| setUserInterviewTemplatesOverride | ? | other |
| setWorkingCopyRows | ? | other |
| showSection | function | app.js:2155 |
| supabaseClient | var | app.js:32 |
| switchCrossDomainTab | function | app.js:1940 |
| switchImplementationToolsTab | function | app.js:2062 |
| switchToTemplate | function | app.js:6453 |
| updateContactButtonVisibility | function | app.js:4661 |
| updateDomainCodeBlocks | function | app.js:1297 |
| updateGuideStepNumbers | function | app.js:5513 |
| updatePageSEO | ? | other |
| updatePlanUI | function | app.js:6812 |
| updateProgress | function | app.js:4678 |
| updatePromoSidebar | function | app.js:1776 |
| updateServerSideCodeBlock | function | app.js:1290 |
| uploadLocalToSupabase | function | app.js:5129 |
| useSupabaseData | var | app.js:1071 |
| validateDomains | function | app.js:6479 |

## Summary

- **~115 deps** in app-init’s `runInit(deps)`.
- **~95** are defined in app.js (function or var at the line above).
- **~20** are marked `?` / other: likely getters/setters, Blueprint.*, or from scripts that run before app.js (e.g. app-core.js, app-deliverable-export.js). When extracting, resolve these and keep the single dep contract (e.g. “all deps come from `window` or from a single `deps` object built in one place”).

## Next steps (smart refactor)

1. **Done:** Map deps and locations (this file).
2. **Done:** Extract bootstrap to `js/app-bootstrap.js`. app.js sets `window.__runAppInit = init`; `app-bootstrap.js` (loaded after app.js) runs `__runAppInit()` on DOMContentLoaded or immediately. The "when to run init" logic is no longer at the end of app.js, so a truncated app.js would still leave the bootstrap file intact (though init would be missing until app.js is fixed).
3. **Next:** Small steps: extract one bounded feature at a time, update the dep list and this map, run the app after each step.
