# irunga1/flexjs architecture

> Architecture diagram of the GitHub repository irunga1/flexjs, 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/irunga1/flexjs
- Repository: https://github.com/irunga1/flexjs

## Overview

1. **What this repo is**
   LiteFlex is a browser-side, JavaScript-module microframework centered on one idea: a `main*.js` entrypoint wires together a data model, a view, optional hooks, and a stylesheet, and the core coordinates the lifecycle.

2. **Top-level architecture**
   The repository is organized into clear layers:
   - `core/` for orchestration
   - `models/` for data access and normalization
   - `views/` for DOM rendering
   - `helper/` for pre/post render hooks
   - `css/` for page-specific styling
   - `main*.js` for demo-specific composition
   - `index*.html` / `movies.html` for minimal browser shells

3. **Core runtime boundary**
   `core/Flex.js` is the main runtime controller. It waits for `DOMContentLoaded`, can inject a stylesheet, optionally shows a temporary blackout/loading overlay, instantiates the chosen model, and then invokes the view after data is ready. `Flex2.js` and `Flex3.js` appear to be alternative/experimental core variants.

4. **Data layer boundary**
   `models/ApiModule.js` is the common base for fetching and response normalization. It fetches data, then normalizes API shapes by moving a configured `dataKey` into `results`. Specific data adapters like `TMDB`, `RickAndMorty`, `FakeStore`, and `News` sit on top of that pattern and encapsulate source-specific URL and response logic.

5. **Data sources and external dependencies**
   The demos connect to multiple sources with different structures:
   - TMDB for movie/streaming-style UIs
   - Rick and Morty API
   - Fake Store API
   - local/news data via `data/news.js`
   
   This makes the model layer the main integration boundary with external services.

6. **Render layer boundary**
   `views/` contains reusable rendering functions such as `movieCard`, `productCard`, `newsCard`, `playerView`, and card-list helpers. These views are responsible for producing the DOM content, typically by writing markup into a container rather than maintaining their own state.

7. **Hook/extensibility layer**
   `helper/` contains pre-render and post-render hooks such as `preRenderFn.js` and `postRenderFn*.js`. The lifecycle is intentionally extensible: the core can run code before rendering to prepare the UI, and after rendering to apply behavior or enhancements.

8. **Composition happens in entrypoints**
   The `main*.js` files are the application assembly points. Each one selects:
   - the API URL or data source
   - the model class
   - the view function
   - the CSS file
   - the optional pre/post hooks
   
   This is where the framework is “configured” per demo.

9. **UI shells and page variants**
   The HTML files are minimal shells that host the app: `index.html`, `movies.html`, `indexnews.html`, `indexplayer.html`, and `index---.html`. They mostly provide the mounting container and let the JS pipeline build the interface dynamically.

10. **Styling strategy**
   Styles are separated by demo or domain in `css/` (`netflix.css`, `news.css`, `player.css`, `page.css`, `local.css`). The core can inject a stylesheet dynamically, so presentation is part of the framework flow rather than static page setup.

11. **Observed end-to-end flow**
   The typical data/render path is:
   `main*.js` → `Flex` core → model fetch/normalize → pre-render hook → view render into container → post-render hook → optional loading overlay teardown.
   That is the central architecture diagram to capture.

12. **Repository character**
   This is not a generic app repo; it is a framework-like codebase with multiple demos proving the same pipeline across domains. The important architectural boundary is between orchestration (`core`), data access (`models`), and presentation (`views`), with `main*.js` acting as the composition root.

