> For the complete documentation index, see [llms.txt](https://docs.snapfix.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snapfix.com/how-the-apps-work/screens/ai/source-document.md).

# Source document

{% hint style="info" %}
Draft, written by an agent and not yet checked by a person ([how to read these docs](https://docs.snapfix.com/how-to-read.md)). Platforms: web, iOS and Android. [Source on GitHub](https://github.com/snapfix/docs/blob/main/spec/screens/ai/source-document.md).
{% endhint %}

Shows a document that a Snapfix AI answer cites, opened at the cited page when the citation's page is reliable.

![Source document](https://3653879137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsVVGa79QbcEkJ7n8srxe%2Fuploads%2Fgit-blob-c45507e46fbe2e139abb05995a52b8d108d2f8ec%2Fsource-document.png?alt=media)

* **Where:** web `/brand-standards/:documentId`, a full page outside the app shell, with no side menu and no "Snapfix AI" button (web\_app\_v2 @ 0989b8e685, `src/app/app.routes.ts:35-41`, `src/app/app.component.html:4`). It opens in the same tab from "View document" on a document card in an answer (`src/app/pages/simon/simon-document-sources/simon-document-sources.component.html:12-20`). iOS: "View document" on a document card opens the document as a sheet over the Snapfix AI card. Android: "View document" opens the document in its own screen.
* **Who:** web: signed-in users. The route's guard (`authMainGuard`) only checks that sign-in data is stored (`src/app/services/auth/auth-guard/auth-main/auth-main.guard.ts:8-19`). iOS and Android: anyone who can see the answer. No platform checks a role; the server decides which documents a user may read ([Access](#access)).
* **Feature:** [Snapfix AI](https://docs.snapfix.com/product/features/ai/snapfix-ai.md). The chat that cites the document is [Snapfix AI](https://docs.snapfix.com/how-the-apps-work/screens/ai/assistant.md); its document cards are under [Cards in an answer](https://docs.snapfix.com/how-the-apps-work/screens/ai/assistant.md#cards-in-an-answer).

All three apps load the document's record from `GET /brand-standards/documents/{id}` on the Snapfix AI host. Production's agent serves it (snapfix\_ai\_agent @ bcbd010 (refactor/development), `app/modules/brand_standards/router.py:101-118`), and on the live web "View document" on a QA test document opened the PDF with its zoom and page controls ([live notes](https://github.com/snapfix/docs/blob/main/notes/crawl/ai.md)) \[[ASK-13](https://github.com/snapfix/docs/blob/main/ASK.md#ask-13-which-services-and-scheduled-jobs-run-in-production)]. The v2 agent on `main` has no such route, so the page and both apps will fail to open documents once it replaces production ([AI API, Simon versions](https://docs.snapfix.com/engineering-reference/api/ai.md)).

## Layout

### Web

1. **Top bar.** A back button (title "Back"), the file name, cut short when it is long, and the Snapfix logo.
2. **Body.** The PDF's pages, one under another, or the message for the page's state ([States](#states)).
3. **Control bar**, at the bottom: "Zoom out", the zoom percentage and "Zoom in". Once the pages are known, it also has "Previous page", "Page {n} of {m}" and "Next page" (`src/app/pages/document-viewer/document-viewer.component.html:34-72`).

### iOS

A page sheet: a navigation bar with the document name from the answer, or "Document" when there is none, and a close button; then the PDF, scrolling down the pages and scaled to the width (ios @ aa31967ac8, `SnapFix/SimonAI/SimonAIPDFPreviewController.swift:19-34`, `:49-65`).

### Android

A toolbar with a back arrow and the document name from the answer, then the pages in a list, each as wide as the screen less its margins. A progress bar shows until the file has downloaded. There are no zoom or page controls (android @ 86068bfeea, `app/src/main/res/layout/activity_simon_document_viewer.xml:10-30`, `app/src/main/java/gmail/com/snapfixapp/activity/SimonDocumentViewerActivity.kt:50-104`).

## Inputs

| Field                    | Type         | Required | Default | Rules and messages                                                                                                                                                                                                                                                                                                                                                                     |
| ------------------------ | ------------ | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Document ID              | Text         | Yes      | None    | Web: the `:documentId` in the address, sent encoded in the request path. iOS and Android: the cited document's ID. Without one, iOS does nothing and Android opens the link the answer carried (`app/src/main/java/gmail/com/snapfixapp/activity/SimonAiActivity.kt:1244-1249`).                                                                                                       |
| Page                     | Whole number | No       | Page 1  | Web: the `page` query, which the card sets only when the citation's page is reliable ([Platform differences](#platform-differences)); zero, negative and non-numeric values are ignored (`src/app/pages/document-viewer/document-viewer.component.ts:40-46`). iOS: the cited page, when it is 1 or more. Android: the cited page, when it is inside the document, else the first page. |
| `fallback` (web)         | `1`          | No       | None    | `1` drops the page. The web's own links never set it.                                                                                                                                                                                                                                                                                                                                  |
| `chunk`, `section` (web) | Text         | No       | None    | Declared and never used (`document-viewer.component.ts:34-38`). No platform opens a document at a section: a citation opens at its page when the page is reliable, else at the first page.                                                                                                                                                                                             |

## Actions

| Action                                                       | Who                        | What happens                                                                                                                                                                                                                                                                                                      | API                                                                                                                                                                                                                                                                       |
| ------------------------------------------------------------ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Open (web: the page loads; iOS and Android: "View document") | Anyone who sees the answer | Web: asks for the document's record, then shows the PDF at the page. iOS: asks for the record, downloads the file, then opens the sheet at the page. Android: shows "Please wait..." while it asks for a fresh link, uses the link the answer carried when that gives nothing, then opens the viewer at the page. | `GET /brand-standards/documents/{id}` on production's agent ([AI API, Simon versions](https://docs.snapfix.com/engineering-reference/api/ai.md)) \[[ASK-13](https://github.com/snapfix/docs/blob/main/ASK.md#ask-13-which-services-and-scheduled-jobs-run-in-production)] |
| "Zoom in", "Zoom out" (web)                                  | Anyone                     | Changes the scale in steps of 25%, from 50% to 300% (`src/app/components/pdf-viewer/pdf-viewer.component.ts:44-46`).                                                                                                                                                                                              | None                                                                                                                                                                                                                                                                      |
| "Previous page", "Next page" (web)                           | Anyone                     | Moves one page; each is off at the first or last page.                                                                                                                                                                                                                                                            | None                                                                                                                                                                                                                                                                      |
| "Download" (web, a file that is not a PDF)                   | Anyone                     | Opens the record's file link in a new tab.                                                                                                                                                                                                                                                                        | None                                                                                                                                                                                                                                                                      |
| Load again (web, once)                                       | Anyone                     | When the PDF fails to load, for example because its signed link has expired, the page asks for the record once more and loads the file again. A second failure shows the failed state (`document-viewer.component.ts:97-106`).                                                                                    | As "Open"                                                                                                                                                                                                                                                                 |
| "Back" (web)                                                 | Anyone                     | Returns to the page the app recorded before this one; with none, opens `/fix` (`src/app/services/helper/helper.service.ts:338-354`).                                                                                                                                                                              | None                                                                                                                                                                                                                                                                      |
| Close (iOS), back (Android)                                  | Anyone                     | Closes the sheet or the viewer and returns to the answer.                                                                                                                                                                                                                                                         | None                                                                                                                                                                                                                                                                      |
| Open in another app (Android)                                | Anyone                     | When the file cannot be downloaded or drawn, hands its link to another app that opens files, without the page, and closes the viewer. With no such app: "Something went wrong. Please try again." (`SimonDocumentViewerActivity.kt:115-132`).                                                                     | None                                                                                                                                                                                                                                                                      |

### Access

Each platform sends only the selected site with the request, and no platform checks the document's site or group itself:

* **Web:** the `parentUuid` header, and no group, since this page is not a group's page (web\_app\_v2 @ 0989b8e685, `src/app/services/simon/simon-http/simon-http.service.ts:176-184`). The record has `parent_uuid` and `business_uuid` (`src/app/models/simon/simon.model.ro.ts:85-97`), and the page does not compare them with the selected site or group.
* **iOS:** the same header (ios @ aa31967ac8, `SnapFix/SimonAI/SimonAIStreamClient.swift:451-455`); its record model reads neither the site nor the group (`SnapFix/SimonAI/SimonAIModels.swift:486-502`).
* **Android:** the site and its first active building as headers, and no group (android @ 86068bfeea, `app/src/main/java/gmail/com/snapfixapp/repository/SimonRepository.kt:149-155`, `:176-206`); its record model has no site or group (`app/src/main/java/gmail/com/snapfixapp/model/simon/SimonBrandDocument.kt:9-16`).

Production's route takes the site from the `parentUuid` header, or else from the token, and answers 400 without one. It looks the document up by its ID, the token's user and that site; it reads the group header but does not use it (snapfix\_ai\_agent @ bcbd010 (refactor/development), `app/modules/brand_standards/router.py:31-47`, `:101-118`) \[[ASK-13](https://github.com/snapfix/docs/blob/main/ASK.md#ask-13-which-services-and-scheduled-jobs-run-in-production)]. Whether the lookup refuses a document of a site the user cannot use is in the document service, which was not read \[[ASK-180](https://github.com/snapfix/docs/blob/main/ASK.md#ask-180-which-service-indexes-and-serves-the-brand-standards-documents-and-does-it-check-the-callers-site-and-group)].

## States

* **Loading:** web: a spinning ring in the middle of the page until the record arrives. iOS: nothing shows while the file downloads; the sheet appears when it is ready. Android: "Please wait..." while the link is fetched, then the progress bar until the file has downloaded.
* **Ready:** the pages.
* **Empty:** none.
* **Unsupported (web):** "This document type can't be previewed here." and "Download", when the record's content type is not a PDF one or, without a content type, when the file name does not end in "pdf" (`document-viewer.component.ts:131-137`). The page ignores the record's `status`; its code says a citation exists only for a document that is already indexed.
* **Not found (web):** "This document could not be found." when the record answers 404.
* **Failed (web):** "This document couldn't be opened. Please try again." for any other error, for a record without a file link, and for a PDF that fails twice (`document-viewer.component.ts:119-147`).
* **Error (iOS):** a "Something went wrong" toast over the Snapfix AI card when the record or the download fails. A file that is not a PDF, or an error page from the file host, opens as a sheet with the document's name and an empty body, and no message (`SnapFix/SimonAI/SimonAIViewModel.swift:456-488`).
* **Error (Android):** the link goes to another app; without one, or without a link, a toast says "Something went wrong. Please try again.".
* **No permission:** web: "You don't have access to this document." when the record answers 403. iOS and Android show their generic message, as for any other failure.
* **Offline (mobile):** no state of its own. iOS shows the toast. Android hands the link to another app, which needs a connection too, or shows its message.

## Dialogs and sheets

* **iOS:** the document opens as a page sheet with a close button. The Snapfix AI card stays open behind it.
* **Android:** a "Please wait..." dialog while the link is fetched; the viewer itself is a screen of its own.
* **Web:** none; the page replaces the app shell while it is open.

## Platform differences

| Topic                             | Web                                                                                                                                                   | iOS                                                                                                 | Android                                                                                                                                                      |
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Opens as                          | A full page, in the same tab                                                                                                                          | A sheet over the chat                                                                               | A screen of its own                                                                                                                                          |
| Page used                         | When a page is given, `deepLinkAvailable` is on and `positionFallback` is off (`src/app/services/simon/simon-helper/simon-helper.service.ts:323-336`) | Whenever `deepLinkAvailable` is on, even with `positionFallback` (`SimonAIViewModel.swift:456-458`) | When `positionFallback` is off; `deepLinkAvailable` is ignored on purpose (`app/src/main/java/gmail/com/snapfixapp/utils/SimonDocumentCardFactory.kt:30-37`) |
| Title                             | The record's `original_filename`                                                                                                                      | The name from the answer                                                                            | The name from the answer                                                                                                                                     |
| File that is not a PDF            | A message and "Download"                                                                                                                              | An empty sheet                                                                                      | Another app                                                                                                                                                  |
| Expired file link                 | Asks for the record again, once, after a load error                                                                                                   | Asks again, once, after an HTTP 403 (`SimonAIViewModel.swift:476-488`)                              | Asks for a fresh link at every open                                                                                                                          |
| The answer's own link (`viewUrl`) | Never used                                                                                                                                            | Never used                                                                                          | Used when the record gives no link; it points into the web app and needs a sign-in (`SimonAiActivity.kt:1238-1258`)                                          |
| Errors                            | One message per case                                                                                                                                  | One toast for every failure                                                                         | Another app, then one toast                                                                                                                                  |
| Zoom and page controls            | Buttons                                                                                                                                               | None; the page fits the width                                                                       | None                                                                                                                                                         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.snapfix.com/how-the-apps-work/screens/ai/source-document.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
