# kushalcodes/konvert-table-to-card architecture

> Architecture diagram of the GitHub repository kushalcodes/konvert-table-to-card, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kushalcodes/konvert-table-to-card
- Repository: https://github.com/kushalcodes/konvert-table-to-card

## Overview

##### Project type and purpose
- This is a small front-end JavaScript library (an open-source tool) whose sole purpose is to convert HTML tables into card layouts on narrow (≤425px) viewports. Users include it via CDN or local script, call `TABLE_KONVERTER.init()`, and pass optional style/type options.

##### File structure
- Top-level files
- index.html – example/demo page that pulls in Bootstrap, the conversion script, and one of the CSS themes
- konvert-table-to-card.js – core JS library implementing the conversion logic
- README.md – usage documentation
- styling/
- simple.css, buddha.css, casual.css – prebuilt theme styles for the generated cards
- type.auto-align.css – CSS rules to auto-align generated cards
- imgs/ – screenshot assets for the README

##### README for architecture cues
- Dependencies: Bootstrap
- Initialization pattern: `TABLE_KONVERTER.init(selector, { style, type, stickyHeader })`
- Runtime behavior: scans the DOM for matching `<table>` elements, generates card markup, injects IDs, applies CSS and sticky headers as configured

##### Main components & relationships
a. Client Browser (User Agent)
- Loads `index.html`
- Fetches Bootstrap CSS, one or more styling/*.css files, and konvert-table-to-card.js
b. TABLE_KONVERTER Module
- Initialization API: `init(selector, options)`
- DOM scanner & converter:
– Locates `<table>` elements by selector
– Reads `<thead>` and `<tbody>` contents
– Generates a `
` structure per row
– Adds generated IDs to cards for future reference
– Attaches sticky header behavior if `options.stickyHeader` provided
- Responsive listener: watches window resize events and re-converts tables/cards when viewport crosses the 425px threshold
c. Styling/CSS Themes
- simple.css, casual.css, buddha.css – theme rules applied to `.card` elements
- type.auto-align.css – additional layout rules for the “autoAlign” type
d. External Dependency
- Bootstrap – provides base layout/grid/utilities used by the generated cards

##### Architectural patterns & principles
- Separation of concerns:
- HTML (index.html) provides static structure
- JS (konvert-table-to-card.js) handles behavior/responsiveness
- CSS (styling/) handles presentation/themes
- Responsive design: single code path adapts output based on viewport width
- Plugin-style initialization: global `TABLE_KONVERTER` object with pluggable options

## Diagram (Mermaid)

```mermaid
graph TB
    Browser["Browser / Client"]
    Index["index.html + HTML tables"]:::html
    Bootstrap["Bootstrap CSS"]:::external
    subgraph "CSS Themes"
        Simple["simple.css"]:::css
        Casual["casual.css"]:::css
        Buddha["buddha.css"]:::css
        AutoAlign["type.auto-align.css"]:::css
    end
    JSModule["konvert-table-to-card.js (TABLE_KONVERTER module)"]:::js
    Docs["README.md (Usage Documentation)"]:::doc
    Screens["imgs/ (Screenshot Assets)"]:::doc

    Browser -->|"fetch index.html"| Index
    Index -->|"loads CSS"| Bootstrap
    Index -->|"loads CSS themes"| Simple
    Simple --> Casual
    Casual --> Buddha
    Buddha --> AutoAlign
    Index -->|"loads JS"| JSModule

    Browser -->|"read docs & view screenshots"| Docs
    Docs -->|"references screenshots"| Screens

    Browser -->|"init() call (selector, options)"| JSModule
    JSModule -->|"scan DOM (tables)"| Index
    JSModule -->|"generate card markup"| Index
    Index -->|"styled by CSS themes & Bootstrap"| Simple
    Browser -->|"window resize event"| JSModule
    JSModule -->|"reflow/convert"| Index

    JSModule -.->|"stickyHeader option"| Index
    JSModule -.->|"autoAlign type option"| AutoAlign

    click Index "https://github.com/kushalcodes/konvert-table-to-card/blob/main/index.html"
    click JSModule "https://github.com/kushalcodes/konvert-table-to-card/blob/main/konvert-table-to-card.js"
    click Simple "https://github.com/kushalcodes/konvert-table-to-card/blob/main/styling/simple.css"
    click Casual "https://github.com/kushalcodes/konvert-table-to-card/blob/main/styling/casual.css"
    click Buddha "https://github.com/kushalcodes/konvert-table-to-card/blob/main/styling/buddha.css"
    click AutoAlign "https://github.com/kushalcodes/konvert-table-to-card/blob/main/styling/type.auto-align.css"
    click Docs "https://github.com/kushalcodes/konvert-table-to-card/blob/main/README.md"
    click Screens "https://github.com/kushalcodes/konvert-table-to-card/tree/main/imgs/"

    classDef html fill:#cce5ff,stroke:#4da6ff,color:#000
    classDef css fill:#cce5ff,stroke:#4da6ff,color:#000
    classDef js fill:#d4edda,stroke:#28a745,color:#000
    classDef external fill:#ffe5b4,stroke:#ffb84d,color:#000
    classDef doc fill:#f0e6ff,stroke:#b380ff,color:#000
```
