# jabesinhoo/pdf-catalogo architecture

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

- Interactive diagram: https://gitdiagram.com/jabesinhoo/pdf-catalogo
- Repository: https://github.com/jabesinhoo/pdf-catalogo

## Overview

1. This repo is a two-tier application: a React/Vite frontend and a Node.js backend. The product is a “catalog PDF” tool that ingests products from Tecnonacho URLs, lets the user edit/organize them, and generates downloadable documents.

2. The frontend is the interactive workspace. Its main screen is composed from `MainLayout`, a top bar, sidebar navigation, search/history panels, product cards, quote editors, and admin screens. It also includes login/session UI, saved documents/quotes panels, and modal-based editing flows for product and quote adjustments.

3. Frontend state is split between server-backed data and browser persistence. Utilities like `documentStorage`, `quoteStorage`, and `savedQuotes` indicate local caching of user work, while `useSessionKeepAlive` suggests the browser keeps the authenticated session alive with periodic backend calls.

4. The backend is organized as a classic API layer with controllers and routes. Separate route groups exist for auth, admin, documents, PDFs, products, stats, and cache, with controllers handling the request/response boundary and services holding the domain logic.

5. Product ingestion is a distinct subsystem. `tecnonachoScraper` pulls data from external Tecnonacho pages, `productService` and `realPriceService` normalize or enrich that data, and `productCacheService` keeps a server-side cache so repeated lookups are cheaper and more consistent.

6. Document generation is another major pipeline. `pdfService` and the `catalogTemplate` / `quoteTemplate` modules build the output artifacts, while the `public/flipbooks` directories show that generated HTML “flipbook” outputs are written to disk and then served statically by the backend.

7. Persistence is handled through a SQL database with migration scripts. The migrations create and evolve at least three core tables: documents, users, and product cache. A `databaseService` abstraction sits between the app and the database, so the rest of the backend likely does not talk to SQL directly.

8. Authentication and administration are first-class concerns. There are dedicated auth and admin controllers/routes, a session config module, a user service, and scripts for creating an admin account and generating password hashes. This points to server-managed login sessions rather than purely token-based auth.

9. Operational safeguards are built into the backend. `rateLimiter` and `validators` sit in middleware, which means request throttling and input validation are enforced before controllers run. `loggerService` and `statsService` suggest the system also records activity and exposes usage metrics.

10. The backend also exposes a product cache/admin statistics surface. Separate cache and stats routes imply that cache maintenance and reporting are explicitly available as API concerns, likely for internal/admin use rather than normal end-user workflows.

11. The main data flow is: user inputs a Tecnonacho URL in the frontend → backend scrapes and normalizes product data → products are edited/organized in the UI → backend generates catalog/quote artifacts → generated files are stored under public assets and returned to the user. Saved work can be revisited via document and quote history.

12. Deployment is automated with GitHub Actions, and the backend includes migration/run scripts for environment setup. That suggests the repo expects repeatable database migrations and server deployment as part of its release process.

