# LYStack **Repository Path**: wanglaibin/LYStack ## Basic Information - **Project Name**: LYStack - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-05 - **Last Updated**: 2026-09-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LYStack A build-tool-agnostic enterprise Vue3 Monorepo foundation: pluggable Vite / Rsbuild adapters, `@repo/*` packages shared across apps, a unified environment-variable gateway, and engineering rules written for AI collaborators. [简体中文](./README.md) | **English** If you have been writing Vue3 for a few years — you can build pages, wire up APIs, fix bugs — but keep hesitating when starting a project from scratch: - How should directories be organized? Why do `components` and `utils` keep turning into junk drawers? - Why does the axios layer get heavier with every wrapper, until nobody dares to touch it? - Why can't environment variables be read just anywhere, and why does `?? ''` plant silent production bugs? - You use Vite today and want Rsbuild tomorrow — why is business code welded to the build tool? - How can multiple apps share services, shared, and ui without copy-pasting? - Why does AI-generated code always run, but never look like your team's code? LYStack exists to answer these questions. It is not yet another frontend framework, nor an admin template with a UI skin — the market has plenty of those. What is scarce is a set of architectural ideas that explains why enterprise projects get complex, where that complexity should live, and how boundaries are maintained over time. ## Quick Start ```bash pnpm install # Interactively pick one or more apps pnpm dev # Non-interactive: start one, several, or all apps pnpm dev example-vite pnpm dev example-vite example-rsbuild pnpm dev all # Build pnpm build # Type checking / linting / tests pnpm typecheck pnpm lint pnpm test ``` Once running: | App | URL | | ----------- | --------------------- | | Vite SPA | http://localhost:5173 | | Rsbuild SPA | http://localhost:5273 | | Rsbuild MPA | http://localhost:5373 | ## Build Capability Matrix | Build tool | SPA | MPA | | ---------- | --- | ---------- | | Vite | ✅ | 🚧 Roadmap | | Rsbuild | ✅ | ✅ | > MPA is carried by Rsbuild — Rspack's js-first entry model plus a programmable TypeScript PageConfig contract is a natural fit for multi-page scenarios. Vite has an html-first mental model; its MPA support requires an HTML generation translation layer, which is on the roadmap. ## Five Core Designs ### 1. Pluggable build tools Apps declare only "what to build" and never touch Vite / Rsbuild details. ```ts // apps/example-vite/vite.config.ts import { defineViteConfig, resolveRoot } from '@repo/build-config/vite'; export default defineViteConfig({ kind: 'spa', appName: 'example-vite', root: resolveRoot(import.meta.url), entry: 'index.html', }); ``` ```ts // apps/example-rsbuild/rsbuild.config.ts import { defineRsbuildConfig, resolveRoot } from '@repo/build-config/rsbuild'; export default defineRsbuildConfig({ kind: 'spa', appName: 'example-rsbuild', root: resolveRoot(import.meta.url), entry: 'src/main.ts', }); ``` App code faces only the neutral `AppBuildOptions` contract; real build-tool differences stay locked inside the adapter. ### 2. Dependency inversion in services The request layer never depends on the router, a UI library, or token storage. Runtime capabilities are injected at the composition root during app bootstrap: ```ts configureServiceAuth({ getToken: () => localStorage.getItem(STORAGE_TOKEN_KEY) ?? '', onAuthenticationFailure: () => { // In a real project: router.push('/login') or trigger SSO console.warn('[bootstrap] Auth expired — plug in your redirect logic'); }, }); setErrorMessenger((msg: string) => { // Swap for ElMessage.error(msg) once a UI framework is wired in console.error(`[LYStack] ${msg}`); }); ``` This keeps `@repo/services` reusable across apps instead of welded to one app's router / UI / localStorage. ### 3. Unified env gateway Business code never reads `import.meta.env` / `process.env` directly — everything goes through `@repo/shared/env`. ```ts const apiBase = getEnv('PUBLIC_API_BASE_URL'); ``` Missing required config fails loudly instead of silently falling back to an empty string. Inside, `shared/env` reads by priority: 1. The build-time aggregated snapshot `__PUBLIC_ENV__` 2. Vite's `import.meta.env` 3. Rsbuild / Node's `process.env` Business code never needs to know which build tool injected the environment. ### 4. PageConfig as the single source of truth for MPA The Rsbuild MPA example manages entries through `page.config.ts`. ```ts export const pages: PageEntry[] = [ { name: 'index', entry: './src/pages/index/main.ts', title: 'LYStack · Home', }, { name: 'about', entry: './src/pages/about/main.ts', title: 'LYStack · About', }, ]; ``` Only registered pages become entries, and `name` serves as both the entry name and the output HTML filename. New pages are injected by `pnpm new:page`, keeping entries from scattering. ### 5. Engineering rules written for AI LYStack ships `AGENTS.md` and `.rules/*` so team engineering constraints are readable by AI: - Comment style - Naming conventions - Directory organization - Vue3 patterns - TypeScript constraints - services / axios conventions - env gateway - error handling - self-review checklists AI does not know your team's rules and falls back to its default style. Writing the rules into the repo is what makes AI output resemble team code. ## Tech Stack | Category | Technology | | ------------- | ---------------------------------- | | Framework | Vue 3.5 + TypeScript 6 (strict) | | Build | Vite 8 / Rsbuild 2 (pluggable) | | HTTP | Axios 1.16 (multi-instance + DI) | | Package | pnpm 9.x workspace + catalog | | Orchestration | Turborepo 2.x | | Testing | Vitest (Vite) / Rstest (Rsbuild) | | Lint | ESLint 9 flat + Prettier 3 | | Commits | husky 9 + commitlint + lint-staged | | UI | None — bring your own | ## Project Structure ``` LYStack/ ├── apps/ │ ├── example-vite/ # Vite SPA example │ ├── example-rsbuild/ # Rsbuild SPA example │ └── example-rsbuild-mpa/ # Rsbuild MPA example │ ├── packages/ │ ├── build-config/ # Build abstraction: AppBuildOptions + Vite/Rsbuild adapters │ ├── shared/ # Build-agnostic shared layer: env / utils / types / constants │ ├── services/ # HTTP layer: AxiosFactory + interceptors + dependency inversion │ └── ui/ # Base UI and style variables, business-free │ ├── plop-templates/ # new:app / new:page code generators ├── app.config.ts # Single source of truth for app ports and static build config ├── pnpm-workspace.yaml # workspace + catalog version source of truth ├── turbo.json # Task orchestration └── tsconfig.base.json # Shared strict TypeScript config ``` Core dependency direction: ```txt apps/* ├─> @repo/services ──> @repo/shared ├─> @repo/ui ──> @repo/shared └─> @repo/shared apps/*.config.ts ──> @repo/build-config/vite | @repo/build-config/rsbuild └─> adapters absorb Vite/Rsbuild differences internally ``` The principle is simple: apps may assemble lower-level capabilities, but lower-level packages must never know about specific apps. ## Environment Variable Contract - The repo maintains a single set of root-level `.env.development` / `.env.test` / `.env.production`. - Only `PUBLIC_`-prefixed variables reach the client bundle; business code reads them exclusively through `@repo/shared/env`. - Vite `mode` and Rsbuild `envMode` map uniformly to `APP_ENV`; env files never redeclare it. - `dev/build` only controls HMR, minification, hashing, and sourcemaps; the test environment also gets production-grade build optimizations. ## Version Detection & Offline Cache Production builds generate the same update protocol for both Vite and Rsbuild: - Every business HTML gets `lystack-app-name`, `lystack-build-id`, and `lystack-build-time` meta tags. - A `version.json` is emitted; pages check it on load, regaining connectivity, focus, becoming visible again, and every 5 minutes. - When a new build is detected, an `app-update-ready` event is dispatched; with offline caching enabled, Service Worker updates are checked as well. - `offlineCache: true` is enabled by default only in `test` / `production` builds, generating `sw.js` and `offline.html`. Apps opt in explicitly in their own build config: ```ts export default defineViteConfig({ // ... offlineCache: true, }); ``` A detailed config object or `false` also works. The Service Worker registers only in secure contexts such as HTTPS or localhost; registration and version-check failures degrade silently without blocking the app. ## Roadmap - [x] Rsbuild adapter (SPA + MPA) - [x] Vite adapter (SPA) - [x] services dependency-inversion layer (HTTP + auth injection + error display injection) - [x] Unified env gateway with fail-loudly semantics - [x] pnpm workspace + catalog as the version source of truth - [x] Turborepo task orchestration - [x] husky + commitlint + lint-staged - [x] `AGENTS.md` + `.rules/*` AI-friendly rules - [ ] Vite MPA support (an HTML translation layer for the unified PageConfig entry contract) - [ ] Optional auth adapter layer - [x] Split-stack testing (Vitest + Rstest) and Plop template smoke tests - [ ] CI - [x] Unified Vite / Rsbuild version detection and optional offline cache ## License [MIT](./LICENSE)