Files
nimg.neuroinf.jp/.opencode/plans/source-code-layout-redesign.md
T
orrisroot f96130aacf refactor: reorganize codebase into layered routing, pages, and components
- Move page components from module directories to src/pages/
- Extract reusable UI components into src/components/
- Introduce src/routes/ with modular route definitions per domain
- Add @/ path alias in tsconfig for cleaner absolute imports
- Update all import paths to reflect the new directory structure
- Move bulletin.json from assets/ to src/nimgdocs/ root
- Bump react-router-dom to 7.16.0 and @biomejs/biome to 2.4.16
2026-05-29 12:57:12 +09:00

361 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ソースコードレイアウト再構成計画
## 目標
サイト固有のルーティングおよびCSSデザイン部分と、純粋なReactコンポーネントを分離する。
---
## 分離ルール
| ディレクトリ | 内容 | CSSモジュール | assets |
|---|---|---|---|
| `routes/` | `Routes`/`Route`/`Navigate`のみ。CSSもassetsもゼロ | なし | なし |
| `pages/` | ルーティングされるページコンポーネント | あり | あり(直配置) |
| `components/` | 純粋UIコンポーネント(ルーティングフックなし) | あり(隣接) | あり(`images/`) |
**`images/` の配置ルール**:
- 各コンポーネントカテゴリの直下にフラットな `images/` フォルダを配置
- サブカテゴリ(2階層目以降のディレクトリ)の画像は親カテゴリの `images/` に統合
- 固有の画像(1つのコンポーネントのみが使用)は `Xxx.images/` として配置
---
## 新しいディレクトリ構造
```
src/
├── App.tsx # BrowserRouterラッパー(変更なし)
├── App.css # グローバルCSS(変更なし)
├── config.ts # 設定(変更なし)
├── functions.ts # ユーティリティ(変更なし)
├── main.tsx # エントリポイント(変更なし)
│
├── routes/ # ★新設: ルーティング層
│ ├── AppRoutes.tsx # 最上位Routes(App.tsxから分離)
│ ├── PageRoutes.tsx # PageコンポーネントのRoutes/レイアウト
│ └── modules/
│ ├── XoonipsRoutes.tsx # XoonipsのRoutes抽出
│ ├── NimgdocsRoutes.tsx # NimgdocsのRoutes抽出
│ ├── CreditsRoutes.tsx # CreditsのRoutes抽出
│ ├── NimgcenterRoutes.tsx # NimgcenterのRoutes抽出
│ └── BrainExplorerRoutes.tsx # BrainExplorerのRoutes抽出
│
├── pages/ # ★新設: ページ層 (Routes + CSS混在)
│ ├── xoonips/
│ │ ├── XoonipsTopPage.tsx # XoonipsTop.tsx からリネーム
│ │ ├── XoonipsTopPage.module.css
│ │ ├── XoonipsDetailPage.tsx # XoonipsDetailItem.tsx からリネーム
│ │ ├── XoonipsSearchPage.tsx # XoonipsSearchBy*.tsx を統合
│ │ └── XoonipsSearchPage.module.css
│ ├── nimgdocs/
│ │ ├── NimgdocsPage.tsx # Nimgdocs.tsx + NimgdocsPage内容
│ │ └── NimgdocsTutorialsPage.tsx
│ ├── credits/
│ │ ├── CreditsIndexPage.tsx # CreditsIndex.tsx からリネーム
│ │ └── CreditsPagePage.tsx # CreditsPage.tsx からリネーム
│ ├── nimgsearch/
│ │ ├── NimgsearchPage.tsx # Nimgsearch.tsx そのまま(905行)
│ │ └── NimgsearchPage.module.css
│ └── brainexplorer/
│ ├── BrainExplorerPage.tsx # BrainExplorerIndex.tsx からリネーム
│ └── BrainExplorerPage.module.css
│
├── components/ # ★新設: 純粋UIコンポーネント
│ ├── common/
│ │ ├── Loading.tsx
│ │ ├── LangFlag.tsx
│ │ ├── LangFlag.images/
│ │ │ ├── mlang_english.gif
│ │ │ └── mlang_japanese.gif
│ │ ├── PageNotFound.tsx
│ │ ├── NoticeBanner.tsx
│ │ ├── XoopsCode.tsx
│ │ └── XoopsCode.images/
│ │ └── smil*.gif
│ ├── xoonips/
│ │ ├── blocks/
│ │ │ ├── IndexTree.tsx
│ │ │ ├── IndexTree.module.css
│ │ │ ├── SearchForm.tsx # Search.tsx からリネーム
│ │ │ ├── RecentContents.tsx
│ │ │ ├── RecentContents.module.css
│ │ │ ├── Rankings.tsx
│ │ │ ├── Rankings.module.css
│ │ │ └── images/
│ │ │ ├── star.gif
│ │ │ ├── tree_line.png
│ │ │ └── tree_node.png
│ │ ├── lib/
│ │ │ ├── XoonipsListItem.tsx
│ │ │ ├── XoonipsListItem.module.css
│ │ │ ├── XoonipsListIndex.tsx
│ │ │ ├── simpf-links.json # JSONは直配置
│ │ │ ├── tree.json # JSONは直配置
│ │ │ ├── AdvancedSearchQuery.ts
│ │ │ ├── IndexUtil.ts
│ │ │ ├── ItemUtil.ts
│ │ │ ├── field/
│ │ │ │ ├── (全23ファイル)
│ │ │ │ └── images/
│ │ │ │ └── simpf_button.png
│ │ │ └── images/
│ │ │ └── icon_folder.gif
│ │ ├── item-type/ # 14アイテムタイプ(構造維持)
│ │ │ ├── index.tsx
│ │ │ ├── lib/ # TopBase, ListBase, DetailBase, AdvancedSearchBase
│ │ │ ├── binder/
│ │ │ ├── book/
│ │ │ └── ...
│ │ └── images/ # xoonipsカテゴリ統合アセット
│ │ ├── icon_binder.gif
│ │ ├── icon_book.gif
│ │ ├── icon_conference.gif
│ │ ├── icon_data.gif
│ │ ├── icon_files.gif
│ │ ├── icon_memo.gif
│ │ ├── icon_model.gif
│ │ ├── icon_nimgcenter.gif
│ │ ├── icon_paper.gif
│ │ ├── icon_presentation.gif
│ │ ├── icon_simulator.gif
│ │ ├── icon_stimulus.gif
│ │ ├── icon_tool.gif
│ │ └── icon_url.gif
│ ├── nimgsearch/
│ │ └── images/
│ │ └── brainarea.json
│ └── custom/
│ ├── Header.tsx
│ ├── Footer.tsx
│ └── images/ # customカテゴリ統合アセット
│ ├── jnode.png
│ ├── banner-niu.png
│ ├── banner-riken.png
│ ├── banner-riken-cbs.png
│ ├── banner-xoonips.png
│ ├── blockTitle.png
│ ├── blockTitleBack.png
│ ├── blockTitleIndent16.png
│ ├── blockTitleIndent12.png
│ ├── footer_back.png
│ ├── h1_indent.png
│ ├── h2_background.png
│ ├── logo.png
│ ├── page_top.png
│ ├── smenu_01.png
│ ├── smenu_03.png
│ ├── smenu_04.png
│ ├── mmenu_01.png
│ ├── mmenu_02.png
│ ├── mmenu_03.png
│ └── mmenu_04.png
│
├── custom/ # ★大幅簡素化: レイアウトのみ
│ └── Page.tsx # Routesを分離、レイアウト構造のみ残す
│
├── common/
│ └── AppRoot.tsx # 変更なし
│
├── nimgcenter/ # 変更なし(routes層のみ参照)
└── data/ # 変更なし
```
---
## Phaseごとの作業詳細
### Phase 1: `routes/` 新設
#### 1a. `routes/AppRoutes.tsx` を作成
- `App.tsx` の BrowserRouter 直下の Routes を分離
- `AppRoot` を参照するだけの簡素なRoutes
#### 1b. `routes/PageRoutes.tsx` を作成
- `custom/Page.tsx` の Routes 構造を抽出
- `CenterColumn`, `LeftColumn`, `MainContent` のレイアウト構造を保持
- 各モジュールのRoutesを `routes/modules/` から import
#### 1c. `routes/modules/XoonipsRoutes.tsx` を作成
- `Xoonips.tsx` の Routes を抽出
- Pages (`XoonipsTopPage`, `XoonipsDetailPage` 等) を参照
- CSSモジュール・HelmetはPages側に移動
#### 1d. `routes/modules/NimgdocsRoutes.tsx` を作成
- `Nimgdocs.tsx` の Routes を抽出
- Pages を参照
#### 1e. `routes/modules/CreditsRoutes.tsx` を作成
- `Credits.tsx` の Routes を抽出
- Pages を参照
#### 1f. `routes/modules/NimgcenterRoutes.tsx` を作成
- `NimgenterUtilities.tsx` の Routes を抽出
- Pages を参照
#### 1g. `routes/modules/BrainExplorerRoutes.tsx` を作成
- `BrainExplorer.tsx` の Routes を抽出
- Pages を参照
### Phase 2: `components/` 新設
#### 2a. `components/common/` を作成
- `common/lib/` の全ファイル (`Loading.tsx`, `LangFlag.tsx`, `PageNotFound.tsx`, `NoticeSiteHasBeenArchived.tsx`, `XoopsCode.tsx`) を移動
- `common/assets/images/mlang_*.gif` → `components/common/LangFlag.images/`
- `common/assets/images/smil*.gif` → `components/common/XoopsCode.images/`
- `common/assets/xoops.css` はそのまま(グローバルCSS)
#### 2b. `components/xoonips/blocks/` を作成
- `xoonips/blocks/` の全ファイル (`IndexTree.tsx`, `Search.tsx`, `RecentContents.tsx`, `Rankings.tsx`) を移動
- `Search.tsx` → `SearchForm.tsx` にリネーム
- CSSモジュールは各ファイルの隣に保持
- `xoonips/assets/images/star.gif` → `components/xoonips/blocks/images/`
- `xoonips/assets/images/tree_*.png` → `components/xoonips/blocks/images/`
- IndexTree, Rankings の `useNavigate` を props/callback に変更
#### 2c. `components/xoonips/lib/` を作成
- `xoonips/lib/` の全ファイル (`XoonipsListItem.tsx`, `XoonipsListIndex.tsx`, `IndexUtil.ts`, `ItemUtil.ts`, `AdvancedSearchQuery.ts`) を移動
- CSSモジュールは各ファイルの隣に保持
- `xoonips/assets/images/icon_folder.gif` → `components/xoonips/lib/images/`
- `simpf-links.json`, `tree.json` は直配置
- XoonipsListItem の `useNavigate`/`useLocation` を props化
#### 2d. `components/xoonips/item-type/` を作成
- `xoonips/item-type/` の全構造をそのまま移動
- 各アイテムタイプの Top/List/Detail/AdvancedSearch コンポーネントを移動
- `xoonips/assets/images/icon_*.gif` (14種) → `components/xoonips/images/`
- `xoonips/item-type/lib/field/` の全ファイルを移動
- `simpf_button.png` → `components/xoonips/lib/field/images/`
#### 2e. `components/custom/` を作成
- `custom/Header.tsx`, `custom/Footer.tsx` を移動
- `custom/assets/images/*` (20種) → `components/custom/images/`
- Header の `useLocation` はそのまま(ルーティングフックだが、Headerはレイアウト固有)
- Footer の `useLocation` はそのまま
#### 2f. `components/custom/blocks/` を作成
- `custom/blocks/` の全ファイル (`Information.tsx`, `BulletinBoard.tsx`, `HowToUseLinks.tsx`, `HowToUseVideo.tsx`, `Questionnaire.tsx`, `RecentStatus.tsx`) を移動
#### 2g. `components/nimgsearch/images/` を作成
- `nimgsearch/assets/brainarea.json` → `components/nimgsearch/images/`
### Phase 3: `pages/` 新設
#### 3a. `pages/xoonips/` を作成
- `XoonipsTop.tsx` → `XoonipsTopPage.tsx` (CSSモジュール同行)
- `XoonipsDetailItem.tsx` → `XoonipsDetailPage.tsx`
- `XoonipsSearchByKeyword.tsx`, `XoonipsSearchByIndexId.tsx`, `XoonipsSearchByItemType.tsx`, `XoonipsSearchByAdvancedKeyword.tsx` → `XoonipsSearchPage.tsx` に統合(共通の検索結果表示ロジックを共有)
- `XoonipsTop.module.css` → `XoonipsTopPage.module.css`
#### 3b. `pages/nimgdocs/` を作成
- `Nimgdocs.tsx` の Routes + Pages を統合して `NimgdocsPage.tsx` に
- `NimgdocsTutorials.tsx` → `NimgdocsTutorialsPage.tsx`
- JSONアセット (`3dbrowse.json` 等) は直配置
#### 3c. `pages/credits/` を作成
- `CreditsIndex.tsx` → `CreditsIndexPage.tsx`
- `CreditsPage.tsx` → `CreditsPagePage.tsx`
#### 3d. `pages/nimgsearch/` を作成
- `Nimgsearch.tsx` → `NimgsearchPage.tsx` (905行、そのまま)
- `Nimgsearch.module.css` → `NimgsearchPage.module.css`
#### 3e. `pages/brainexplorer/` を作成
- `BrainExplorerIndex.tsx` → `BrainExplorerPage.tsx`
- `BrainExplorerIndex.module.css` → `BrainExplorerPage.module.css`
- `brainexplorer/assets/images/*` (3種) → `pages/brainexplorer/images/`
### Phase 4: クリーンアップ
#### 4a. 既存ファイルの削除
- `xoonips/Xoonips.tsx` → routes/へ移動済みなので削除
- `xoonips/XoonipsTop.tsx` → pages/へ移動済みなので削除
- `xoonips/XoonipsDetailItem.tsx` → pages/へ移動済みなので削除
- `xoonips/XoonipsAdvancedSearch.tsx` → routes/へ統合
- `xoonips/XoonipsSearchBy*.tsx` → pages/へ移動済みなので削除
- `xoonips/XoonipsXoopsPathRedirect.tsx` → routes/へ統合
- `xoonips/blocks/*` → components/へ移動済みなので削除
- `xoonips/lib/*` → components/へ移動済みなので削除
- `xoonips/item-type/*` → components/へ移動済みなので削除
- `xoonips/assets/*` → components/へ移動済みなので削除
- `custom/Page.tsx` → routes/へ移動済みなので削除
- `custom/Header.tsx` → components/へ移動済みなので削除
- `custom/Footer.tsx` → components/へ移動済みなので削除
- `custom/blocks/*` → components/へ移動済みなので削除
- `custom/assets/*` → components/へ移動済みなので削除
- `nimgdocs/Nimgdocs.tsx` → routes/へ統合
- `nimgdocs/NimgdocsTutorials.tsx` → pages/へ移動済みなので削除
- `nimgdocs/assets/*` → pages/へ移動済みなので削除
- `credits/Credits.tsx` → routes/へ統合
- `credits/CreditsIndex.tsx` → pages/へ移動済みなので削除
- `credits/CreditsPage.tsx` → pages/へ移動済みなので削除
- `credits/blocks/CreditsMenu.tsx` → components/へ移動済みなので削除
- `brainexplorer/BrainExplorer.tsx` → routes/へ統合
- `brainexplorer/BrainExplorerIndex.tsx` → pages/へ移動済みなので削除
- `brainexplorer/assets/*` → pages/へ移動済みなので削除
- `common/lib/*` → components/へ移動済みなので削除
- `common/assets/*` → components/へ移動済みなので削除
#### 4b. 空ディレクトリ削除
- `xoonips/blocks/`, `xoonips/lib/`, `xoonips/item-type/`, `xoonips/assets/`
- `custom/blocks/`, `custom/assets/`
- `nimgdocs/assets/`
- `credits/blocks/`
- `brainexplorer/assets/`
- `common/lib/`, `common/assets/`
### Phase 5: ビルド確認
```bash
npm run build
```
---
## 重要な変換ルール
### useNavigate/useLocation → props/callback
`useNavigate` を直接使用しているコンポーネントは、ナビゲーションコールバックを props で受けるように変更:
```tsx
// Before (IndexTree.tsx)
import { useNavigate } from 'react-router-dom';
const IndexTree: React.FC<Props> = () => {
const navigate = useNavigate();
const handleSelect = (key: number) => navigate(IndexUtil.getUrl(key));
};
// After
interface Props {
onNavigate: (url: string) => void;
}
const IndexTree: React.FC<Props> = ({ onNavigate }) => {
const handleSelect = (key: number) => onNavigate(IndexUtil.getUrl(key));
};
```
### ファイル命名規則
- Pages: `XxxPage.tsx` / `XxxPage.module.css`
- Components: `Xxx.tsx` / `Xxx.module.css`
- Routes: `XxxRoutes.tsx`
### Assets配置ルール
| 現在の場所 | 移動先 |
|---|---|
| `xoonips/assets/images/star.gif` | `components/xoonips/blocks/images/` |
| `xoonips/assets/images/tree_*.png` | `components/xoonips/blocks/images/` |
| `xoonips/assets/images/icon_*.gif` (14種) | `components/xoonips/images/` |
| `xoonips/assets/images/icon_folder.gif` | `components/xoonips/lib/images/` |
| `xoonips/assets/images/simpf_button.png` | `components/xoonips/lib/field/images/` |
| `common/assets/images/mlang_*.gif` | `components/common/LangFlag.images/` |
| `common/assets/images/smil*.gif` | `components/common/XoopsCode.images/` |
| `custom/assets/images/*` (20種) | `components/custom/images/` |
| `brainexplorer/assets/images/*` (3種) | `pages/brainexplorer/images/` |
| `nimgsearch/assets/brainarea.json` | `components/nimgsearch/images/` |
| `nimgdocs/assets/*.json` (7種) | `pages/nimgdocs/` (直配置) |
| `xoonips/assets/simpf-links.json` | `components/xoonips/lib/` (直配置) |
| `xoonips/assets/tree.json` | `components/xoonips/lib/` (直配置) |