Main entry points: [`core/Flex.js`](https://github.com/irunga1/flexjs/blob/main/core/Flex.js) (Flex.js), [`models/ApiModule.js`](https://github.com/irunga1/flexjs/blob/main/models/ApiModule.js) (ApiModule.js), [`main.js`](https://github.com/irunga1/flexjs/blob/main/main.js) (main.js), [`main2.js`](https://github.com/irunga1/flexjs/blob/main/main2.js) (main2.js)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_composition["Composition"]
  node_main["main.js<br/>entrypoint<br/>[main.js]"]
  node_main2["main2.js<br/>entrypoint<br/>[main2.js]"]
  node_main3["main3.js<br/>entrypoint<br/>[main3.js]"]
  node_main4["main4.js<br/>entrypoint<br/>[main4.js]"]
  node_main5["main5.js<br/>entrypoint<br/>[main5.js]"]
  node_main7["main7.js<br/>entrypoint<br/>[main7.js]"]
  node_indexhtml["index.html<br/>shell<br/>[index.html]"]
  node_moviehtml["movies.html<br/>shell<br/>[movies.html]"]
  node_newshtml["indexnews.html<br/>shell<br/>[indexnews.html]"]
  node_playerhtml["indexplayer.html<br/>shell<br/>[indexplayer.html]"]
end

subgraph group_runtime["Runtime"]
  node_coreflex["Flex.js<br/>runtime<br/>[Flex.js]"]
  node_coreflex2["Flex2.js<br/>runtime<br/>[Flex2.js]"]
  node_coreflex3["Flex3.js<br/>runtime<br/>[Flex3.js]"]
end

subgraph group_data["Data"]
  node_apimodule["ApiModule.js<br/>data base<br/>[ApiModule.js]"]
  node_tmdb["TMDB<br/>data adapter<br/>[TMDB.js]"]
  node_rickmorty["RickMorty<br/>data adapter<br/>[RickAndMorty.js]"]
  node_fakestore["FakeStore<br/>data adapter<br/>[FakeStore.js]"]
  node_newsmodel["News<br/>data adapter<br/>[News.js]"]
  node_newsdata["news.js<br/>local data<br/>[news.js]"]
end

subgraph group_presentation["Presentation"]
  node_moviecard["movieCard<br/>view<br/>[movieCard.js]"]
  node_productcard["productCard<br/>view<br/>[productCard.js]"]
  node_newscard["newsCard<br/>view<br/>[newsCard.js]"]
  node_playerview["playerView<br/>[playerView.js]"]
  node_cardlist["viewCardList<br/>list view<br/>[viewCardList.js]"]
  node_cardlistalt["viewCardListAlt<br/>list view<br/>[viewCardListAlt.js]"]
  node_prerender["preRenderFn<br/>hook<br/>[preRenderFn.js]"]
  node_prerender5["preRenderFn5<br/>hook<br/>[preRenderFn5.js]"]
  node_postrender["postRenderFn<br/>hook<br/>[postRenderFn.js]"]
  node_postrender2["postRenderFn2<br/>hook<br/>[postRenderFn2.js]"]
  node_postrender3["postRenderFn3<br/>hook<br/>[postRenderFn3.js]"]
  node_postrender5["postRenderFn5<br/>hook<br/>[postRenderFn5.js]"]
  node_netflixcss["netflix.css<br/>style<br/>[netflix.css]"]
  node_newscss["news.css<br/>style<br/>[news.css]"]
  node_playercss["player.css<br/>style<br/>[player.css]"]
end

node_main -->|"uses"| node_coreflex
node_main2 -->|"uses"| node_coreflex
node_main3 -->|"uses"| node_coreflex
node_main4 -->|"uses"| node_coreflex
node_main5 -->|"uses"| node_coreflex
node_main7 -->|"uses"| node_coreflex
node_main -->|"configures"| node_tmdb
node_main2 -->|"configures"| node_rickmorty
node_main3 -->|"configures"| node_fakestore
node_main4 -->|"configures"| node_newsmodel
node_main5 -->|"configures"| node_newsdata
node_main -->|"configures"| node_moviecard
node_main2 -->|"configures"| node_cardlist
node_main3 -->|"configures"| node_productcard
node_main4 -->|"configures"| node_newscard
node_main5 -->|"configures"| node_playerview
node_coreflex -->|"instantiates"| node_apimodule
node_apimodule -->|"base for"| node_tmdb
node_apimodule -->|"base for"| node_rickmorty
node_apimodule -->|"base for"| node_fakestore
node_apimodule -->|"base for"| node_newsmodel
node_newsmodel -->|"reads"| node_newsdata
node_coreflex -->|"hooks"| node_prerender
node_coreflex -->|"hooks"| node_postrender
node_coreflex -->|"hooks"| node_postrender2
node_coreflex -->|"hooks"| node_postrender3
node_coreflex -->|"hooks"| node_postrender5
node_coreflex -->|"renders"| node_moviecard
node_coreflex -->|"renders"| node_productcard
node_coreflex -->|"renders"| node_newscard
node_coreflex -->|"renders"| node_playerview
node_moviecard -->|"composes"| node_cardlist
node_productcard -->|"composes"| node_cardlistalt
node_coreflex -->|"injects"| node_netflixcss
node_coreflex -->|"injects"| node_newscss
node_coreflex -->|"injects"| node_playercss
node_indexhtml -->|"hosts"| node_coreflex
node_moviehtml -->|"hosts"| node_coreflex
node_newshtml -->|"hosts"| node_coreflex
node_playerhtml -->|"hosts"| node_coreflex

click node_main "https://github.com/irunga1/flexjs/blob/main/main.js"
click node_main2 "https://github.com/irunga1/flexjs/blob/main/main2.js"
click node_main3 "https://github.com/irunga1/flexjs/blob/main/main3.js"
click node_main4 "https://github.com/irunga1/flexjs/blob/main/main4.js"
click node_main5 "https://github.com/irunga1/flexjs/blob/main/main5.js"
click node_main7 "https://github.com/irunga1/flexjs/blob/main/main7.js"
click node_indexhtml "https://github.com/irunga1/flexjs/blob/main/index.html"
click node_moviehtml "https://github.com/irunga1/flexjs/blob/main/movies.html"
click node_newshtml "https://github.com/irunga1/flexjs/blob/main/indexnews.html"
click node_playerhtml "https://github.com/irunga1/flexjs/blob/main/indexplayer.html"
click node_coreflex "https://github.com/irunga1/flexjs/blob/main/core/Flex.js"
click node_coreflex2 "https://github.com/irunga1/flexjs/blob/main/core/Flex2.js"
click node_coreflex3 "https://github.com/irunga1/flexjs/blob/main/core/Flex3.js"
click node_apimodule "https://github.com/irunga1/flexjs/blob/main/models/ApiModule.js"
click node_tmdb "https://github.com/irunga1/flexjs/blob/main/models/TMDB.js"
click node_rickmorty "https://github.com/irunga1/flexjs/blob/main/models/RickAndMorty.js"
click node_fakestore "https://github.com/irunga1/flexjs/blob/main/models/FakeStore.js"
click node_newsmodel "https://github.com/irunga1/flexjs/blob/main/models/News.js"
click node_newsdata "https://github.com/irunga1/flexjs/blob/main/data/news.js"
click node_moviecard "https://github.com/irunga1/flexjs/blob/main/views/movieCard.js"
click node_productcard "https://github.com/irunga1/flexjs/blob/main/views/productCard.js"
click node_newscard "https://github.com/irunga1/flexjs/blob/main/views/newsCard.js"
click node_playerview "https://github.com/irunga1/flexjs/blob/main/views/playerView.js"
click node_cardlist "https://github.com/irunga1/flexjs/blob/main/views/viewCardList.js"
click node_cardlistalt "https://github.com/irunga1/flexjs/blob/main/views/viewCardListAlt.js"
click node_prerender "https://github.com/irunga1/flexjs/blob/main/helper/preRenderFn.js"
click node_prerender5 "https://github.com/irunga1/flexjs/blob/main/helper/preRenderFn5.js"
click node_postrender "https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn.js"
click node_postrender2 "https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn2.js"
click node_postrender3 "https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn3.js"
click node_postrender5 "https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn5.js"
click node_netflixcss "https://github.com/irunga1/flexjs/blob/main/css/netflix.css"
click node_newscss "https://github.com/irunga1/flexjs/blob/main/css/news.css"
click node_playercss "https://github.com/irunga1/flexjs/blob/main/css/player.css"

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_main,node_main2,node_main3,node_main4,node_main5,node_main7,node_indexhtml,node_moviehtml,node_newshtml,node_playerhtml toneBlue
class node_coreflex,node_coreflex2,node_coreflex3 toneAmber
class node_apimodule,node_tmdb,node_rickmorty,node_fakestore,node_newsmodel,node_newsdata toneMint
class node_moviecard,node_productcard,node_newscard,node_playerview,node_cardlist,node_cardlistalt,node_prerender,node_prerender5,node_postrender,node_postrender2,node_postrender3,node_postrender5,node_netflixcss,node_newscss,node_playercss toneRose
```

## Components

### Composition

Demo entrypoints and HTML shells

- [main.js](https://github.com/irunga1/flexjs/blob/main/main.js): entrypoint · Primary demo composition root · `main.js`
- [main2.js](https://github.com/irunga1/flexjs/blob/main/main2.js): entrypoint · Alternative demo composition · `main2.js`
- [main3.js](https://github.com/irunga1/flexjs/blob/main/main3.js): entrypoint · Alternative demo composition · `main3.js`
- [main4.js](https://github.com/irunga1/flexjs/blob/main/main4.js): entrypoint · Alternative demo composition · `main4.js`
- [main5.js](https://github.com/irunga1/flexjs/blob/main/main5.js): entrypoint · Alternative demo composition · `main5.js`
- [main7.js](https://github.com/irunga1/flexjs/blob/main/main7.js): entrypoint · Alternative demo composition · `main7.js`
- [index.html](https://github.com/irunga1/flexjs/blob/main/index.html): shell · Browser shell for demos · `index.html`
- [movies.html](https://github.com/irunga1/flexjs/blob/main/movies.html): shell · Movie demo shell · `movies.html`
- [indexnews.html](https://github.com/irunga1/flexjs/blob/main/indexnews.html): shell · News demo shell · `indexnews.html`
- [indexplayer.html](https://github.com/irunga1/flexjs/blob/main/indexplayer.html): shell · Player demo shell · `indexplayer.html`

### Runtime

Core orchestration layer

- [Flex.js](https://github.com/irunga1/flexjs/blob/main/core/Flex.js): runtime · Main lifecycle controller · `core/Flex.js`
- [Flex2.js](https://github.com/irunga1/flexjs/blob/main/core/Flex2.js): runtime · Alternative core variant · `core/Flex2.js`
- [Flex3.js](https://github.com/irunga1/flexjs/blob/main/core/Flex3.js): runtime · Alternative core variant · `core/Flex3.js`

### Data

API adapters and local data sources

- [ApiModule.js](https://github.com/irunga1/flexjs/blob/main/models/ApiModule.js): data base · Fetch and normalize API responses · `models/ApiModule.js`
- [TMDB](https://github.com/irunga1/flexjs/blob/main/models/TMDB.js): data adapter · Movie API adapter · `models/TMDB.js`
- [RickMorty](https://github.com/irunga1/flexjs/blob/main/models/RickAndMorty.js): data adapter · Character API adapter · `models/RickAndMorty.js`
- [FakeStore](https://github.com/irunga1/flexjs/blob/main/models/FakeStore.js): data adapter · Product API adapter · `models/FakeStore.js`
- [News](https://github.com/irunga1/flexjs/blob/main/models/News.js): data adapter · News data adapter · `models/News.js`
- [news.js](https://github.com/irunga1/flexjs/blob/main/data/news.js): local data · Local news dataset · `data/news.js`

### Presentation

Views, hooks, and styling

- [movieCard](https://github.com/irunga1/flexjs/blob/main/views/movieCard.js): view · Movie card renderer · `views/movieCard.js`
- [productCard](https://github.com/irunga1/flexjs/blob/main/views/productCard.js): view · Product card renderer · `views/productCard.js`
- [newsCard](https://github.com/irunga1/flexjs/blob/main/views/newsCard.js): view · News card renderer · `views/newsCard.js`
- [playerView](https://github.com/irunga1/flexjs/blob/main/views/playerView.js): view · Player renderer · `views/playerView.js`
- [viewCardList](https://github.com/irunga1/flexjs/blob/main/views/viewCardList.js): list view · Card list composition helper · `views/viewCardList.js`
- [viewCardListAlt](https://github.com/irunga1/flexjs/blob/main/views/viewCardListAlt.js): list view · Alternative list composition helper · `views/viewCardListAlt.js`
- [preRenderFn](https://github.com/irunga1/flexjs/blob/main/helper/preRenderFn.js): hook · Pre-render lifecycle hook · `helper/preRenderFn.js`
- [preRenderFn5](https://github.com/irunga1/flexjs/blob/main/helper/preRenderFn5.js): hook · Alternative pre-render hook · `helper/preRenderFn5.js`
- [postRenderFn](https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn.js): hook · Post-render lifecycle hook · `helper/postRenderFn.js`
- [postRenderFn2](https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn2.js): hook · Alternative post-render hook · `helper/postRenderFn2.js`
- [postRenderFn3](https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn3.js): hook · Alternative post-render hook · `helper/postRenderFn3.js`
- [postRenderFn5](https://github.com/irunga1/flexjs/blob/main/helper/postRenderFn5.js): hook · Alternative post-render hook · `helper/postRenderFn5.js`
- [netflix.css](https://github.com/irunga1/flexjs/blob/main/css/netflix.css): style · Movie/streaming styling · `css/netflix.css`
- [news.css](https://github.com/irunga1/flexjs/blob/main/css/news.css): style · News styling · `css/news.css`
- [player.css](https://github.com/irunga1/flexjs/blob/main/css/player.css): style · Player styling · `css/player.css`

## Connections

- main.js → Flex.js: uses · Composition root wires the runtime
- main2.js → Flex.js: uses · Composition root wires the runtime
- main3.js → Flex.js: uses · Composition root wires the runtime
- main4.js → Flex.js: uses · Composition root wires the runtime
- main5.js → Flex.js: uses · Composition root wires the runtime
- main7.js → Flex.js: uses · Composition root wires the runtime
- main.js → TMDB: configures · Selects a model per demo
- main2.js → RickMorty: configures · Selects a model per demo
- main3.js → FakeStore: configures · Selects a model per demo
- main4.js → News: configures · Selects a model per demo
- main5.js → news.js: configures · Selects a local data source
- main.js → movieCard: configures · Selects a view per demo
- main2.js → viewCardList: configures · Selects a view per demo
- main3.js → productCard: configures · Selects a view per demo
- main4.js → newsCard: configures · Selects a view per demo
- main5.js → playerView: configures · Selects a view per demo
- Flex.js → ApiModule.js: instantiates · Core creates the configured model
- ApiModule.js → TMDB: base for · Shared fetch/normalize pattern
- ApiModule.js → RickMorty: base for · Shared fetch/normalize pattern
- ApiModule.js → FakeStore: base for · Shared fetch/normalize pattern
- ApiModule.js → News: base for · Shared fetch/normalize pattern
- News → news.js: reads · Uses local news dataset
- Flex.js → preRenderFn: hooks · Optional lifecycle hook before render
- Flex.js → postRenderFn: hooks · Optional lifecycle hook after render
- Flex.js → postRenderFn2: hooks · Optional lifecycle hook after render
- Flex.js → postRenderFn3: hooks · Optional lifecycle hook after render
- Flex.js → postRenderFn5: hooks · Optional lifecycle hook after render
- Flex.js → movieCard: renders · Invokes selected view after data is ready
- Flex.js → productCard: renders · Invokes selected view after data is ready
- Flex.js → newsCard: renders · Invokes selected view after data is ready
- Flex.js → playerView: renders · Invokes selected view after data is ready
- movieCard → viewCardList: composes · Movie rendering uses list helpers
- productCard → viewCardListAlt: composes · Product rendering uses list helpers
- Flex.js → netflix.css: injects · Runtime can attach demo stylesheet
- Flex.js → news.css: injects · Runtime can attach demo stylesheet
- Flex.js → player.css: injects · Runtime can attach demo stylesheet
- index.html → Flex.js: hosts · Shell mounts the JS pipeline
- movies.html → Flex.js: hosts · Shell mounts the JS pipeline
- indexnews.html → Flex.js: hosts · Shell mounts the JS pipeline
- indexplayer.html → Flex.js: hosts · Shell mounts the JS pipeline
