# andresvillamil/008_localstorage-app_v2 architecture

> Architecture diagram of the GitHub repository andresvillamil/008_localstorage-app_v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andresvillamil/008_localstorage-app_v2
- Repository: https://github.com/andresvillamil/008_localstorage-app_v2

## Overview

1. **Project type and boundary**
   - This is a **browser-only CRUD app** for managing books.
   - There is **no backend, API, or database**; all persistence happens in the browser via **localStorage**.
   - The runtime boundary is the **HTML page + ES module JavaScript** loaded from `index.html`.

2. **Entry point**
   - `index.html` is the UI shell that loads the JavaScript modules with `type="module"`.
   - The page contains the user-facing surfaces described in the README: **form, table/list, action buttons, and an edit modal**.

3. **Core architectural split**
   - The code is organized into four modules under `js/`, each with a single responsibility:
     - `app.js` → orchestration / event handling
     - `books.js` → book CRUD logic
     - `storage.js` → persistence adapter for localStorage
     - `ui.js` → DOM rendering

4. **Controller/orchestrator: `app.js`**
   - `app.js` is the central coordination layer.
   - It listens for user actions such as **submit, edit click, delete click**, and manages the **edit modal state**.
   - It bridges the UI and business logic, deciding when to call CRUD operations and when to re-render the screen.

5. **Business logic: `books.js`**
   - `books.js` is the application’s **domain layer** for book records.
   - It exposes the CRUD operations described in the README: **read all, add, update, delete**.
   - It likely works with a book array and hides the details of how the data is stored from the UI layer.

6. **Persistence layer: `storage.js`**
   - `storage.js` is the only module that talks directly to **localStorage**.
   - It provides the low-level read/write functions (`getLibros`, `saveLibros`) used by the business logic.
   - This creates a clean boundary: the rest of the app treats data as JavaScript objects/arrays, not storage details.

7. **Presentation layer: `ui.js`**
   - `ui.js` owns all **DOM rendering** responsibilities.
   - It generates the table/list of books and the empty-state message when there is no data.
   - It does not decide business rules; it only reflects the current state supplied by the controller/logic layer.

8. **Primary data flow**
   - User interacts with the form or action buttons in the HTML UI.
   - `app.js` captures the event and delegates to `books.js`.
   - `books.js` updates the book collection and persists it through `storage.js`.
   - `app.js` then triggers `ui.js` to redraw the list with the updated state.

9. **State model**
   - The app’s main state is a **collection of book objects** stored as an array in localStorage.
   - Each record contains fields like **titulo, autor, editorial, anio** as shown in the README.
   - Because the state is client-side only, page reloads preserve data but nothing is shared across devices or users.

10. **Interaction pattern**
   - The list uses **event delegation / centralized event handling** rather than inline handlers, which keeps the view cleaner and improves maintainability.
   - Editing is handled through a **modal workflow**, with `app.js` controlling when the modal opens, receives data, and saves changes.

11. **Dependencies and technology choices**
   - The architecture depends on **vanilla HTML/CSS/JavaScript**, ES6 modules, and the browser’s **localStorage API**.
   - The README notes that it should be run from a **local server** because module loading will not work correctly over `file://`.

12. **What to show in an architecture diagram**
   - The key diagram should show:
     - **User → HTML UI**
     - **HTML UI → app.js**
     - **app.js → books.js**
     - **books.js ↔ storage.js ↔ localStorage**
     - **app.js / books.js → ui.js → HTML UI**
   - The main architectural idea is a **simplified front-end MVC-style split** with clear separation between control, logic, rendering, and persistence.

13. **Non-runtime files**
   - `.vscode` and the `INFO*.md` files are support/documentation artifacts, not part of the runtime architecture.
   - They may help with development context, but they do not affect the execution path of the app.

Main entry points: [`js/app.js`](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/app.js) (app.js), [`js/ui.js`](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/ui.js) (ui.js), [`js/books.js`](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/books.js) (books.js), [`js/storage.js`](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/storage.js) (storage.js)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Browser runtime"]
  node_user(("User<br/>actor"))
  node_index_html["index.html<br/>ui shell<br/>[index.html]"]
  node_local_storage[("localStorage<br/>browser storage")]
  node_form["Form<br/>input surface"]
  node_list["Book list<br/>table view"]
  node_modal["Edit modal<br/>dialog"]
