Skip to content

Add UI architecture documentation of android and detail of the FrontendScreen#2965

Draft
TimoPtr wants to merge 3 commits into
masterfrom
android/webview_architecture
Draft

Add UI architecture documentation of android and detail of the FrontendScreen#2965
TimoPtr wants to merge 3 commits into
masterfrom
android/webview_architecture

Conversation

@TimoPtr

@TimoPtr TimoPtr commented Feb 17, 2026

Copy link
Copy Markdown
Member

Proposed change

WIP

Type of change

  • Document existing features within Home Assistant
  • Document new or changing features for which there is an existing pull request elsewhere
  • Spelling or grammatical corrections, or rewording for improved clarity
  • Changes to the backend of this documentation
  • Remove stale or deprecated documentation

Checklist

  • I have read and followed the documentation guidelines.
  • I have verified that my changes render correctly in the documentation.

Additional information

Summary by CodeRabbit

  • Documentation
    • Added a WebView communication architecture section to Android docs, including an architecture overview, an interaction diagram illustrating message flow, and a "Component responsibilities" subsection detailing the public-facing components and their roles.

@TimoPtr TimoPtr requested a review from a team as a code owner February 17, 2026 09:15
@coderabbitai

coderabbitai Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new documentation section titled "WebView communication architecture" is added to the Android architecture guide, detailing the communication flow between Home Assistant Frontend JS and internal Android components, including architecture overview and component responsibilities. This is a documentation-only addition with no code or behavior changes.

Changes

Cohort / File(s) Summary
Android architecture documentation
docs/android/architecture.md
Added new "WebView communication architecture" section with component interaction overview, Mermaid diagram describing data flow between FrontendJsBridge, FrontendMessageHandler, FrontendExternalBusRepository, and ServerSessionManager, and detailed component responsibilities subsection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'UI architecture documentation of android' and 'FrontendScreen', but the actual changes add WebView communication architecture documentation focused on component responsibilities and message flow, not UI architecture or FrontendScreen details. Update the title to accurately reflect the change, such as 'Add WebView communication architecture documentation for Android' to match the actual documentation content.
Description check ⚠️ Warning The PR description is incomplete. The 'Proposed change' section contains only 'WIP' placeholder text rather than describing the actual changes being made. Replace 'WIP' in the 'Proposed change' section with a clear description of why this documentation update is needed and what architectural concepts it explains.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch android/webview_architecture

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/android/architecture.md (1)

119-119: Consider clarifying the arrow label for consistency.

The label "FrontendJsHandler" appears to reference an interface or type, while other labels in the diagram use method names or actions (e.g., "getExternalAuth()", "onMessageReceived()"). Consider making this label more descriptive to match the pattern, such as "implements FrontendJsHandler" or "via FrontendJsHandler".

📝 Suggested clarification
-    JsBridge -->|"FrontendJsHandler"| MsgHandler
+    JsBridge -->|"via FrontendJsHandler"| MsgHandler

or

-    JsBridge -->|"FrontendJsHandler"| MsgHandler
+    JsBridge -->|"implements FrontendJsHandler"| MsgHandler
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/android/architecture.md` at line 119, The diagram arrow label
"FrontendJsHandler" is ambiguous compared to other action/method labels; update
the label between JsBridge and MsgHandler to a descriptive phrase like
"implements FrontendJsHandler" or "via FrontendJsHandler" so it matches the
pattern of method/action labels (reference: JsBridge, FrontendJsHandler,
MsgHandler).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/android/architecture.md`:
- Line 92: The two broken links in the sentence referencing external
authentication and external bus need updating: replace the paths
`/docs/api/native-app-integration/frontend/external-authentication` and
`/docs/api/native-app-integration/frontend/external-bus` with the correct
`/docs/frontend/external-authentication` and `/docs/frontend/external-bus`
respectively so the WebView paragraph links point to the actual documentation
pages.

---

Nitpick comments:
In `@docs/android/architecture.md`:
- Line 119: The diagram arrow label "FrontendJsHandler" is ambiguous compared to
other action/method labels; update the label between JsBridge and MsgHandler to
a descriptive phrase like "implements FrontendJsHandler" or "via
FrontendJsHandler" so it matches the pattern of method/action labels (reference:
JsBridge, FrontendJsHandler, MsgHandler).

Comment thread docs/android/architecture.md Outdated
@TimoPtr

TimoPtr commented Feb 17, 2026

Copy link
Copy Markdown
Member Author

@jpelgrom do we wait for it to be use before merging this?

@jpelgrom

Copy link
Copy Markdown
Member

Mermaid styling seems to need some tweaks for dark mode...

do we wait for it to be use before merging this?

Yes I'd wait until this is actually how the main WebView works, we might tweak it while developing.

@silamon silamon marked this pull request as draft March 2, 2026 17:46
@silamon

silamon commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

From what I understand, this isn't ready for merge yet, hence setting as draft.

@TimoPtr

TimoPtr commented Mar 3, 2026

