# octaviusoo/3.1-home-inspector architecture

> Architecture diagram of the GitHub repository octaviusoo/3.1-home-inspector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/octaviusoo/3.1-home-inspector
- Repository: https://github.com/octaviusoo/3.1-home-inspector

## Overview

1. **Overall shape**
   This is a **Next.js App Router** application built with React and Node.js. The main user flows are centered on creating, editing, viewing, exporting, and syncing structured inspection reports.

2. **Primary route boundaries**
   The app surface is organized around a few key routes:
   - `app/page.jsx` for the main landing/workspace
   - `app/report/[id]/page.jsx` for editing a specific report
   - `app/report/[id]/view/page.jsx` for read-only presentation/viewing
   - `app/error.jsx` and `app/not-found.jsx` for app-level failure states  
   The dynamic `report/[id]` segment is the main domain boundary.

3. **Report editor as the core UI**
   The largest subsystem is the report editor, assembled from many focused React components in `components/`. Sections like **Summary, Scope, Standards, Glossary, Documents, InspectionDetails, Presentation, and AIGuide** imply a modular report structure where each section can be edited independently and reordered/managed through dedicated modals.

4. **Domain model and persistence layer**
   Persistent app state appears to live in **Firebase/Firestore**, with `firebase.ts`, `firestore.rules`, and `lib/db/*` forming the data layer. The `lib/db` modules split responsibilities by concern: reports, media, settings, comments, shortcuts, translations, maintenance, and sync. This suggests the UI talks to an application-specific data access layer rather than directly to Firestore everywhere.

5. **AI assistance and suggestion generation**
   The app integrates **Gemini** through `lib/gemini.js`, with a large catalog of category-specific suggestion modules under `lib/suggestions/` such as roofing, plumbing, electrical, HVAC, foundation, kitchen, bathroom, etc. These likely feed AI-assisted text generation, inspection recommendations, or templated findings inside the report editor.

6. **Media capture and handling**
   The UI includes dedicated tooling for **photos, video, voice, QR, and image editing** (`PhotoEditorModal`, `PhotoViewer`, `VideoCapture`, `VoiceRecorder`, `QRScanner`, `QRGenerator`, `MediaImage`). This points to a workflow where media is captured during inspection, attached to report sections, and then reused in the generated report output.

7. **Export and document generation pipeline**
   Report output is handled by `lib/docx-generator.js` and `lib/export.js`, with many `patch_*.js` scripts indicating a post-processing pipeline for generated documents. The presence of these patch scripts suggests the export path is not trivial: content is assembled, rendered into a document format, and then adjusted for layout, fonts, bookmarks, photos, tables, and viewer compatibility.

8. **Sync, backup, and restore flows**
   `lib/firebaseSync.js`, `lib/sync.js`, `lib/db/sync.js`, and the `FirebaseRestoreModal` indicate support for synchronization and recovery of report data. The architecture likely supports a local editing experience with cloud-backed persistence/restore rather than a purely server-centric workflow.

9. **Platform and offline support**
   `public/sw.js` and `public/manifest.json` indicate PWA-style support, so the app likely includes offline caching or installable web-app behavior. The build artifacts in `.next-dev/` confirm standard Next.js server/client bundling and runtime separation.

10. **Supporting tooling and scripts**
   The repository includes many maintenance scripts (`translate-*.js`, `update_*`, `fix_*`, `parse.js`, `split.js`) plus ESLint and CSS tooling. These are ancillary to runtime but important to the repo’s evolution: they suggest the app’s document/content structure has been repeatedly migrated, translated, and normalized over time.

