How andresvillamil/008_localstorage-app_v2 works
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: app.js app.js · ui.js ui.js · books.js books.js · storage.js storage.js
Components 11
Browser runtime
User-facing HTML shell and browser storage boundary.
- User · Interacts with the CRUD interface.
- index.html · HTML page that loads the ES modules and hosts the form, list, and modal.
index.html - localStorage · Browser persistence used for saved books.
- Form · Book entry and edit form in the page.
- Book list · Rendered collection view with edit and delete actions.
- Edit modal · Modal workflow used when editing an existing book.
JavaScript modules
ES module application code under js/.
- app.js · Central orchestration layer for events, modal state, and re-rendering.
js/app.js - books.js · Book record operations: read, add, update, delete.
js/books.js - ui.js · Builds and updates the book list and empty state in the DOM.
js/ui.js - storage.js · Reads and writes the book collection through localStorage.
js/storage.js
App state
Client-side book collection managed by the app.
- Book array · Array of book objects persisted in the browser.
Connections 16
- 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.