Copy link
Copy Markdown
Member Author

From what I understand, this isn't ready for merge yet, hence setting as draft.

Exactly. I'll handle the merge, once the migration is going to be over. We are merging small bits at the time in debug only in the app. I'm going to probably keep this PR for a while and might update it along the way. The progress can be tracked in home-assistant/android#6424

@TimoPtr TimoPtr force-pushed the android/webview_architecture branch from 47b9b01 to 32c179b Compare June 3, 2026 10:17
@TimoPtr TimoPtr changed the title Add webview communication with the frontend Add UI architecture documentation of android and detail of the FrontendScreen Jun 3, 2026

@jpelgrom jpelgrom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated doc helps a lot in making it clear what you want to achieve 👍

What I'm missing is:

  • The introduction of UseCase

Comparing this to something like https://developer.android.com/topic/architecture or https://github.com/android/nowinandroid/blob/main/docs/ArchitectureLearningJourney.md, the language feels very theoretical and not practical, while this should be a practical document.

Comment thread docusaurus.config.js
image: "img/default-social.png",
mermaid: {
theme: { light: "neutral", dark: "forest" },
theme: { light: "neutral", dark: "dark" },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change along with the other dependency changes should be submitted separately so others who do more work with Docusaurus will also notice it

@@ -0,0 +1,446 @@
---
title: "UI architecture (MVI‑like)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: "UI architecture (MVI‑like)"
title: "UI architecture"

sidebar_label: "UI architecture"
---

This page describes the **MVI‑like** pattern we use for screens, and then shows how the dashboard (the frontend screen) applies it. New UI should follow the same pattern.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggests a generic architecture for any screen, not just frontend. If that is intended I think it should be referenced near the top of the architecture page (## Application architecture) to avoid readers thinking we follow 100% what Google suggests.


## The pattern

A screen often has many concurrent input sources — the user, system callbacks (permissions, file chooser), timers, and external channels — that all have to be reduced into **one** coherent UI. The pattern keeps that predictable and testable: all inputs flow _in_ as intents, and are turned into a few well‑defined outputs — durable **state**, one‑shot **events**, and imperative **actions**.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting note for here and many paragraphs following: the style (guide) used uses bold for UI strings or sometimes at the start of a sentence or by exception. Emphases can be added using italicized text but sparingly. This page is full of bold and italicized text and reads like LLM output.


---

## The frontend screen

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the size of the page, and the intention to have the text above be more generic, I'd suggest splitting this into another (sub)page


VM -->|"delegates"| Handlers
VM -->|"delegates"| Managers
VM -->|"delegates"| Repos

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows as the top item of the section now, it should be the other way around with repositories at the bottom to match the previous graphs!


### At a glance

| Pattern role | Frontend implementation | File(s) |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For file(s), please provide links

| State | `FrontendViewState` (`LoadServer`, `Loading`, `Content`, `Error`, `Insecure`, `SecurityLevelRequired`) | `frontend/FrontendViewState.kt` |
| Events | `FrontendEvent` | `frontend/navigation/FrontendEvent.kt` |
| Actions | `WebViewAction` | `frontend/WebViewAction.kt` |
| Request/response prompts | `SingleSlotQueue` | `common/util/SingleSlotQueue.kt` |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the common util pattern, shouldn't I expect to see the type used with the prompt here?

Comment on lines +333 to +338
- creates the platform `WebView` in an `AndroidView` and applies a baseline **`defaultSettings()`** — JavaScript and DOM storage on, zoom controls off, a minimum font size, the Home Assistant user‑agent appended, and a **transparent background** (so the launch screen/theme shows through until the frontend paints);
- applies the **night‑mode** preference via `WebSettingsCompat.setForceDark` — a fallback for forked or older system WebViews that don't follow the app theme on their own;
- shows a **placeholder** instead of a real WebView under Compose previews / screenshot tests, and reports `onWebViewCreationFailed` when the system WebView provider can't be instantiated (which the ViewModel turns into an unrecoverable `Error` state);
- routes the **back button** to `WebView.goBack()`, falling back to the nav host once the WebView's history is empty.

On top of that baseline, `FrontendScreen.configureForFrontend(...)` layers the **frontend‑specific** setup: it attaches the two clients, enables first‑ and third‑party **cookies** (`CookieManager`), toggles `mediaPlaybackRequiresUserGesture` from the "autoplay video" preference, registers a **download listener**, and installs a multi‑pointer **swipe listener** feeding `onGesture`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this detail level really relevant when describing the architecture of the webview setup and how it maps onto the general architecture?

| `FrontendEventHandler` | Compose UI | Emitting each `FrontendEvent` invokes the right host callback (navigate, snackbar, …). |
| `FrontendScreen` | Screenshot | Visual regression only (no logic). |

## What to fix in the code to match this doc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is for an issue, not documentation. The documentation could have a basic note that not all screens match the architecture and to link to one or more issues, and welcome contributions after discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants