|
| 1 | +# CLAUDE.md - JEditor Project Guidelines |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +JEditor is a Python-based code editor built with PySide6 (Qt), featuring syntax highlighting, code formatting, plugin system, Git integration, and LangChain-powered AI assistance. |
| 6 | + |
| 7 | +- **Language**: Python 3.10+ |
| 8 | +- **UI Framework**: PySide6 6.11.0 |
| 9 | +- **Package Manager**: pip / setuptools |
| 10 | +- **Testing**: pytest + pytest-qt |
| 11 | +- **Linting**: ruff, pycodestyle |
| 12 | +- **Formatting**: yapf |
| 13 | + |
| 14 | +## Project Structure |
| 15 | + |
| 16 | +``` |
| 17 | +je_editor/ # Main package |
| 18 | + pyside_ui/ # UI layer (Qt widgets) |
| 19 | + browser/ # Built-in browser |
| 20 | + code/ # Code editor components (syntax, formatting, process management) |
| 21 | + dialog/ # Dialog windows |
| 22 | + git_ui/ # Git UI components |
| 23 | + main_ui/ # Main window and layout |
| 24 | + code_scan/ # Ruff linting & watchdog file monitoring |
| 25 | + git_client/ # Git operations (GitPython) |
| 26 | + plugins/ # Plugin loader system |
| 27 | + utils/ # Shared utilities |
| 28 | +test/ # Unit tests (pytest) |
| 29 | +docs/ # Sphinx documentation |
| 30 | +``` |
| 31 | + |
| 32 | +## Build & Test Commands |
| 33 | + |
| 34 | +```bash |
| 35 | +# Install dependencies |
| 36 | +pip install -r requirements.txt |
| 37 | + |
| 38 | +# Install dev dependencies |
| 39 | +pip install -r dev_requirements.txt |
| 40 | + |
| 41 | +# Run tests (excludes Qt UI tests by default) |
| 42 | +pytest |
| 43 | + |
| 44 | +# Build package (stable) |
| 45 | +python -m build |
| 46 | + |
| 47 | +# Build dev package (rename pyproject.toml <-> dev.toml first) |
| 48 | +python -m build |
| 49 | +``` |
| 50 | + |
| 51 | +## Design Principles |
| 52 | + |
| 53 | +### Design Patterns |
| 54 | + |
| 55 | +- **MVC separation**: UI widgets (View) in `pyside_ui/`, business logic (Model/Controller) in `code_scan/`, `git_client/`, `utils/` |
| 56 | +- **Plugin architecture**: Extend functionality via `plugins/plugin_loader.py` without modifying core code |
| 57 | +- **Observer pattern**: Use Qt signals/slots for decoupled event communication between components |
| 58 | +- **Strategy pattern**: Code formatting and syntax highlighting are interchangeable strategies |
| 59 | +- **Single Responsibility**: Each module handles one concern; avoid god classes |
| 60 | + |
| 61 | +### Software Engineering |
| 62 | + |
| 63 | +- **DRY**: Extract shared logic into `utils/`; never duplicate code across modules |
| 64 | +- **SOLID principles**: Favor composition over inheritance; depend on abstractions |
| 65 | +- **Fail fast**: Validate inputs at boundaries; raise clear exceptions early |
| 66 | +- **Minimal public API**: Keep internal methods private (`_prefix`); expose only what consumers need |
| 67 | +- **Type hints**: All function signatures must include type annotations |
| 68 | + |
| 69 | +### Performance |
| 70 | + |
| 71 | +- **Lazy loading**: Defer heavy imports and widget initialization until needed |
| 72 | +- **Thread safety**: Run file I/O, Git operations, linting, and process execution in `QThread` or background threads — never block the UI thread |
| 73 | +- **Efficient string handling**: Use `QTextCursor` batch operations for bulk text edits; avoid repeated `setText()` calls |
| 74 | +- **Resource cleanup**: Always release file handles, threads, and subprocesses in `closeEvent` or `deleteLater` |
| 75 | +- **Debounce**: Throttle expensive operations triggered by rapid user input (typing, resizing) |
| 76 | + |
| 77 | +### Security (Mandatory) |
| 78 | + |
| 79 | +- **No shell injection**: Never pass unsanitized user input to `subprocess.Popen(shell=True)` or `os.system()`. Use `subprocess.run()` with argument lists |
| 80 | +- **Path traversal prevention**: Validate and sanitize all file paths from user input; reject paths containing `..` when operating within a project directory |
| 81 | +- **No eval/exec on user data**: Never use `eval()`, `exec()`, or `compile()` on untrusted input |
| 82 | +- **Sensitive data**: Never hardcode API keys, tokens, or credentials. Load from environment variables or config files excluded via `.gitignore` |
| 83 | +- **Dependency awareness**: Pin dependency versions; review before upgrading |
| 84 | +- **Input validation**: Sanitize all external input (file content, plugin data, user dialog input) at system boundaries |
| 85 | + |
| 86 | +## Code Style |
| 87 | + |
| 88 | +- Follow PEP 8; enforced by ruff |
| 89 | +- Use `snake_case` for functions/variables, `PascalCase` for classes |
| 90 | +- Keep functions short and focused (< 50 lines preferred) |
| 91 | +- Remove dead code — do not comment out unused blocks or leave `# TODO` stubs without tracking |
| 92 | + |
| 93 | +## Git & Commit Rules |
| 94 | + |
| 95 | +- **Commit messages**: Write in English, concise, imperative mood (e.g., "Add plugin hot-reload support") |
| 96 | +- **No AI attribution**: Do not mention any AI tool, assistant, or model name in commit messages or code comments |
| 97 | +- **Branch strategy**: `main` = stable release, `dev` = active development |
| 98 | +- **Clean commits**: Each commit should be a single logical change; no unrelated changes bundled together |
0 commit comments