♻️ refactor: restructure SPA routes to src/routes and src/router (#12542)

* 📝 docs: add SPA routes restructure design and implementation plan

* ♻️ refactor: restructure SPA routes to src/routes and src/router

- Move SPA page components from src/app/[variants] to src/routes/
  - (main) -> Desktop pages
  - (mobile) -> Mobile pages
  - (desktop) -> Desktop-specific pages
  - onboarding -> Onboarding pages
  - share -> Share pages
- Move router configurations from src/app/[variants]/router to src/router/
  - desktopRouter.config.tsx
  - desktopRouter.config.desktop.tsx
  - mobileRouter.config.tsx
- Keep auth pages in src/app/[variants]/(auth) for SSR
- Update all import paths:
  - @/app/[variants]/ -> @/routes/
  - Relative paths adjusted for new directory structure
- Update CLAUDE.md and project-overview skill documentation

* 🔧 chore: restore imports for RouteConfig and ErrorBoundary in desktopRouter.config.desktop.tsx

- Reintroduced the imports for RouteConfig, ErrorBoundary, and redirectElement in the desktop router configuration file.
- Ensured proper organization and functionality of the desktop routing setup.

Signed-off-by: Innei <tukon479@gmail.com>

* 🐛 fix: update import paths after routes restructure

- Fix imports from old `src/app/[variants]/` to new `src/routes/` paths
- Update Title, Sidebar, MakedownRender, McpList imports
- Fix desktop-onboarding/storage import path
- Run lint --fix to sort imports

* 📝 docs: SPA routes convention and spa-routes skill

- Add roots vs features rules to CLAUDE.md and AGENTS.md
- Add .agents/skills/spa-routes for route/feature file division
- Phase 1: move page route logic to src/features/Pages, thin route files

Made-with: Cursor

* 🌐 chore: translate non-English comments to English in memory module (#12547)

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* ♻️ refactor: move router and entries to src/spa, platform-based warmup

- Move src/router and entry.*.tsx to src/spa/
- Update HTML, vite.config, and entry imports
- Warmup only the entry matching current platform (web/mobile)
- Update CLAUDE.md, AGENTS.md, and spa-routes skill

Made-with: Cursor

* 🗂️ chore: restructure SPA routes and configurations

- Deleted outdated SPA routes and implementation plan documents.
- Migrated SPA page components to new `src/routes/` directory.
- Moved route configurations to `src/router/`.
- Updated import paths across the project to reflect new structure.
- Revised AI documentation to align with the updated directory layout.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
Co-authored-by: LobeHub Bot <i@lobehub.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Innei
2026-03-01 18:35:38 +08:00
committed by GitHub
parent 5e3a8146d1
commit 794fe5f60b
1176 changed files with 868 additions and 606 deletions

View File

@@ -21,7 +21,21 @@ lobe-chat/
│ ├── agent-runtime/ # Agent runtime
│ └── ...
├── src/
│ ├── app/ # Next.js app router
│ ├── app/ # Next.js App Router (backend API + auth)
│ │ ├── (backend)/ # API routes (trpc, webapi, etc.)
│ │ ├── spa/ # SPA HTML template service
│ │ └── [variants]/(auth)/ # Auth pages (SSR required)
│ ├── routes/ # SPA page components (Vite)
│ │ ├── (main)/ # Desktop pages
│ │ ├── (mobile)/ # Mobile pages
│ │ ├── (desktop)/ # Desktop-specific pages
│ │ ├── onboarding/ # Onboarding pages
│ │ └── share/ # Share pages
│ ├── spa/ # SPA entry points and router config
│ │ ├── entry.web.tsx # Web entry
│ │ ├── entry.mobile.tsx
│ │ ├── entry.desktop.tsx
│ │ └── router/ # React Router configuration
│ ├── store/ # Zustand stores
│ ├── services/ # Client services
│ ├── server/ # Server services and routers
@@ -29,6 +43,26 @@ lobe-chat/
└── e2e/ # E2E tests (Cucumber + Playwright)
```
## SPA Routes and Features
SPA-related code is grouped under `src/spa/` (entries + router) and `src/routes/` (page segments). We use a **roots vs features** split: route trees only hold page segments; business logic and UI live in features.
- **`src/spa/`** SPA entry points (`entry.web.tsx`, `entry.mobile.tsx`, `entry.desktop.tsx`) and React Router config (`router/`). Keeps router config next to entries to avoid confusion with `src/routes/`.
- **`src/routes/` (roots)**\
Only page-segment files: `_layout/index.tsx`, `index.tsx` (or `page.tsx`), and dynamic segments like `[id]/index.tsx`. Keep these **thin**: they should only import from `@/features/*` and compose layout/page, with no business logic or heavy UI.
- **`src/features/`**\
Business components by **domain** (e.g. `Pages`, `PageEditor`, `Home`). Put layout chunks (sidebar, header, body), hooks, and domain-specific UI here. Each feature exposes an `index.ts` (or `index.tsx`) with clear exports.
When adding or changing SPA routes:
1. In `src/routes/`, add only the route segment files (layout + page) that delegate to features.
2. Implement layout and page content under `src/features/<Domain>/` and export from there.
3. In route files, use `import { X } from '@/features/<Domain>'` (or `import Y from '@/features/<Domain>/...'`). Do not add new `features/` folders inside `src/routes/`.
See the **spa-routes** skill (`.agents/skills/spa-routes/SKILL.md`) for the full convention and file-division rules.
## Development
### Starting the Dev Environment