Main entry points: [`backend/src/routes`](https://github.com/jabesinhoo/pdf-catalogo/tree/main/backend/src/routes) (API routes), [`frontend/src/layouts/MainLayout.jsx`](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/layouts/MainLayout.jsx) (Main layout), [`backend/src/services`](https://github.com/jabesinhoo/pdf-catalogo/tree/main/backend/src/services) (Core services), [`backend/src/services/databaseService.js`](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/services/databaseService.js) (Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_main_layout["Main layout<br/>shell/layout<br/>[MainLayout.jsx]"]
  node_frontend_topbar["Top bar<br/>ui/chrome<br/>[TopBar.jsx]"]
  node_frontend_sidebar["Sidebar nav<br/>ui/navigation"]
  node_frontend_search["Search panel<br/>ui/search<br/>[SearchPanel.jsx]"]
  node_frontend_cards["Product cards<br/>ui/product list"]
  node_frontend_quote_editor["Quote editor<br/>ui/editing"]
  node_frontend_saved_work["Saved work<br/>ui/persistence<br/>[SavedDocuments.jsx]"]
  node_frontend_auth["Auth UI<br/>ui/session<br/>[Login.jsx]"]
  node_frontend_modals["Edit modals<br/>ui/modals"]
  node_frontend_state["Local state<br/>browser cache<br/>[documentStorage.js]"]
  node_frontend_keepalive(("Keepalive<br/>session hook"))
end

subgraph group_backend["Backend"]
  node_backend_api["API app<br/>express app<br/>[app.js]"]
  node_backend_routes["API routes<br/>routing"]
  node_backend_services["Core services<br/>domain services"]
  node_backend_ingest["Tecnonacho ingest<br/>scraper/normalizer"]
  node_backend_pdf["PDF pipeline<br/>document generation<br/>[pdfService.js]"]
  node_backend_templates["Templates<br/>[catalogTemplate.js]"]
  node_backend_persistence[("Database<br/>sql persistence<br/>[databaseService.js]")]
  node_backend_security["Security<br/>middleware<br/>[validators.js]"]
  node_backend_ops["Ops tools<br/>scripts/deploy<br/>[run-migrations.js]"]
end

node_frontend_main_layout -->|"composes"| node_frontend_topbar
node_frontend_main_layout -->|"composes"| node_frontend_sidebar
node_frontend_main_layout -->|"hosts"| node_frontend_search
node_frontend_main_layout -->|"hosts"| node_frontend_cards
node_frontend_main_layout -->|"hosts"| node_frontend_quote_editor
node_frontend_main_layout -->|"hosts"| node_frontend_saved_work
node_frontend_auth -->|"extends session"| node_frontend_keepalive
node_frontend_state -->|"backs"| node_frontend_saved_work
node_frontend_search -->|"queries"| node_backend_routes
node_frontend_quote_editor -->|"saves"| node_backend_routes
node_frontend_auth -->|"authenticates"| node_backend_routes
node_backend_api -->|"mounts"| node_backend_routes
node_backend_routes -->|"guards"| node_backend_security
node_backend_routes -->|"delegates"| node_backend_services
node_backend_services -->|"ingests"| node_backend_ingest
node_backend_services -->|"renders"| node_backend_pdf
node_backend_pdf -->|"uses"| node_backend_templates
node_backend_services -->|"stores"| node_backend_persistence
node_backend_ingest -->|"caches"| node_backend_persistence
node_backend_ops -->|"migrates"| node_backend_persistence
node_backend_ops -->|"deploys"| node_backend_api
node_backend_services -.->|"serves"| node_backend_routes

click node_frontend_main_layout "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/layouts/MainLayout.jsx"
click node_frontend_topbar "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/TopBar.jsx"
click node_frontend_sidebar "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/SidebarDocumentNav.jsx"
click node_frontend_search "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/SearchPanel.jsx"
click node_frontend_cards "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/DraggableProductCard.jsx"
click node_frontend_quote_editor "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/QuoteEditorTable.jsx"
click node_frontend_saved_work "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/SavedDocuments.jsx"
click node_frontend_auth "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/Login.jsx"
click node_frontend_modals "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/EditProductModal.jsx"
click node_frontend_state "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/utils/documentStorage.js"
click node_frontend_keepalive "https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/hooks/useSessionKeepAlive.js"
click node_backend_api "https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/app.js"
click node_backend_routes "https://github.com/jabesinhoo/pdf-catalogo/tree/main/backend/src/routes"
click node_backend_services "https://github.com/jabesinhoo/pdf-catalogo/tree/main/backend/src/services"
click node_backend_ingest "https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/scrapers/tecnonachoScraper.js"
click node_backend_pdf "https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/services/pdfService.js"
click node_backend_templates "https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/templates/catalogTemplate.js"
click node_backend_persistence "https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/services/databaseService.js"
click node_backend_security "https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/middleware/validators.js"
click node_backend_ops "https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/scripts/run-migrations.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_frontend_main_layout,node_frontend_topbar,node_frontend_sidebar,node_frontend_search,node_frontend_cards,node_frontend_quote_editor,node_frontend_saved_work,node_frontend_auth,node_frontend_modals,node_frontend_state,node_frontend_keepalive toneBlue
class node_backend_api,node_backend_routes,node_backend_services,node_backend_ingest,node_backend_pdf,node_backend_templates,node_backend_persistence,node_backend_security,node_backend_ops toneAmber
```

## Components

### Frontend

React/Vite workspace for searching, editing, and organizing catalog content.

- [Main layout](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/layouts/MainLayout.jsx): shell/layout · Primary workspace composition for the app shell and core panels. · `frontend/src/layouts/MainLayout.jsx`
- [Top bar](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/TopBar.jsx): ui/chrome · Header actions, navigation, and session-related controls. · `frontend/src/components/TopBar.jsx`
- [Sidebar nav](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/SidebarDocumentNav.jsx): ui/navigation · Document and workspace navigation panel. · `frontend/src/components/SidebarDocumentNav.jsx`
- [Search panel](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/SearchPanel.jsx): ui/search · Product search and browsing entry point. · `frontend/src/components/SearchPanel.jsx`
- [Product cards](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/DraggableProductCard.jsx): ui/product list · Draggable product presentation and organization surface. · `frontend/src/components/DraggableProductCard.jsx`
- [Quote editor](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/QuoteEditorTable.jsx): ui/editing · Table and form tools for quote editing and recalculation. · `frontend/src/components/QuoteEditorTable.jsx`
- [Saved work](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/SavedDocuments.jsx): ui/persistence · Panels for saved documents, quotes, and action history. · `frontend/src/components/SavedDocuments.jsx`
- [Auth UI](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/Login.jsx): ui/session · Login and user/session status controls. · `frontend/src/components/Login.jsx`
- [Edit modals](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/components/EditProductModal.jsx): ui/modals · Modal flows for product, price, and confirmation edits. · `frontend/src/components/EditProductModal.jsx`
- [Local state](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/utils/documentStorage.js): browser cache · Browser-side persistence for documents, quotes, and saved items. · `frontend/src/utils/documentStorage.js`
- [Keepalive](https://github.com/jabesinhoo/pdf-catalogo/blob/main/frontend/src/hooks/useSessionKeepAlive.js): session hook · Periodic session refresh to keep authentication active. · `frontend/src/hooks/useSessionKeepAlive.js`

### Backend

Node.js API, ingestion, persistence, and document generation services.

- [API app](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/app.js): express app · Backend application entry and server wiring. · `backend/src/app.js`
- [API routes](https://github.com/jabesinhoo/pdf-catalogo/tree/main/backend/src/routes): routing · Route boundaries for auth, admin, documents, PDFs, products, cache, and stats. · `backend/src/routes`
- [Core services](https://github.com/jabesinhoo/pdf-catalogo/tree/main/backend/src/services): domain services · Business logic for products, documents, users, stats, logging, and storage. · `backend/src/services`
- [Tecnonacho ingest](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/scrapers/tecnonachoScraper.js): scraper/normalizer · External product scraping and normalization pipeline. · `backend/src/scrapers/tecnonachoScraper.js`
- [PDF pipeline](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/services/pdfService.js): document generation · Catalog and quote template rendering plus PDF/export handling. · `backend/src/services/pdfService.js`
- [Templates](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/templates/catalogTemplate.js): render templates · Catalog and quote document layouts used by generation services. · `backend/src/templates/catalogTemplate.js`
- [Database](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/services/databaseService.js): sql persistence · Database config, migrations, and persistence abstraction for users, documents, and cache. · `backend/src/services/databaseService.js`
- [Security](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/src/middleware/validators.js): middleware · Session, validation, and rate limiting controls around API access. · `backend/src/middleware/validators.js`
- [Ops tools](https://github.com/jabesinhoo/pdf-catalogo/blob/main/backend/scripts/run-migrations.js): scripts/deploy · Migration, admin creation, and deployment scripts. · `backend/scripts/run-migrations.js`

## Connections

- Main layout → Top bar: composes · The app shell includes top-level chrome.
- Main layout → Sidebar nav: composes · Workspace navigation is part of the main layout.
- Main layout → Search panel: hosts · Search and browsing are central workspace panels.
- Main layout → Product cards: hosts · Product organization happens inside the main workspace.
- Main layout → Quote editor: hosts · Quote editing is embedded in the workspace.
- Main layout → Saved work: hosts · Saved items and history panels are reachable from the main layout.
- Auth UI → Keepalive: extends session · Authentication state is maintained in the browser.
- Local state → Saved work: backs · Local persistence feeds the saved documents/quotes UI.
- Search panel → API routes: queries · Search and product ingestion actions call backend APIs.
- Quote editor → API routes: saves · Quote edits and document actions are persisted server-side.
- Auth UI → API routes: authenticates · Login/session flows depend on backend auth endpoints.
- API app → API routes: mounts · The server exposes grouped HTTP routes.
- API routes → Security: guards · Middleware enforces validation and throttling before handlers.
- API routes → Core services: delegates · Controllers and routes hand off to domain services.
- Core services → Tecnonacho ingest: ingests · Product services rely on Tecnonacho scraping and normalization.
- Core services → PDF pipeline: renders · Document services generate catalog and quote artifacts.
- PDF pipeline → Templates: uses · Templates define the output document structure.
- Core services → Database: stores · Domain services read and write through the database abstraction.
- Tecnonacho ingest → Database: caches · Scraped product data is normalized and cached server-side.
- Ops tools → Database: migrates · Scripts manage schema creation and updates.
- Ops tools → API app: deploys · Operational scripts support server startup and release workflows.
- Core services → API routes: serves · Service outputs are exposed through controllers and routes.
