anhuiqiang 1 неделя назад
Родитель
Сommit
65a87a31c1
3 измененных файлов с 226 добавлено и 47 удалено
  1. 179 0
      AGENTS.md
  2. 3 3
      CLAUDE.md
  3. 44 44
      docs/DEVELOPMENT_STANDARDS.md

+ 179 - 0
AGENTS.md

@@ -0,0 +1,179 @@
+# AGENTS.md
+
+This file provides guidance for AI agents working in this repository.
+
+## Project Overview
+
+Simple Knowledge Base is a full-stack RAG (Retrieval-Augmented Generation) Q&A system built with React 19 + NestJS. It's a monorepo with Japanese/Chinese documentation but English code.
+
+**Key Features:**
+- Multi-model support (OpenAI-compatible APIs + Google Gemini native SDK)
+- Dual processing modes: Fast (Tika text-only) and High-precision (Vision pipeline)
+- User isolation with JWT authentication and per-user knowledge bases
+- Hybrid search (vector + keyword) with Elasticsearch
+- Multi-language interface (Japanese, Chinese, English)
+- Streaming responses via Server-Sent Events (SSE)
+
+## Build Commands
+
+### Root Workspace
+```bash
+# Install all dependencies
+yarn install
+
+# Start both frontend and backend in dev mode
+yarn dev
+```
+
+### Server (NestJS Backend) - Port 3001
+```bash
+cd server
+
+# Build
+yarn build
+
+# Development server (watch mode)
+yarn start:dev
+
+# Format code
+yarn format
+
+# Lint code
+yarn lint
+```
+
+### Web (React Frontend) - Port 13001
+```bash
+cd web
+
+# Development server
+yarn dev
+
+# Build for production
+yarn build
+```
+
+## Test Commands
+
+### Server (Backend) - Jest Testing
+```bash
+cd server
+
+# Run all tests
+yarn test
+
+# Run tests in watch mode
+yarn test:watch
+
+# Run with coverage report
+yarn test:cov
+
+# Run single test file by name pattern
+yarn test --testPathPattern=<test-name>
+
+# Run single test by exact path
+yarn test --testPathPattern=path/to/file.spec.ts
+
+# Run e2e tests
+yarn test:e2e
+
+# Debug tests
+yarn test:debug
+```
+
+**Examples of running single tests:**
+```bash
+# Run only auth service tests
+yarn test --testPathPattern=auth.service.spec
+
+# Run tests in specific file
+yarn test src/chat/chat.service.spec.ts
+
+# Run tests matching a pattern
+yarn test --testPathPattern="user.*service"
+```
+
+**Note:** Frontend currently has no test framework configured.
+
+## Code Style Guidelines
+
+### Language Requirements
+- **Comments**: English
+- **Log messages**: English
+- **Error messages**: Internationalized (i18n) - support Japanese/Chinese/English based on user's language preference
+
+### Formatting
+- **Prettier**: Single quotes, trailing commas enabled
+- **ESLint**: TypeScript strict mode
+- **TypeScript**: Avoid `any` types, use explicit typing
+
+### Naming Conventions
+- **Variables/Functions**: `camelCase` (e.g., `getUserData`, `processDocument`)
+- **Classes/Interfaces/Types**: `PascalCase` (e.g., `UserService`, `UserDto`)
+- **Constants**: `SCREAMING_SNAKE_CASE` (e.g., `MAX_FILE_SIZE`, `DEFAULT_TIMEOUT`)
+- **Private members**: Prefix with underscore (e.g., `_privateMethod`)
+
+### Import Organization
+1. External libraries (npm packages)
+2. Internal modules (project imports)
+3. Relative imports (same directory)
+4. Use absolute imports where configured
+
+### Error Handling
+```typescript
+try {
+  // Operation logic
+} catch (error) {
+  this.logger.error('Operation failed', error);
+  throw new Error(this.i18n.t('errors.operationFailed'));
+}
+```
+
+### Testing Guidelines
+- Place test files as `*.spec.ts` in same directory as source
+- Test file naming: `{serviceName}.spec.ts` or `{controllerName}.e2e-spec.ts`
+- Use descriptive test names (describe blocks and it blocks)
+- Mock external dependencies (APIs, databases)
+
+## Project Architecture
+
+### Directory Structure
+```
+auraAuraK/
+├── web/                    # React frontend (Vite)
+│   ├── components/         # UI components
+│   ├── contexts/           # React Context providers
+│   ├── services/           # API client services
+│   └── utils/              # Utility functions
+├── server/                 # NestJS backend
+│   ├── src/
+│   │   ├── ai/             # AI services (embedding, etc.)
+│   │   ├── api/            # API module
+│   │   ├── auth/           # JWT authentication
+│   │   ├── chat/           # Chat/RAG module
+│   │   ├── elasticsearch/  # Elasticsearch integration
+│   │   ├── import-task/    # Import task management
+│   │   ├── knowledge-base/ # Knowledge base management
+│   │   ├── libreoffice/    # LibreOffice integration
+│   │   ├── model-config/   # Model configuration management
+│   │   ├── vision/         # Vision model integration
+│   │   └── vision-pipeline/# Vision pipeline orchestration
+│   ├── data/               # SQLite database storage
+│   ├── uploads/            # Uploaded files storage
+│   └── temp/               # Temporary files
+├── docs/                   # Documentation (Japanese/Chinese)
+├── nginx/                  # Nginx configuration
+├── libreoffice-server/     # LibreOffice conversion service (Python/FastAPI)
+└── docker-compose.yml      # Docker orchestration
+```
+
+### Key Concepts
+- **Dual Processing Modes**: Fast (Tika) vs High-Precision (Vision Pipeline)
+- **Multi-Model Support**: OpenAI-compatible APIs + Google Gemini
+- **RAG System**: Hybrid search with Elasticsearch, SSE streaming responses
+- **Authentication**: JWT-based user isolation
+- **Database**: SQLite with TypeORM
+
+## Reference
+
+See `CLAUDE.md` for comprehensive project documentation and `docs/DEVELOPMENT_STANDARDS.md` for detailed coding standards.

