diff --git a/.claude/settings.local.json b/.claude/settings.local.json index f09ac2e..e641cfd 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -7,7 +7,12 @@ "Bash(node scripts/init-database-simple.js:*)", "Bash(git init:*)", "Bash(git config:*)", - "Bash(git add:*)" + "Bash(git add:*)", + "Bash(git commit -m \"$(cat <<''EOF''\nInitial commit: 5 Why Root Cause Analyzer v1.0.0\n\nPhase 0 & Phase 2 completed:\n- Project structure setup\n- Environment configuration (.env, .gitignore)\n- Enterprise-grade dependencies (bcrypt, helmet, mysql2, etc.)\n- Complete database schema with 8 tables + 2 views\n- Database initialization scripts\n- Comprehensive documentation\n\nDatabase Tables:\n- users (user management with 3-tier permissions)\n- analyses (analysis records)\n- analysis_perspectives (multi-angle analysis)\n- analysis_whys (detailed 5 Why records)\n- llm_configs (LLM API configurations)\n- system_settings (system parameters)\n- audit_logs (security audit trail)\n- sessions (session management)\n\nTech Stack:\n- Backend: Node.js + Express\n- Frontend: React 18 + Vite + Tailwind CSS\n- Database: MySQL 9.4.0\n- AI: Ollama API (qwen2.5:3b)\n\nGenerated with Claude Code\nCo-Authored-By: Claude \nEOF\n)\")", + "Bash(curl:*)", + "Bash(git remote add:*)", + "Bash(git branch:*)", + "Bash(git push:*)" ], "deny": [], "ask": [] diff --git a/PROJECT_STATUS.md b/PROJECT_STATUS.md new file mode 100644 index 0000000..243643e --- /dev/null +++ b/PROJECT_STATUS.md @@ -0,0 +1,306 @@ +# 5 Why Analyzer - 專案狀態報告 + +**版本**: 1.0.0 +**最後更新**: 2025-12-05 +**狀態**: Phase 0, 1, 2 完成 ✅ + +--- + +## 📊 整體進度 + +| Phase | 名稱 | 狀態 | 完成度 | +|-------|------|------|--------| +| Phase 0 | 專案初始化 | ✅ 完成 | 100% | +| Phase 1 | 版本控制設定 | ✅ 完成 | 100% | +| Phase 2 | 資料庫架構 | ✅ 完成 | 100% | +| Phase 3 | UI/UX 預覽確認 | ⏳ 待確認 | 50% (已有原型) | +| Phase 4 | 核心程式開發 | ⏳ 待開發 | 30% (基礎已建立) | +| Phase 5 | 管理者功能 | ⏳ 待開發 | 0% | +| Phase 6 | 通用功能 | ⏳ 待開發 | 0% | +| Phase 7 | 資安檢視 | ⏳ 待檢視 | 0% | +| Phase 8 | 文件維護 | 🔄 進行中 | 60% | +| Phase 9 | 部署前檢查 | ⏳ 待執行 | 0% | + +**總體完成度**: 34% (3/9 Phases 完成) + +--- + +## ✅ 已完成項目 + +### Phase 0: 專案初始化 +- ✅ 專案資料夾結構建立 + - `models/`, `routes/`, `templates/`, `static/`, `docs/`, `scripts/` +- ✅ 環境變數配置 + - `.env`, `.env.example` 完整設定 +- ✅ Git 版本控制準備 + - `.gitignore` 設定完成 +- ✅ 依賴套件管理 + - `package.json` 更新,包含所有必要套件 + - 安全套件: bcryptjs, helmet, express-rate-limit + - 資料庫: mysql2 + - 其他: dotenv, express-session, csv-parser, json2csv +- ✅ 文件建立 + - `README_FULL.md` + - `docs/user_command_log.md` + - `docs/CHANGELOG.md` + +### Phase 1: 版本控制設定 +- ✅ Git repository 初始化 +- ✅ Gitea repository 建立 + - **Repository URL**: https://gitea.theaken.com/donald/5why-analyzer + - **User**: donald + - **Status**: Public +- ✅ Remote origin 設定 +- ✅ Initial commit 完成 +- ✅ 推送到 Gitea main 分支 + +### Phase 2: 資料庫架構 +- ✅ 資料庫連線配置 + - `config.js` 建立 + - Connection pool 設定 +- ✅ 資料庫 Schema 設計 + - `docs/db_schema.sql` (完整 SQL) + - 8 個資料表 + 2 個視圖 +- ✅ 資料庫文件 + - `docs/db_schema.md` (詳細文件) +- ✅ 資料庫初始化腳本 + - `scripts/init-database.js` + - `scripts/init-database-simple.js` + - `scripts/test-db-connection.js` +- ✅ 資料庫建立與測試 + - 所有資料表成功建立 + - 測試資料匯入完成 + +--- + +## 🗄️ 資料庫狀態 + +**資料庫**: db_A102 @ mysql.theaken.com:33306 +**MySQL 版本**: 9.4.0 +**字元集**: utf8mb4_unicode_ci +**引擎**: InnoDB + +### 資料表清單 + +| # | 資料表 | 記錄數 | 說明 | +|---|--------|--------|------| +| 1 | users | 3 | 使用者資料表 | +| 2 | analyses | 0 | 分析記錄表 | +| 3 | analysis_perspectives | 0 | 分析角度表 | +| 4 | analysis_whys | 0 | 5 Why 詳細記錄 | +| 5 | llm_configs | 1 | LLM API 配置 | +| 6 | system_settings | 6 | 系統設定 | +| 7 | audit_logs | 0 | 稽核日誌 | +| 8 | sessions | 0 | Session 管理 | +| 9 | user_analysis_stats | - | 使用者統計視圖 | +| 10 | recent_analyses | - | 最近分析視圖 | + +### 預設資料 +- **管理員帳號**: admin@example.com (密碼: Admin@123456) +- **測試使用者**: user001, user002 +- **LLM 配置**: Ollama (qwen2.5:3b) +- **系統設定**: 6 個預設設定 + +--- + +## 🛠️ 技術架構 + +### 後端 +- **框架**: Node.js + Express +- **資料庫**: MySQL 9.4.0 +- **ORM**: mysql2 (direct SQL) +- **安全**: + - Password: bcryptjs + - Headers: helmet + - Rate Limit: express-rate-limit + - Session: express-session + +### 前端 +- **框架**: React 18 +- **建置工具**: Vite +- **樣式**: Tailwind CSS +- **狀態管理**: React Hooks + +### AI/LLM +- **提供商**: Ollama API +- **模型**: qwen2.5:3b +- **API URL**: https://ollama_pjapi.theaken.com +- **支援多語言**: 繁中、簡中、英文、日文、韓文、越南文、泰文 + +--- + +## 📂 專案結構 + +``` +5why-analyzer/ +├── .git/ # Git repository +├── .env # 環境變數 (不在 repo 中) +├── .env.example # 環境變數範本 +├── .gitignore # Git 忽略清單 +├── config.js # 配置模組 +├── server.js # Express 伺服器 +├── package.json # 專案配置 +├── index.html # HTML 入口 +├── vite.config.js # Vite 配置 +├── tailwind.config.js # Tailwind 配置 +├── postcss.config.js # PostCSS 配置 +│ +├── docs/ # 文件目錄 +│ ├── db_schema.sql # 資料庫 Schema SQL +│ ├── db_schema.md # 資料庫文件 +│ ├── CHANGELOG.md # 變更紀錄 +│ ├── user_command_log.md # 使用者指令紀錄 +│ └── git-setup-instructions.md +│ +├── scripts/ # 工具腳本 +│ ├── init-database.js # 資料庫初始化 +│ ├── init-database-simple.js +│ └── test-db-connection.js # 連線測試 +│ +├── src/ # React 前端 +│ ├── main.jsx # React 入口 +│ ├── App.jsx # 主應用 +│ ├── FiveWhyAnalyzer.jsx # 5 Why 分析器 +│ └── index.css # 全局樣式 +│ +├── models/ # 資料庫模型 (待建立) +├── routes/ # API 路由 (待建立) +├── templates/ # 前端模板 (待建立) +└── static/ # 靜態資源 + ├── css/ + ├── js/ + └── images/ +``` + +--- + +## 🔗 重要連結 + +### Git Repository +- **Gitea**: https://gitea.theaken.com/donald/5why-analyzer +- **Clone URL**: https://gitea.theaken.com/donald/5why-analyzer.git +- **Branch**: main + +### 資料庫 +- **Host**: mysql.theaken.com:33306 +- **Database**: db_A102 +- **User**: A102 + +### API +- **Ollama API**: https://ollama_pjapi.theaken.com +- **Model**: qwen2.5:3b + +### 本地開發 +- **Backend**: http://localhost:3001 +- **Frontend**: http://localhost:5173 + +--- + +## 🚀 快速開始 + +### 1. Clone Repository +```bash +git clone https://gitea.theaken.com/donald/5why-analyzer.git +cd 5why-analyzer +``` + +### 2. 安裝依賴 +```bash +npm install +``` + +### 3. 配置環境變數 +```bash +cp .env.example .env +# 編輯 .env 填入實際設定 +``` + +### 4. 初始化資料庫(如果需要) +```bash +npm run db:init +``` + +### 5. 啟動應用 +```bash +npm run dev +``` + +### 6. 訪問應用 +- Frontend: http://localhost:5173 +- Backend API: http://localhost:3001 + +--- + +## ⏭️ 下一步工作 + +### 優先級 1: Phase 3 - UI/UX 預覽確認 +- [ ] 建立 `preview.html` (純前端,無資料庫) +- [ ] 與使用者確認 UI/UX 設計 +- [ ] 取得使用者批准後進入開發階段 + +### 優先級 2: Phase 4 - 核心程式開發 +- [ ] 建立資料庫模型 (models/) + - User.js + - Analysis.js + - LLMConfig.js +- [ ] 建立 API 路由 (routes/) + - auth.js (登入/登出) + - analyze.js (5 Why 分析) + - admin.js (管理功能) +- [ ] 整合資料庫與 API +- [ ] 連接前端與後端 + +### 優先級 3: Phase 5 - 管理者功能 +- [ ] 使用者管理介面 +- [ ] LLM API 設定介面 +- [ ] 系統設定介面 +- [ ] 稽核日誌查看器 + +--- + +## 📝 待建立文件 + +- [ ] `docs/SDD.md` - 系統設計文件 +- [ ] `docs/API_DOC.md` - API 文件 +- [ ] `docs/security_audit.md` - 資安稽核報告 +- [ ] `docs/deployment_guide.md` - 部署指南 +- [ ] `docs/user_manual.md` - 使用者手冊 + +--- + +## 🐛 已知問題 + +目前沒有已知問題。 + +--- + +## 💡 注意事項 + +1. **安全性**: + - `.env` 檔案包含敏感資訊,已在 `.gitignore` 中排除 + - 預設管理員密碼需要在首次登入後更改 + - Gitea Token 已在 `.env` 中,不要外洩 + +2. **資料庫**: + - 資料庫 `db_A102` 同時包含其他 HR 系統的資料表 + - 5 Why 系統的資料表與其他系統互不影響 + - 定期備份資料庫 + +3. **開發**: + - 使用 `npm run dev` 同時啟動前後端 + - 使用 `npm run db:test` 測試資料庫連線 + - 使用 `npm run db:init` 重新初始化資料庫(會保留現有資料) + +--- + +## 📞 聯絡資訊 + +**專案維護者**: donald +**Email**: donald@panjit.com.tw +**Gitea**: https://gitea.theaken.com/donald + +--- + +**文件版本**: 1.0.0 +**最後更新**: 2025-12-05 +**下次檢視**: Phase 3 完成後 diff --git a/docs/git-setup-instructions.md b/docs/git-setup-instructions.md new file mode 100644 index 0000000..89424f3 --- /dev/null +++ b/docs/git-setup-instructions.md @@ -0,0 +1,98 @@ +# Git Setup Instructions + +## Repository Information +- **Gitea URL**: https://gitea.theaken.com/ +- **Username**: donald +- **Token**: 9e0a888d1a25bde9cf2ad5dff2bb7ee6d68d6ff0 + +## Step 1: Create Repository on Gitea + +請先在 Gitea 上建立新的 repository: + +1. 訪問 https://gitea.theaken.com/ +2. 登入帳號 (donald) +3. 點擊右上角 "+" -> "New Repository" +4. 填寫: + - **Repository name**: `5why-analyzer` + - **Description**: `5 Why Root Cause Analysis Tool with Ollama API Integration` + - **Visibility**: Private (或根據需求選擇) + - **Initialize**: 不要勾選任何選項(我們已經有 local repository) +5. 點擊 "Create Repository" + +## Step 2: Add Remote and Push + +建立 repository 後,執行以下指令: + +```bash +# 進入專案目錄 +cd "c:\Users\91223\Downloads\5why" + +# 添加 remote(使用 Token 認證) +git remote add origin https://9e0a888d1a25bde9cf2ad5dff2bb7ee6d68d6ff0@gitea.theaken.com/donald/5why-analyzer.git + +# 或使用 SSH(如果有設定 SSH key) +# git remote add origin git@gitea.theaken.com:donald/5why-analyzer.git + +# 推送到 Gitea +git push -u origin master + +# 或如果主分支叫 main +# git branch -M main +# git push -u origin main +``` + +## Step 3: Verify + +檢查 repository 是否成功推送: +```bash +git remote -v +git status +``` + +訪問 https://gitea.theaken.com/donald/5why-analyzer 查看 repository + +## Alternative: Using Gitea API + +如果您想要用 API 自動建立 repository: + +```bash +curl -X POST "https://gitea.theaken.com/api/v1/user/repos" \ + -H "Authorization: token 9e0a888d1a25bde9cf2ad5dff2bb7ee6d68d6ff0" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "5why-analyzer", + "description": "5 Why Root Cause Analysis Tool with Ollama API Integration", + "private": true, + "auto_init": false + }' +``` + +然後執行: +```bash +cd "c:\Users\91223\Downloads\5why" +git remote add origin https://9e0a888d1a25bde9cf2ad5dff2bb7ee6d68d6ff0@gitea.theaken.com/donald/5why-analyzer.git +git push -u origin master +``` + +## Troubleshooting + +### Error: remote origin already exists +```bash +git remote remove origin +git remote add origin https://9e0a888d1a25bde9cf2ad5dff2bb7ee6d68d6ff0@gitea.theaken.com/donald/5why-analyzer.git +``` + +### Error: Authentication failed +確認 Token 是否正確,或嘗試用使用者名稱密碼: +```bash +git remote set-url origin https://donald:!QAZ2wsx@gitea.theaken.com/donald/5why-analyzer.git +``` + +### Error: SSL certificate problem +```bash +git config --global http.sslVerify false +``` + +--- + +**Note**: Token 已在 `.env` 檔案中,記得不要 commit `.env` 到 repository! diff --git a/docs/user_command_log.md b/docs/user_command_log.md index e9fdf8f..1fbf9ac 100644 --- a/docs/user_command_log.md +++ b/docs/user_command_log.md @@ -22,32 +22,115 @@ - 要求遵循 Phase 0 ~ Phase 9 的完整開發流程 - 包含版本控制、資料庫架構、UI/UX 預覽、管理者功能、資安檢視等 -### 待確認事項 -1. Gitea Repository 資訊 - - 伺服器位址 - - Repository 名稱 - - 使用者帳號 +### 用戶提供的資訊(2025-12-05) +1. **MySQL 資料庫資訊** ✅ + - Host: mysql.theaken.com + - Port: 33306 + - Database: db_A102 + - User: A102 + - Password: Bb123456 -2. MySQL 資料庫資訊 - - 伺服器位址 - - Port - - 使用者帳號 - - 密碼 - - Database 名稱 +2. **Gitea Repository 資訊** ✅ + - URL: https://gitea.theaken.com/ + - User: donald + - Password: !QAZ2wsx + - Token: 9e0a888d1a25bde9cf2ad5dff2bb7ee6d68d6ff0 -3. 技術棧確認 - - 後端: Node.js (Express) 或 Python (Flask/FastAPI)? - - 前端: React + Vite (已確認) +3. **技術棧確認** ✅ + - 後端: Node.js + Express + - 前端: React + Vite + - 資料庫: MySQL 9.4.0 + - AI: Ollama API (qwen2.5:3b) --- ## 變更歷程 ### v1.0.0 (2025-12-05) -- 初始專案建立 -- 完成 Phase 0: 專案初始化 - - ✅ 建立專案資料夾結構 - - ✅ 建立 .env.example - - ✅ 建立 .gitignore - - ✅ 更新 package.json (新增安全性相關套件) - - 🔄 建立 README.md (進行中) + +#### Phase 0: 專案初始化 ✅ +- ✅ 建立專案資料夾結構 + - models/, routes/, templates/, static/, docs/, scripts/ +- ✅ 建立 .env.example 和 .env +- ✅ 建立 .gitignore +- ✅ 更新 package.json + - 新增安全性套件: bcryptjs, helmet, express-rate-limit + - 新增資料庫套件: mysql2 + - 新增其他套件: dotenv, express-session, csv-parser, json2csv +- ✅ 建立 README_FULL.md +- ✅ 建立 user_command_log.md +- ✅ 建立 CHANGELOG.md + +#### Phase 1: 版本控制設定 ✅ +- ✅ 初始化 Git repository +- ✅ 配置 Git user (donald) +- ✅ 使用 Gitea API 建立 remote repository + - Repository: https://gitea.theaken.com/donald/5why-analyzer + - Status: Public +- ✅ 添加 remote origin +- ✅ Initial commit 完成 + - Commit hash: 78efac6 + - 23 files changed, 3059 insertions(+) +- ✅ 推送到 Gitea main 分支 + +#### Phase 2: 資料庫架構設計 ✅ +- ✅ 建立 config.js 資料庫配置模組 +- ✅ 設計完整資料庫 Schema + - 8 個核心資料表 + - 2 個統計視圖 + - 完整的外鍵關聯 + - 適當的索引策略 +- ✅ 建立 docs/db_schema.sql + - 包含 CREATE TABLE 語句 + - 包含 INSERT 預設資料 + - 包含 CREATE VIEW 語句 +- ✅ 建立 docs/db_schema.md + - 詳細的資料表說明 + - 欄位定義與說明 + - 關聯圖 + - 索引策略 + - 維護建議 +- ✅ 建立資料庫初始化腳本 + - scripts/init-database.js + - scripts/init-database-simple.js + - scripts/test-db-connection.js +- ✅ 執行資料庫初始化 + - 成功建立 8 個資料表 + - 成功建立 2 個視圖 + - 成功匯入預設資料 + - 3 個使用者 (admin, user001, user002) + - 1 個 LLM 配置 (Ollama) + - 6 個系統設定 +- ✅ 測試資料庫連線 + - MySQL 9.4.0 連線成功 + - 所有資料表驗證成功 + +#### 文件建立 +- ✅ PROJECT_STATUS.md - 專案狀態總覽 +- ✅ docs/git-setup-instructions.md - Git 設定指引 +- ✅ docs/CHANGELOG.md - 變更紀錄 +- ✅ README_FULL.md - 完整專案說明 + +#### 資料庫狀態 +**連線資訊**: +- Host: mysql.theaken.com:33306 +- Database: db_A102 +- Version: MySQL 9.4.0 +- Character Set: utf8mb4_unicode_ci + +**資料表清單** (10 個): +1. users (3 rows) +2. analyses (0 rows) +3. analysis_perspectives (0 rows) +4. analysis_whys (0 rows) +5. llm_configs (1 row) +6. system_settings (6 rows) +7. audit_logs (0 rows) +8. sessions (0 rows) +9. user_analysis_stats (view) +10. recent_analyses (view) + +**預設帳號**: +- Admin: admin@example.com / Admin@123456 +- User1: user001@example.com +- User2: user002@example.com