Main entry points: [`components/ReportEditor.jsx`](https://github.com/octaviusoo/3.1-home-inspector/blob/main/components/ReportEditor.jsx) (Editor), [`lib/db/index.js`](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/db/index.js) (DB API), [`lib/suggestions/index.js`](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/suggestions/index.js) (Suggestions), [`lib/firebaseSync.js`](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/firebaseSync.js) (Sync)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App shell"]
  node_app_page["Home<br/>route<br/>[page.jsx]"]
  node_report_edit["Report edit<br/>route<br/>[page.jsx]"]
  node_report_view["Report view<br/>route<br/>[page.jsx]"]
  node_app_error["Error<br/>route<br/>[error.jsx]"]
  node_app_notfound["Not found<br/>route<br/>[not-found.jsx]"]
end

subgraph group_ui["UI components"]
  node_report_editor["Editor<br/>workspace<br/>[ReportEditor.jsx]"]
  node_section_editor["Section editor<br/>[SectionEditor.jsx]"]
  node_report_sections["Report sections"]
  node_media_tools["Media tools<br/>capture"]
  node_modals["Modals<br/>ui kit"]
end

subgraph group_data["Data layer"]
  node_firebase_core[("Firebase<br/>backend<br/>[firebase.ts]")]
  node_db_api[("DB API<br/>persistence<br/>[index.js]")]
  node_sync_layer["Sync<br/>[firebaseSync.js]"]
end

subgraph group_content["Content engine"]
  node_ai_suggestions["Suggestions<br/>ai content<br/>[index.js]"]
  node_gemini["Gemini<br/>ai client<br/>[gemini.js]"]
  node_export_pipeline["Export<br/>doc pipeline<br/>[export.js]"]
  node_docx_generator["DOCX gen<br/>doc generator<br/>[docx-generator.js]"]
end

subgraph group_tooling["Tooling"]
  node_patch_scripts{{"Patches<br/>post-process"}}
  node_maintenance_scripts{{"Scripts<br/>tooling"}}
end

node_app_page -->|"opens"| node_report_editor
node_report_edit -->|"hosts"| node_report_editor
node_report_view -.->|"reuses data"| node_report_editor
node_report_editor -->|"delegates"| node_section_editor
node_report_editor -->|"organizes"| node_report_sections
node_report_editor -->|"attaches media"| node_media_tools
node_report_editor -->|"uses"| node_modals
node_report_editor -->|"persists"| node_db_api
node_db_api -->|"backed by"| node_firebase_core
node_db_api -->|"coordinates"| node_sync_layer
node_sync_layer -->|"syncs"| node_firebase_core
node_report_editor -->|"suggests"| node_ai_suggestions
node_ai_suggestions -->|"uses"| node_gemini
node_report_editor -->|"exports"| node_export_pipeline
node_export_pipeline -->|"builds"| node_docx_generator
node_docx_generator -.->|"post-processes"| node_patch_scripts
node_maintenance_scripts -.->|"migrates"| node_report_sections
node_maintenance_scripts -.->|"updates"| node_ai_suggestions

click node_app_page "https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/page.jsx"
click node_report_edit "https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/report/[id]/page.jsx"
click node_report_view "https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/report/[id]/view/page.jsx"
click node_app_error "https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/error.jsx"
click node_app_notfound "https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/not-found.jsx"
click node_report_editor "https://github.com/octaviusoo/3.1-home-inspector/blob/main/components/ReportEditor.jsx"
click node_section_editor "https://github.com/octaviusoo/3.1-home-inspector/blob/main/components/SectionEditor.jsx"
click node_firebase_core "https://github.com/octaviusoo/3.1-home-inspector/blob/main/firebase.ts"
click node_db_api "https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/db/index.js"
click node_sync_layer "https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/firebaseSync.js"
click node_ai_suggestions "https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/suggestions/index.js"
click node_gemini "https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/gemini.js"
click node_export_pipeline "https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/export.js"
click node_docx_generator "https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/docx-generator.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_page,node_report_edit,node_report_view,node_app_error,node_app_notfound toneBlue
class node_report_editor,node_section_editor,node_report_sections,node_media_tools,node_modals toneAmber
class node_firebase_core,node_db_api,node_sync_layer toneMint
class node_ai_suggestions,node_gemini,node_export_pipeline,node_docx_generator toneRose
class node_patch_scripts,node_maintenance_scripts toneIndigo
```

## Components

### App shell

Next.js route layer and page-level entry points.

- [Home](https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/page.jsx): route · Main landing and workspace entry. · `app/page.jsx`
- [Report edit](https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/report/[id]/page.jsx): route · Dynamic report editor route for a specific report. · `app/report/[id]/page.jsx`
- [Report view](https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/report/[id]/view/page.jsx): route · Read-only report presentation route. · `app/report/[id]/view/page.jsx`
- [Error](https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/error.jsx): route · App-level error boundary page. · `app/error.jsx`
- [Not found](https://github.com/octaviusoo/3.1-home-inspector/blob/main/app/not-found.jsx): route · App-level 404 page. · `app/not-found.jsx`

### UI components

Core editor, sections, and modal workflows.

- [Editor](https://github.com/octaviusoo/3.1-home-inspector/blob/main/components/ReportEditor.jsx): workspace · Main report editing orchestrator. · `components/ReportEditor.jsx`
- [Section editor](https://github.com/octaviusoo/3.1-home-inspector/blob/main/components/SectionEditor.jsx): editor · Reusable section-level editing UI. · `components/SectionEditor.jsx`
- **Report sections**: sections · Structured report sections such as Summary, Scope, Standards, Glossary, Documents, InspectionDetails, Presentation, and AI guidance.
- **Media tools**: capture · Photo, video, voice, QR, and image workflow components.
- **Modals**: ui kit · Shared dialogs for creation, management, settings, restore, and confirmation flows.

### Data layer

Persistence, sync, and Firebase-backed modules.

- [Firebase](https://github.com/octaviusoo/3.1-home-inspector/blob/main/firebase.ts): backend · Firebase app configuration and Firestore rules. · `firebase.ts`
- [DB API](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/db/index.js): persistence · Application data access layer for reports, media, settings, comments, shortcuts, translations, maintenance, and sync. · `lib/db/index.js`
- [Sync](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/firebaseSync.js): sync · Firebase sync and backup/restore coordination. · `lib/firebaseSync.js`

### Content engine

AI suggestions, export generation, and document assembly.

- [Suggestions](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/suggestions/index.js): ai content · Category-specific inspection suggestion modules used to generate findings and guidance. · `lib/suggestions/index.js`
- [Gemini](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/gemini.js): ai client · Gemini integration for assisted generation. · `lib/gemini.js`
- [Export](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/export.js): doc pipeline · Document generation and export flow for report output. · `lib/export.js`
- [DOCX gen](https://github.com/octaviusoo/3.1-home-inspector/blob/main/lib/docx-generator.js): doc generator · Report-to-Word document assembly and formatting. · `lib/docx-generator.js`

### Tooling

Build, repair, translation, and maintenance scripts.

- **Patches**: post-process · Repair and normalization scripts for generated docs, photos, tables, fonts, bookmarks, and viewer compatibility.
- **Scripts**: tooling · Translation, update, parsing, splitting, and repair scripts used to evolve report content and structure.

## Connections

- Home → Editor: opens · The workspace route mounts the main editor.
- Report edit → Editor: hosts · The dynamic report route renders the editor for one report.
- Report view → Editor: reuses data · Read-only view consumes report content generated by the editing flow.
- Editor → Section editor: delegates · The editor composes section-level editing surfaces.
- Editor → Report sections: organizes · The editor manages the modular report sections.
- Editor → Media tools: attaches media · Media capture and editing are part of report authoring.
- Editor → Modals: uses · The editor relies on shared dialogs for workflow actions.
- Editor → DB API: persists · Report state is stored through the application DB layer.
- DB API → Firebase: backed by · The DB layer is implemented on Firebase/Firestore.
- DB API → Sync: coordinates · Sync-related persistence flows pass through the DB layer.
- Sync → Firebase: syncs · Backup and restore flows synchronize against Firebase.
- Editor → Suggestions: suggests · The editor can inject category-specific guidance and findings.
- Suggestions → Gemini: uses · Suggestion generation is powered by Gemini.
- Editor → Export: exports · Completed reports are sent to the document export pipeline.
- Export → DOCX gen: builds · Export assembles the Word document through the DOCX generator.
- DOCX gen → Patches: post-processes · Generated documents are adjusted by patch scripts for layout and compatibility.
- Scripts → Report sections: migrates · Repository scripts normalize and translate report content structures.
- Scripts → Suggestions: updates · Utility scripts refresh or rewrite suggestion catalogs.