end

subgraph group_modules["JavaScript modules"]
  node_app_js["app.js<br/>controller<br/>[app.js]"]
  node_books_js["books.js<br/>domain CRUD<br/>[books.js]"]
  node_ui_js["ui.js<br/>renderer<br/>[ui.js]"]
  node_storage_js["storage.js<br/>persistence adapter<br/>[storage.js]"]
end

subgraph group_state["App state"]
  node_book_state[("Book array<br/>client state")]
end

node_user -->|"uses"| node_index_html
node_index_html -->|"loads"| node_app_js
node_app_js -->|"handles submit"| node_form
node_app_js -->|"controls"| node_modal
node_app_js -->|"delegates CRUD"| node_books_js
node_books_js -->|"reads/writes"| node_book_state
node_books_js -->|"persists via"| node_storage_js
node_storage_js -->|"uses"| node_local_storage
node_storage_js -->|"loads/saves"| node_book_state
node_app_js -->|"requests render"| node_ui_js
node_ui_js -->|"renders"| node_list
node_ui_js -->|"updates"| node_form
node_ui_js -->|"updates"| node_modal
node_list -->|"events to controller"| node_app_js
node_form -->|"submit events"| node_app_js
node_modal -->|"save/cancel events"| node_app_js

click node_index_html "https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/index.html"
click node_app_js "https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/app.js"
click node_books_js "https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/books.js"
click node_ui_js "https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/ui.js"
click node_storage_js "https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/storage.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_user,node_index_html,node_local_storage,node_form,node_list,node_modal toneBlue
class node_app_js,node_books_js,node_ui_js,node_storage_js toneAmber
class node_book_state toneMint
```

## Components

### Browser runtime

User-facing HTML shell and browser storage boundary.

- **User**: actor · Interacts with the CRUD interface.
- [index.html](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/index.html): ui shell · HTML page that loads the ES modules and hosts the form, list, and modal. · `index.html`
- **localStorage**: browser storage · Browser persistence used for saved books.
- **Form**: input surface · Book entry and edit form in the page.
- **Book list**: table view · Rendered collection view with edit and delete actions.
- **Edit modal**: dialog · Modal workflow used when editing an existing book.

### JavaScript modules

ES module application code under js/.

- [app.js](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/app.js): controller · Central orchestration layer for events, modal state, and re-rendering. · `js/app.js`
- [books.js](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/books.js): domain CRUD · Book record operations: read, add, update, delete. · `js/books.js`
- [ui.js](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/ui.js): renderer · Builds and updates the book list and empty state in the DOM. · `js/ui.js`
- [storage.js](https://github.com/andresvillamil/008_localstorage-app_v2/blob/master/js/storage.js): persistence adapter · Reads and writes the book collection through localStorage. · `js/storage.js`

### App state

Client-side book collection managed by the app.

- **Book array**: client state · Array of book objects persisted in the browser.

## Connections

- User → index.html: uses · User interacts with the page.
- index.html → app.js: loads · The HTML shell loads the application modules.
- app.js → Form: handles submit · Controller captures form submissions and edit actions.
- app.js → Edit modal: controls · Opens, populates, and closes the edit modal.
- app.js → books.js: delegates CRUD · Routes user actions to domain operations.
- books.js → Book array: reads/writes · Domain logic works over the book collection.
- books.js → storage.js: persists via · Book operations are saved through the storage adapter.
- storage.js → localStorage: uses · Direct browser persistence boundary.
- storage.js → Book array: loads/saves · Serializes and hydrates the collection.
- app.js → ui.js: requests render · Controller triggers UI refresh after state changes.
- ui.js → Book list: renders · Produces the book list and empty-state view.
- ui.js → Form: updates · Keeps visible form state in sync with app state.
- ui.js → Edit modal: updates · Reflects the current edit state in the modal.
- Book list → app.js: events to controller · Edit and delete actions flow back through centralized handling.
- Form → app.js: submit events · Form submissions are handled by the controller.
- Edit modal → app.js: save/cancel events · Modal actions are handled centrally.
