|
1 | | -# CLAUDE.md |
| 1 | +# Repository Guidelines |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 3 | +Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed. |
4 | 4 |
|
5 | | -## Project Overview |
| 5 | +**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment. |
6 | 6 |
|
7 | | -Huntly is a self-hosted AI-powered information management tool with multiple client options. It provides AI content processing, RSS feeds, web page archiving, Twitter content saving, full-text search, and integrations with external services like GitHub. |
| 7 | +## 1. Think Before Coding |
8 | 8 |
|
9 | | -The project consists of: |
10 | | -- **Backend**: Java Spring Boot application (`app/server/`) |
11 | | -- **Web Client**: React TypeScript application (`app/client/`) |
12 | | -- **Browser Extension**: Chrome/Firefox extension with Manifest V3 (`app/extension/`) |
13 | | -- **Desktop App**: Tauri application with Vite + React frontend (`app/tauri/`) |
| 9 | +**Don't assume. Don't hide confusion. Surface tradeoffs.** |
14 | 10 |
|
15 | | -## Development Commands |
| 11 | +Before implementing: |
| 12 | +- State your assumptions explicitly. If uncertain, ask. |
| 13 | +- If multiple interpretations exist, present them - don't pick silently. |
| 14 | +- If a simpler approach exists, say so. Push back when warranted. |
| 15 | +- If something is unclear, stop. Name what's confusing. Ask. |
16 | 16 |
|
17 | | -### Backend (Spring Boot) |
18 | | -```bash |
19 | | -# Navigate to server directory |
20 | | -cd app/server |
| 17 | +## 2. Simplicity First |
21 | 18 |
|
22 | | -# Run server in dev mode (Primary Development Mode) |
23 | | -# Checks dependencies and rebuilds if necessary, then runs the server |
24 | | -# Options: |
25 | | -# --task : Enable connector tasks (default: disabled) |
26 | | -# --sql : Show SQL logs (default: disabled) |
27 | | -./start-dev.sh |
| 19 | +**Minimum code that solves the problem. Nothing speculative.** |
28 | 20 |
|
29 | | -# Build with Maven wrapper |
30 | | -./mvnw clean install |
| 21 | +- No features beyond what was asked. |
| 22 | +- No abstractions for single-use code. |
| 23 | +- No "flexibility" or "configurability" that wasn't requested. |
| 24 | +- No error handling for impossible scenarios. |
| 25 | +- If you write 200 lines and it could be 50, rewrite it. |
31 | 26 |
|
32 | | -# Run server via Maven directly |
33 | | -./mvnw spring-boot:run -pl huntly-server -am |
| 27 | +Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify. |
34 | 28 |
|
35 | | -# Or run the built JAR |
36 | | -java -Xms128m -Xmx1024m -jar huntly-server/target/huntly-server.jar |
| 29 | +## 3. Surgical Changes |
37 | 30 |
|
38 | | -# Run with custom port |
39 | | -java -Xms128m -Xmx1024m -jar huntly-server/target/huntly-server.jar --server.port=80 |
40 | | -``` |
41 | | - |
42 | | -### Web Client (React) |
43 | | -```bash |
44 | | -# Navigate to client directory |
45 | | -cd app/client |
| 31 | +**Touch only what you must. Clean up only your own mess.** |
46 | 32 |
|
47 | | -# Install dependencies |
48 | | -yarn install |
| 33 | +When editing existing code: |
| 34 | +- Don't "improve" adjacent code, comments, or formatting. |
| 35 | +- Don't refactor things that aren't broken. |
| 36 | +- Match existing style, even if you'd do it differently. |
| 37 | +- If you notice unrelated dead code, mention it - don't delete it. |
49 | 38 |
|
50 | | -# Start development server (proxies to localhost:8080) |
51 | | -yarn start |
52 | | -# or |
53 | | -yarn dev |
| 39 | +When your changes create orphans: |
| 40 | +- Remove imports/variables/functions that YOUR changes made unused. |
| 41 | +- Don't remove pre-existing dead code unless asked. |
54 | 42 |
|
55 | | -# Build for production |
56 | | -yarn build |
| 43 | +The test: Every changed line should trace directly to the user's request. |
57 | 44 |
|
58 | | -# Run tests |
59 | | -yarn test |
| 45 | +## 4. Goal-Driven Execution |
60 | 46 |
|
61 | | -# Generate API client from OpenAPI |
62 | | -yarn api-generate |
63 | | -``` |
| 47 | +**Define success criteria. Loop until verified.** |
64 | 48 |
|
65 | | -### Browser Extension |
66 | | -```bash |
67 | | -# Navigate to extension directory |
68 | | -cd app/extension |
| 49 | +Transform tasks into verifiable goals: |
| 50 | +- "Add validation" → "Write tests for invalid inputs, then make them pass" |
| 51 | +- "Fix the bug" → "Write a test that reproduces it, then make it pass" |
| 52 | +- "Refactor X" → "Ensure tests pass before and after" |
69 | 53 |
|
70 | | -# Install dependencies |
71 | | -yarn install |
| 54 | +For multi-step tasks, state a brief plan: |
| 55 | +``` |
| 56 | +1. [Step] → verify: [check] |
| 57 | +2. [Step] → verify: [check] |
| 58 | +3. [Step] → verify: [check] |
| 59 | +``` |
72 | 60 |
|
73 | | -# Development build with watch |
74 | | -yarn dev |
75 | | -yarn watch |
| 61 | +Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification. |
76 | 62 |
|
77 | | -# Production build |
78 | | -yarn build |
| 63 | +--- |
79 | 64 |
|
80 | | -# Run tests |
81 | | -yarn test |
| 65 | +**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes. |
82 | 66 |
|
83 | | -# Code formatting |
84 | | -yarn style |
85 | | -``` |
| 67 | +## Project Structure & Module Organization |
| 68 | +`app/server/` contains the Spring Boot parent with `huntly-server`, `huntly-jpa`, `huntly-common`, and `huntly-interfaces`. `app/client/` serves the React SPA, `app/extension/` holds the Chrome/Firefox browser extension, and `app/tauri/` ships the desktop app built with Tauri + Vite. Shared static assets live in `static/`; container manifests sit in `Dockerfile*` and `docker-compose.yml`. |
86 | 69 |
|
87 | | -### Desktop Application (Tauri) |
88 | | -```bash |
89 | | -cd app/tauri |
90 | | -yarn install |
| 70 | +## Build, Test, and Development Commands |
| 71 | +- Server: `cd app/server` and use `./start-dev.sh` (primary dev mode, supports `--task` to enable connectors and `--sql` to show SQL); `./mvnw clean verify` builds everything; direct maven run: `./mvnw spring-boot:run -pl huntly-server -am` serves `localhost:8080`. |
| 72 | +- Web client: `cd app/client && yarn install && yarn start`; use `yarn build` for production assets and `yarn test` for the Jest suite. |
| 73 | +- Browser extension: `cd app/extension && yarn install && yarn dev`; guard releases with `yarn build` and `yarn test`. |
| 74 | +- Desktop app (Tauri): `cd app/tauri && yarn install && yarn tauri dev`; `yarn build` compiles frontend and `yarn tauri build` bundles the desktop app. |
| 75 | +- Containers: `docker-compose up -d` runs the published image; `docker build -t huntly-local -f Dockerfile .` produces a workspace-aware image. |
91 | 76 |
|
92 | | -# Development mode (runs Vite + Tauri) |
93 | | -yarn tauri dev |
| 77 | +## Coding Style & Naming Conventions |
| 78 | +Java code uses four-space indentation, `com.huntly.*` packages, and Lombok DTOs; keep controllers in `huntly-server` and persistence code in `huntly-jpa`. TypeScript components and hooks are PascalCase files with camelCase props and co-located Tailwind styles. The React app follows `react-scripts` ESLint defaults, and the extension formats with `yarn style`. Name static assets and env samples in kebab-case to match the existing tree. |
94 | 79 |
|
95 | | -# Build frontend only |
96 | | -yarn build |
| 80 | +## Testing Guidelines |
| 81 | +Java modules rely on JUnit 5 and AssertJ; place tests beside new code under `src/test/java` and run `./mvnw test` (or module-targeted variants) before pushing. The React client uses React Testing Library through `yarn test`; name files `<Component>.test.tsx`. Extension suites run with ts-jest via `yarn test`; provide deterministic fixtures for new parsers or DOM mutations. |
97 | 82 |
|
98 | | -# Build desktop application |
99 | | -yarn tauri build |
100 | | -``` |
| 83 | +## Commit & Pull Request Guidelines |
| 84 | +Follow Conventional Commits (`feat:`, `fix:`, optional scopes) in imperative voice, keeping subjects ≤72 characters. PRs should link issues, describe impact, attach UI captures when relevant, and confirm `./mvnw clean verify`, `yarn test` (client), and `yarn test` (extension) succeed. Flag schema, Docker, or configuration changes explicitly for reviewers. |
101 | 85 |
|
102 | | -### Docker |
103 | | -```bash |
104 | | -# Run with docker-compose (recommended) |
105 | | -docker-compose up -d |
106 | | - |
107 | | -# Build local image |
108 | | -docker build -t huntly-local -f Dockerfile . |
109 | | -``` |
110 | | - |
111 | | -## Architecture |
112 | | - |
113 | | -### Backend Architecture |
114 | | -- **Spring Boot 2.6** application with modular Maven structure |
115 | | -- **Java 11** minimum requirement |
116 | | -- **Multi-module project**: huntly-server, huntly-interfaces, huntly-common, huntly-jpa |
117 | | -- **Database**: SQLite with JPA/Hibernate |
118 | | -- **Search**: Apache Lucene 9.4 with IK Analyzer for Chinese text tokenization |
119 | | -- **RSS Processing**: Rome library for feed parsing |
120 | | -- **Content Extraction**: Boilerpipe and Mozilla Readability for article content extraction |
121 | | -- **API Documentation**: Springfox/Swagger/OpenAPI |
122 | | - |
123 | | -Key modules: |
124 | | -- `huntly-server/`: Main Spring Boot application with controllers and services |
125 | | -- `huntly-interfaces/`: DTOs and API interfaces |
126 | | -- `huntly-common/`: Shared utilities and base classes |
127 | | -- `huntly-jpa/`: JPA entities, repositories, and custom specifications |
128 | | - |
129 | | -### Frontend Architecture |
130 | | -- **React 18** with TypeScript |
131 | | -- **Material-UI (MUI) v5** for UI components |
132 | | -- **TanStack Query v4** for API state management |
133 | | -- **React Router v6** for navigation |
134 | | -- **Tailwind CSS** for styling |
135 | | -- **OpenAPI Generator** for backend API client generation |
136 | | -- **react-markdown** with remark-gfm for Markdown rendering |
137 | | - |
138 | | -### Browser Extension Architecture |
139 | | -- **Manifest V3** Chrome/Firefox extension |
140 | | -- **TypeScript** with Webpack bundling |
141 | | -- **React 18** for popup and options pages |
142 | | -- **Mozilla Readability** for content extraction |
143 | | -- **Content Scripts** for page interaction |
144 | | -- **Background Service Worker** for message handling |
145 | | -- **Auto-save functionality** for web pages and Twitter/X content |
146 | | - |
147 | | -### Desktop App Architecture (Tauri) |
148 | | -- **Tauri** for native desktop wrapper |
149 | | -- **Vite** for frontend bundling |
150 | | -- **React 18** with TypeScript |
151 | | -- **System tray** integration |
152 | | -- **Embedded JRE** for running the Spring Boot server locally |
153 | | - |
154 | | -### Key Features |
155 | | -- **AI Content Processing**: Streaming content processing with configurable shortcuts for summarization, translation, etc. |
156 | | -- **Article Preview**: Real-time preview during AI processing |
157 | | -- **Tweet Saving**: Special handling for Twitter/X with thread reconstruction |
158 | | -- **Full-text Search**: Lucene-based search with Chinese tokenization support |
159 | | -- **RSS Feeds**: Automated feed fetching with file-based caching |
160 | | -- **External Connectors**: GitHub integration for syncing starred repositories |
161 | | - |
162 | | -## Database & Data Storage |
163 | | -- **Primary DB**: SQLite (`app/server/huntly-server/db.sqlite`) |
164 | | -- **Feed Cache**: File-based caching (`app/server/huntly-server/feed_cache/`) |
165 | | -- **Lucene Index**: Full-text search index (`app/server/huntly-server/lucene/`) |
166 | | - |
167 | | -## Configuration Files |
168 | | -- **Spring Boot**: `application.yml` in `app/server/huntly-server/src/main/resources/` |
169 | | -- **AI Shortcuts**: `config/default-shortcuts.json` for AI processing shortcuts |
170 | | -- **TypeScript**: Multiple `tsconfig.json` files for different modules |
171 | | -- **Webpack**: Separate configs in `app/extension/webpack/` for dev/prod builds |
172 | | -- **Tailwind**: Individual configs in client, extension, and tauri apps |
173 | | -- **Tauri**: `src-tauri/tauri.conf.json` for desktop app configuration |
174 | | - |
175 | | -## Testing |
176 | | -- **Backend**: Maven Surefire plugin with JUnit 5 and AssertJ |
177 | | -- **Extension**: Jest with ts-jest for TypeScript support |
178 | | -- **Client**: React Testing Library with Jest (via react-scripts) |
| 86 | +## Security & Configuration Tips |
| 87 | +Avoid committing SQLite artifacts in `app/server/huntly-server/db.sqlite*`; persist data through the `/data` volume when containerised. Store secrets in environment variables or Tauri keychains. Expose the API over HTTPS and review CORS settings before distributing new browser builds. |
179 | 88 |
|
180 | 89 | ## Documentation Guidelines |
181 | 90 | When updating the project's README, ensure all language versions are updated consistently: |
182 | 91 | - `README.md` (English) |
183 | 92 | - `README.zh.md` (Chinese) |
184 | 93 |
|
185 | | -## Common Patterns |
186 | | -- **API Controllers**: REST endpoints in `controller/` package |
187 | | -- **Service Layer**: Business logic in `service/` package |
188 | | -- **Repository Pattern**: JPA repositories with custom specifications in `huntly-jpa` |
189 | | -- **DTO Mapping**: MapStruct for entity-DTO conversion |
190 | | -- **Event-Driven**: Application events for decoupled processing |
191 | | -- **Streaming**: Server-Sent Events for real-time AI content processing |
192 | | - |
193 | 94 | ## UI Language Guidelines |
194 | | -All user interface text must be written in English. This applies to: |
195 | | -- Button labels, menu items, and tooltips |
196 | | -- Error messages and notifications |
197 | | -- Form labels and placeholder text |
198 | | -- Any user-facing strings in the browser extension, web client, and desktop app |
| 95 | +All user interface text must be written in English. This applies to button labels, menu items, tooltips, error messages, notifications, form labels, and any user-facing strings across all clients (browser extension, web client, desktop app). |
| 96 | + |
| 97 | +## Reply Guidelines |
| 98 | + |
| 99 | +使用与用户发送的消息相同的语言进行回复。 |
0 commit comments