From a12633b47d33de52937456bbc580070e20fdda1a Mon Sep 17 00:00:00 2001 From: lintsinghua <1930438860@qq.com> Date: Wed, 22 Oct 2025 15:12:59 +0800 Subject: [PATCH] refactor(project-structure): Restructure project architecture and improve code organization - Reorganize source code into feature-based and shared module structure - Move components, services, and hooks into more logical directories - Update project configuration files to reflect new structure - Add .env.example template for easier environment setup - Enhance README.md with more detailed project information and setup instructions - Consolidate utility functions and hooks into shared modules - Remove deprecated or unused files and components - Improve type definitions and configuration management - Update routing and main application configuration This refactoring aims to improve code maintainability, readability, and scalability by implementing a more modular and organized project structure. --- .env.example | 19 + README.md | 72 +- README_EN.md | 277 +++--- components.json | 5 +- index.html | 3 +- package.json | 11 +- postcss.config.js | 2 +- scripts/check-setup.js | 102 +++ scripts/setup.bat | 124 +++ scripts/setup.js | 142 ++++ scripts/setup.sh | 106 +++ src/App.tsx | 4 +- src/app/App.tsx | 29 + src/{ => app}/main.tsx | 4 +- src/{ => app}/routes.tsx | 14 +- src/assets/styles/globals.css | 221 +++++ src/components/common/Footer.tsx | 71 -- src/components/common/PageMeta.tsx | 20 - src/components/debug/DatabaseTest.tsx | 364 ++++---- src/components/layout/Footer.tsx | 26 + src/components/{common => layout}/Header.tsx | 23 +- src/components/layout/PageMeta.tsx | 60 ++ src/components/ui/accordion.tsx | 2 +- src/components/ui/alert-dialog.tsx | 2 +- src/components/ui/alert.tsx | 2 +- src/components/ui/avatar.tsx | 2 +- src/components/ui/badge.tsx | 2 +- src/components/ui/breadcrumb.tsx | 2 +- src/components/ui/button.tsx | 2 +- src/components/ui/calendar.tsx | 2 +- src/components/ui/card.tsx | 2 +- src/components/ui/carousel.tsx | 2 +- src/components/ui/chart.tsx | 2 +- src/components/ui/checkbox.tsx | 2 +- src/components/ui/command.tsx | 2 +- src/components/ui/dialog.tsx | 2 +- src/components/ui/drawer.tsx | 2 +- src/components/ui/dropdown-menu.tsx | 2 +- src/components/ui/form.tsx | 2 +- src/components/ui/input-otp.tsx | 2 +- src/components/ui/input.tsx | 2 +- src/components/ui/label.tsx | 2 +- src/components/ui/menubar.tsx | 2 +- src/components/ui/navigation-menu.tsx | 2 +- src/components/ui/pagination.tsx | 2 +- src/components/ui/popover.tsx | 2 +- src/components/ui/progress.tsx | 2 +- src/components/ui/radio-group.tsx | 2 +- src/components/ui/resizable.tsx | 2 +- src/components/ui/scroll-area.tsx | 2 +- src/components/ui/select.tsx | 2 +- src/components/ui/separator.tsx | 2 +- src/components/ui/sheet.tsx | 2 +- src/components/ui/sidebar.tsx | 4 +- src/components/ui/skeleton.tsx | 2 +- src/components/ui/slider.tsx | 2 +- src/components/ui/switch.tsx | 2 +- src/components/ui/table.tsx | 2 +- src/components/ui/tabs.tsx | 2 +- src/components/ui/textarea.tsx | 2 +- src/components/ui/toast.tsx | 2 +- src/components/ui/toaster.tsx | 2 +- src/components/ui/toggle-group.tsx | 2 +- src/components/ui/toggle.tsx | 2 +- src/components/ui/tooltip.tsx | 2 +- .../analysis}/services/codeAnalysis.ts | 0 src/features/analysis/services/index.ts | 2 + src/features/projects/services/index.ts | 3 + .../projects}/services/repoScan.ts | 4 +- src/features/projects/services/repoZipScan.ts | 216 +++++ src/hooks/use-debounce.ts | 15 - src/hooks/use-go-back.ts | 17 - src/index.css | 106 --- src/lib/utils.ts | 39 - src/pages/AdminDashboard.tsx | 4 +- src/pages/AuditTasks.tsx | 167 ++-- src/pages/Dashboard.tsx | 801 ++++++++---------- src/pages/InstantAnalysis.tsx | 785 ++++++++--------- src/pages/Login.tsx | 6 +- src/pages/NotFound.tsx | 2 +- src/pages/ProjectDetail.tsx | 6 +- src/pages/Projects.tsx | 572 +++++++++---- src/pages/SamplePage.tsx | 2 +- src/pages/TaskDetail.tsx | 4 +- src/services/.keep | 0 src/services/repoZipScan.ts | 104 --- .../supabase.ts => shared/config/database.ts} | 0 src/shared/config/env.ts | 38 + src/shared/config/index.ts | 3 + src/shared/constants/index.ts | 93 ++ src/shared/hooks/index.ts | 7 + src/shared/hooks/use-go-back.ts | 15 + src/{ => shared}/hooks/use-mobile.ts | 2 +- src/{ => shared}/hooks/use-toast.tsx | 5 +- src/shared/hooks/useAsync.ts | 62 ++ src/shared/hooks/useDebounce.ts | 46 + src/shared/hooks/useLocalStorage.ts | 60 ++ src/{types/types.ts => shared/types/index.ts} | 8 + src/shared/utils/paths.ts | 40 + src/shared/utils/utils.ts | 164 ++++ src/types/index.ts | 6 - supabase/migrations/full_schema.sql | 604 ++++++------- tailwind.config.js | 2 +- vite.config.ts | 49 +- 104 files changed, 3617 insertions(+), 2229 deletions(-) create mode 100644 .env.example create mode 100644 scripts/check-setup.js create mode 100644 scripts/setup.bat create mode 100644 scripts/setup.js create mode 100755 scripts/setup.sh create mode 100644 src/app/App.tsx rename src/{ => app}/main.tsx (71%) rename src/{ => app}/routes.tsx (72%) create mode 100644 src/assets/styles/globals.css delete mode 100644 src/components/common/Footer.tsx delete mode 100644 src/components/common/PageMeta.tsx create mode 100644 src/components/layout/Footer.tsx rename src/components/{common => layout}/Header.tsx (73%) create mode 100644 src/components/layout/PageMeta.tsx rename src/{ => features/analysis}/services/codeAnalysis.ts (100%) create mode 100644 src/features/analysis/services/index.ts create mode 100644 src/features/projects/services/index.ts rename src/{ => features/projects}/services/repoScan.ts (97%) create mode 100644 src/features/projects/services/repoZipScan.ts delete mode 100644 src/hooks/use-debounce.ts delete mode 100644 src/hooks/use-go-back.ts delete mode 100644 src/index.css delete mode 100644 src/lib/utils.ts delete mode 100644 src/services/.keep delete mode 100644 src/services/repoZipScan.ts rename src/{db/supabase.ts => shared/config/database.ts} (100%) create mode 100644 src/shared/config/env.ts create mode 100644 src/shared/config/index.ts create mode 100644 src/shared/constants/index.ts create mode 100644 src/shared/hooks/index.ts create mode 100644 src/shared/hooks/use-go-back.ts rename src/{ => shared}/hooks/use-mobile.ts (99%) rename src/{ => shared}/hooks/use-toast.tsx (96%) create mode 100644 src/shared/hooks/useAsync.ts create mode 100644 src/shared/hooks/useDebounce.ts create mode 100644 src/shared/hooks/useLocalStorage.ts rename src/{types/types.ts => shared/types/index.ts} (96%) create mode 100644 src/shared/utils/paths.ts create mode 100644 src/shared/utils/utils.ts delete mode 100644 src/types/index.ts diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f217521 --- /dev/null +++ b/.env.example @@ -0,0 +1,19 @@ +# Google Gemini AI 配置 (必需) +VITE_GEMINI_API_KEY=your_gemini_api_key_here +VITE_GEMINI_MODEL=gemini-2.5-flash +VITE_GEMINI_TIMEOUT_MS=25000 + +# Supabase 配置 (可选,用于数据持久化) +VITE_SUPABASE_URL=https://your-project.supabase.co +VITE_SUPABASE_ANON_KEY=your-anon-key-here + +# GitHub 集成 (可选,用于仓库分析) +VITE_GITHUB_TOKEN=your_github_token_here + +# 应用配置 +VITE_APP_ID=xcodereviewer + +# 分析配置 +VITE_MAX_ANALYZE_FILES=40 +VITE_LLM_CONCURRENCY=2 +VITE_LLM_GAP_MS=500 \ No newline at end of file diff --git a/README.md b/README.md index bf50b98..bc5d345 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # XCodeReviewer - 您的智能代码审计伙伴 🚀
+
+
@@ -14,19 +18,18 @@
[](https://vitejs.dev/)
[](https://supabase.com/)
[](https://ai.google.dev/)
-[](https://star-history.com/#lintsinghua/XCodeReviewer&Date)
-**XCodeReviewer** is a modern code auditing platform powered by Large Language Models (LLM), designed to provide developers with intelligent, comprehensive, and in-depth code quality analysis and review services.
+**XCodeReviewer** is a modern code audit platform powered by Large Language Models (LLM), designed to provide developers with intelligent, comprehensive, and in-depth code quality analysis and review services.
## 🌟 Why Choose XCodeReviewer?
-In the fast-paced world of software development, ensuring code quality is crucial. Traditional code auditing tools are rigid and inefficient, while manual auditing is time-consuming and labor-intensive. XCodeReviewer leverages the powerful capabilities of Google Gemini AI to revolutionize the way code review is conducted:
+In the fast-paced world of software development, ensuring code quality is crucial. Traditional code audit tools are rigid and inefficient, while manual audits are time-consuming and labor-intensive. XCodeReviewer leverages the powerful capabilities of Google Gemini AI to revolutionize the way code reviews are conducted:
-- **🤖 AI-Driven Deep Analysis**: Beyond traditional static analysis, understanding code intent and discovering deep logical issues.
+- **🤖 AI-Driven Deep Analysis**: Beyond traditional static analysis, understands code intent and discovers deep logical issues.
- **🎯 Multi-dimensional, Comprehensive Assessment**: From **security**, **performance**, **maintainability** to **code style**, providing 360-degree quality evaluation.
-- **💡 Clear, Actionable Fix Suggestions**: Innovative **What-Why-How** pattern that not only tells you "what" the problem is, but also explains "why" and provides "how to fix" with specific code examples.
-- **⚡ Real-time Feedback, Instant Improvement**: Whether it's code snippets or entire code repositories, you can get fast and accurate analysis results.
-- **✨ Modern, High-Quality User Interface**: Built with React + TypeScript, providing smooth and intuitive user experience.
+- **💡 Clear, Actionable Fix Suggestions**: Innovative **What-Why-How** approach that not only tells you "what" the problem is, but also explains "why" and provides "how to fix" with specific code examples.
+- **⚡ Real-time Feedback, Instant Improvement**: Whether it's code snippets or entire repositories, get fast and accurate analysis results.
+- **✨ Modern, Beautiful User Interface**: Built with React + TypeScript, providing a smooth and intuitive user experience.
## 🎬 Project Demo
@@ -34,77 +37,15 @@ In the fast-paced world of software development, ensuring code quality is crucia
#### 📊 Intelligent Dashboard

-*Real-time display of project statistics, quality trends and system performance, providing comprehensive code audit overview*
+*Real-time display of project statistics, quality trends, and system performance, providing comprehensive code audit overview*
#### ⚡ Instant Analysis

-*Support for rapid code snippet analysis, providing detailed What-Why-How explanations and fix suggestions*
+*Support for quick code snippet analysis with detailed What-Why-How explanations and fix suggestions*
#### 🚀 Project Management

-*Integration with GitHub/GitLab repositories, supporting multi-language project auditing and batch code analysis*
-
-## ✨ Core Features
-
-🚀 Project Management
-
-- **One-click Repository Integration**: Seamless integration with mainstream platforms like GitHub, GitLab.
-- **Multi-language "Full Suite" Support**: Covering popular languages like JavaScript, TypeScript, Python, Java, Go, Rust.
-- **Flexible Branch Auditing**: Support for precise analysis of specified code branches.
-⚡ Instant Analysis
-
-- **Code Snippet "Paste & Go"**: Directly paste code in the web interface and get instant analysis results.
-- **10+ Language Instant Support**: Meeting your diverse code analysis needs.
-- **Millisecond Response**: Quickly get code quality scores and optimization suggestions.
-🧠 Intelligent Auditing
-
-- **AI Deep Code Understanding**: Based on Google Gemini, providing intelligent analysis beyond keyword matching.
-- **Five Core Dimension Detection**:
- - 🐛 **Potential Bugs**: Accurately capture logic errors, boundary conditions, and null pointer issues.
- - 🔒 **Security Vulnerabilities**: Identify security risks like SQL injection, XSS, sensitive information leakage.
- - ⚡ **Performance Bottlenecks**: Discover inefficient algorithms, memory leaks, and unreasonable async operations.
- - 🎨 **Code Style**: Ensure code follows industry best practices and unified standards.
- - 🔧 **Maintainability**: Evaluate code readability, complexity, and modularity.
-💡 Explainable Analysis (What-Why-How)
-
-- **What (What is it)**: Clearly point out problems in the code.
-- **Why (Why)**: Detailed explanation of potential risks and impacts this problem may bring.
-- **How (How to fix)**: Provide specific, directly usable code fix examples.
-- **Precise Code Location**: Quickly jump to the line and column where the problem is located.
-📊 Visual Reports
-
-- **Code Quality Dashboard**: Provide 0-100 comprehensive quality assessment, making code health status clear at a glance.
-- **Multi-dimensional Issue Statistics**: Classify and count issues by type and severity.
-- **Quality Trend Analysis**: Display code quality changes over time through charts.
-🚀 Project Management
+
+- **One-click Repository Integration**: Seamlessly connect with GitHub, GitLab, and other mainstream platforms.
+- **Multi-language "Full Stack" Support**: Covers popular languages like JavaScript, TypeScript, Python, Java, Go, Rust, and more.
+- **Flexible Branch Auditing**: Support for precise analysis of specified code branches.
+⚡ Instant Analysis
+
+- **Code Snippet "Quick Paste"**: Directly paste code in the web interface for immediate analysis results.
+- **10+ Language Instant Support**: Meet your diverse code analysis needs.
+- **Millisecond Response**: Quickly get code quality scores and optimization suggestions.
+🧠 Intelligent Auditing
+
+- **AI Deep Code Understanding**: Based on Google Gemini, providing intelligent analysis beyond keyword matching.
+- **Five Core Detection Dimensions**:
+ - 🐛 **Potential Bugs**: Precisely capture logical errors, boundary conditions, and null pointer issues.
+ - 🔒 **Security Vulnerabilities**: Identify SQL injection, XSS, sensitive information leakage, and other security risks.
+ - ⚡ **Performance Bottlenecks**: Discover inefficient algorithms, memory leaks, and unreasonable asynchronous operations.
+ - 🎨 **Code Style**: Ensure code follows industry best practices and unified standards.
+ - 🔧 **Maintainability**: Evaluate code readability, complexity, and modularity.
+💡 Explainable Analysis (What-Why-How)
+
+- **What**: Clearly identify problems in the code.
+- **Why**: Detailed explanation of potential risks and impacts the problem may cause.
+- **How**: Provide specific, directly usable code fix examples.
+- **Precise Code Location**: Quickly jump to the problematic line and column.
+📊 Visual Reports
+
+- **Code Quality Dashboard**: Provides comprehensive quality assessment from 0-100, making code health status clear at a glance.
+- **Multi-dimensional Issue Statistics**: Classify and count issues by type and severity.
+- **Quality Trend Analysis**: Display code quality changes over time through charts.
+