+ 3 - 3
CLAUDE.md

@@ -113,8 +113,8 @@ simple-kb/
 ## Code Standards
 
 ### Language Requirements
-- **Code comments must be in Japanese** (updated from Chinese as per user requirement)
-- **Log messages must be in Japanese**
+- **Code comments must be in English**
+- **Log messages must be in English**
 - **Error messages must support internationalization** to enable multi-language frontend interface
 - **API response messages must support internationalization** to enable multi-language frontend interface
 - Interface supports Japanese, Chinese, and English
@@ -133,7 +133,7 @@ simple-kb/
 
 ### Adding a New API Endpoint
 1. Create controller in appropriate module under `server/src/`
-2. Add service methods with Japanese comments
+2. Add service methods with English comments
 3. Update DTOs and validation
 4. Add tests in `*.spec.ts` files
 

+ 44 - 44
docs/DEVELOPMENT_STANDARDS.md

@@ -1,71 +1,71 @@
-# 開発基準
+# Development Standards
 
-## コードコメントの基準
+## Code Language Requirements
 
-### 1. コメントの言語
+### 1. Comments
+- **All code comments must be in English**
+- Includes the following (not limited to):
+  - Function/method comments
+  - Inline comments
+  - Code block explanations
+  - TODO/FIXME comments
 
-- **すべてのコードコメントは中国語を使用する必要があります**
-- 以下を含みますが、これらに限定されません:
-  - 関数/メソッドのコメント
-  - 行内コメント
-  - コードブロックの説明
-  - TODO/FIXME コメント
+### 2. Logging
+- **All log output must be in English**
+- Includes the following (not limited to):
+  - `logger.log()` info logs
+  - `logger.warn()` warning logs
+  - `logger.error()` error logs
+  - `console.log()` debug output
 
-### 2. ログ出力の基準
+### 3. Error Messages
+- **Error messages must support internationalization (i18n)**
+- **User-facing error messages**: Display in the user's selected language (Japanese/Chinese/English) via i18n system
+- **Debug/development error messages**: Display in the user's selected language via i18n system
+- **Exception messages**: Use i18n for internationalized error messages
 
-- **すべてのログ出力は中国語を使用する必要があります**
-- 以下を含みますが、これらに限定されません:
-  - `logger.log()` 情報ログ
-  - `logger.warn()` 警告ログ
-  - `logger.error()` ラーログ
-  - `console.log()` デバッグ出力
+## Examples
 
-### 3. エラーメッセージの基準
-
-- **ユーザーに表示されるエラーメッセージは中国語を使用します**
-- **開発デバッグ用のエラーメッセージは中国語を使用します**
-- 例外スロー時のエラーメッセージには中国語を使用します
-
-## 例
-
-### 正しいコメントとログ
+### Correct Comments and Logs (English + i18n)
 
 ```typescript
-// 正解:中国語のコメント
+// Get embeddings for texts
 async getEmbeddings(texts: string[]): Promise<number[][]> {
-  this.logger.log(`正在为 ${texts.length} 个文本生成嵌入向量`); // 正解:中国語のログ
+  this.logger.log(`Getting embeddings for ${texts.length} texts`);
   
   try {
-    // APIを呼び出して埋め込みベクトルを取得
+    // Call API to get embeddings
     const response = await this.callEmbeddingAPI(texts);
     return response.data;
   } catch (error) {
-    this.logger.error('获取嵌入向量失败', error); // 正解:中国語のログ
-    throw new Error('嵌入向量生成失败'); // 正解:中国語のエラーメッセージ
+    this.logger.error('Failed to get embeddings', error);
+    // Use i18n for user-facing error messages
+    throw new Error(this.i18n.t('errors.embeddingGenerationFailed'));
   }
 }
 ```
 
-### 誤ったコメントとログ
+### Using i18n for Error Messages
 
 ```typescript
-// 誤り:英語のコメントとログ
-async getEmbeddings(texts: string[]): Promise<number[][]> {
-  this.logger.log(`Getting embeddings for ${texts.length} texts`);
-  
+import { I18nService } from './i18n.service';
+
+async processDocument(file: Express.Multer.File) {
   try {
-    // Call API to get embeddings
-    const response = await this.callEmbeddingAPI(texts);
-    return response.data;
+    // Process document...
+    return result;
   } catch (error) {
-    this.logger.error('Failed to get embeddings', error);
-    throw new Error('Embedding generation failed');
+    // Error message in user's selected language
+    throw new Error(this.i18n.t('errors.documentProcessingFailed', {
+      filename: file.originalname
+    }));
   }
 }
 ```
 
-## 履行基準
+## Compliance Standards
 
-1. **コードレビュー時には、必ずコメントとログの言語をチェックしてください**
-2. **新規コードは、中国語のコメントとログの基準に従う必要があります**
-3. **既存のコードをリファクタリングする際は、同時にコメントとログも中国語に更新してください**
+1. **During code reviews, always check the language of comments and logs**
+2. **New code must follow English comments and logs standards**
+3. **When refactoring existing code, update comments and logs to English simultaneously**
+4. **All error messages must use the i18n system for internationalization**