# Lit + Zustand Architecture A modern, no-build web application architecture using Lit web components with Zustand state management and IndexedDB persistence. ## For TSX/React Developers If you're coming from React/TSX, here's how this architecture maps to familiar concepts: | React/TSX Pattern | This Architecture | |-------------------|-------------------| | `useState` / `useReducer` | Zustand vanilla store | | `useEffect` + state subscription | `StoreController` (ReactiveController) | | Context API | Global Zustand store | | `localStorage` / `sessionStorage` | IndexedDB via persist middleware | | JSX | Lit's `html` tagged template literals | | CSS-in-JS / CSS Modules | Lit's `css` tagged template literals | | React Router | Simple route state in store | | Build step (Vite/Webpack) | Import maps (no build!) | ### Key Differences 1. **No Virtual DOM**: Lit uses native Web Components with efficient DOM updates 2. **No Build Step**: Import maps let you use npm packages directly from CDN 3. **Reactive Controllers**: Replace hooks - attach to component lifecycle 4. **Tagged Templates**: Instead of JSX, use `html\`
...
\`` ## Architecture Overview * **Lit-based web components** - Standards-based, framework-agnostic UI * **No-build tooling** - Import maps only, no bundler required * **Zustand state management** - Lightweight, vanilla JS store * **IndexedDB persistence** - Automatic state persistence with idb-keyval ## Layout ``` src/ store/ index.js ← zustand store definition middleware/ persistence.js ← idb-keyval persist adapter sync.js ← optional cross-tab broadcast components/ app-root.js feature-a/ feature-a.js ← Lit component feature-a.css ← adopted stylesheet or constructable controllers/ fetch.js ← ReactiveController for API calls 3d.js ← optional Three/WebGPU controller lib/ idb.js ← thin idb-keyval wrapper/schema index.html importmap.json ← extracted importmap (referenced via ``` ## Benefits Over React/TSX ✅ **No build step** - Edit and refresh, instant feedback ✅ **Smaller bundle** - No framework runtime, just standards ✅ **Better encapsulation** - Shadow DOM, scoped styles ✅ **Framework agnostic** - Works anywhere, even in React apps ✅ **Future-proof** - Built on web standards ## See Also - [tasks.md](./tasks.md) - Current issues and improvements - [Lit Documentation](https://lit.dev) - [Zustand Documentation](https://zustand.docs.pmnd.rs) - [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components)