Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
Write this description for human reviewers and delete the sections that do not apply.
Bug fixes and small changes don't need a ticket. New features and larger changes should follow a triaged ticket (label `1. to develop` or later); discuss them in the ticket before implementing them.
-->

## Context

<!-- Closes #1234 -->

## Approach

<!--
The code shows what changed. Explain why:
- Which approach did you take and why?
- Which alternatives did you consider and why did you discard them?
- What did you intentionally leave out?
-->

## Screenshots

<!-- Visual changes only. Include light and dark theme and mobile where relevant. Use the table with one before and one after image, or a single combined image that embeds both screenshots. -->

| Before | After |
| ------ | ----- |
| | |

## Testing

<!--
Describe how a reviewer can test this, if it differs from the steps to reproduce in the ticket.
State which manual tests you did, for example in a browser and with a CardDAV client.
If something is not tested manually, say so and why.
-->

## AI assistance

<!-- Disclose AI tool use, e.g. "Assisted by ClaudeCode:claude-sonnet-5-5", or state "None". -->
2 changes: 2 additions & 0 deletions .github/pull_request_template.md.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
SPDX-License-Identifier: AGPL-3.0-or-later
157 changes: 157 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,137 @@ Single-page Vue 3 app with Vite bundling. Entry point: `main.js`, root component
*/
```

### Code comments

The diff shows *what* changed and *how*; a comment exists only to capture *why* — intent the code and names can't convey on their own.

- **Default to none.** Most changes need zero comments; express intent through clear names and small functions.
- **Comment the *why*, never the *how*.** Legitimate reasons: a non-obvious workaround (link the issue/ticket), a subtle business rule, a deliberate deviation from the expected. Never narrate what the next lines do.
- **No multi-line explanatory blocks, AI-style walkthroughs, or section banners.**
- **Remove a stale comment** only when you're already editing that code for the task at hand — no drive-by cleanups.

## Coding conventions

These are the points maintainers raise again and again in review. Following them up
front keeps review focused on design instead of the same recurring notes. CodeRabbit reads this file automatically and reviews against these conventions, so the bot flags
the same things — but the author should not need the bot to learn them.

### Scope & commits
- **One concern per PR.** Keep unrelated edits, drive-by refactors, code-style churn,
dependency/lock-file bumps and new runtime-version support out of a feature PR — put
them in a separate PR so they stay backportable to stable branches. Small,
single-purpose PRs sail through; large diffs draw change requests.
- **The commit type must match the change:** moving code with no behavior change is
`refactor:`, not `feat:`. Scopes stay broad (`teams`, `ui`).
- **Reuse before reinventing.** Grep for an existing helper, mapper, constant or pattern
and mirror it instead of writing a parallel implementation.

### PHP backend
- **Types over PHPDoc.** Prefer native param/return/property types; drop PHPDoc that only
restates them; keep `@throws` and anything that adds information. Use precise
`psalm-type` array shapes (reuse existing shape definitions) instead of bare `array`.
Handle Psalm's possible-null and
`string|false` (e.g. `file_get_contents`) results — throw a domain exception, don't
cast the failure away. Use constructor property promotion and strict comparison
(`===`, `in_array(..., true)`).
- **Exceptions.** Catch narrowly — never a blanket `\Exception`/`\Throwable` for a
specific failure. When wrapping, pass the original as `$previous` (or rethrow) so the
stack trace survives. Throw domain exceptions; don't leak abstraction-layer exceptions
(`DoesNotExistException`, storage exceptions) out of a service. Keep `@throws` in sync
with the interface contract.
- **Logging.** Inject `LoggerInterface`; log with a meaningful message and
`['exception' => $e]` context at the right level. Log non-critical conditions at
info/debug and return rather than throwing or spamming warnings. Never swallow errors.
- **Dependency injection & layering.** Inject collaborators (incl. OCP services) via the
constructor, not the service locator. Replace `time()` with `ITimeFactory` for
testability. Don't inject request data such as `userId` into services (controllers
only) — pass it as an argument so the service stays usable from background jobs. Keep
controllers thin (request/response only); business logic and DB access belong in
services; keep constants in their owning class.
- **Nextcloud API boundaries.** Never use another app's private `\OCA\OtherApp\*` API — go
through a stable OCP interface. Respect the minimum server version in `appinfo/info.xml`;
guard newer OCP APIs with `method_exists` + a fallback. Store new config via
`IAppConfig` (no dots in new keys). Controllers use `#[NoAdminRequired]` for non-admin
routes (omit it on admin-only ones), HTTP 422 for validation errors and `Http::STATUS_*`
constants. Keep 400 (client error) vs 404 (not found) intentional. Prefer kebab-case
URLs with the id in the path and a single `resource` route.
- **Controller access control.** Check that the current user owns the resource before
acting on an incoming id — guard against IDOR, don't act on a guessed id. Take a nullable
`?string $userId` from the predefined core services and return 401 when it is null.

### Mappers & entities
- **Build every query with `IQueryBuilder`, never with raw SQL strings.** Use `expr()` for
conditions, `func()` for SQL functions and `createNamedParameter()` for values — the
builder handles quoting, table prefixes and dialect differences (Oracle, Postgres,
SQLite). Don't pass hand-written SQL to `IDBConnection`, and don't concatenate
keywords, operators or fragments into `createFunction()`. The one accepted use of
`createFunction()` is embedding a builder-generated subquery:
`$qb->expr()->in('col', $qb->createFunction($sub->getSQL()))`.
- Let mappers propagate `DoesNotExistException` / `OCP\DB\Exception` to the caller — don't
catch not-found inside the mapper. Reuse the `QBMapper` `insert`/`update`/`find` helpers
instead of hand-writing queries.
- Name accessors `findX`/`getX` (not `store`); keep entity `@method` annotations accurate,
including `int|null` for nullable columns; register column types with `addType` in the
constructor.

### Database & migrations
- **Re-runnable:** check column/table existence before changing schema so a partially
failed migration can retry.
- **Version naming:** name the `Version` class after the *next unreleased* minor and bump
`version` in `appinfo/info.xml`, or the migration won't run.
- **Foreign keys** on referencing columns, with the delete action chosen from the
relationship: cascade delete for rows the parent owns (so deleting the parent leaves
no orphans), `SET NULL` for an optional reference, `RESTRICT` to prevent deletion. Clean up
dangling rows pre-schema.
- **Indexes:** composite column order matters (`[a,b]` ≠ `[b,a]`) — match the query's
WHERE/ORDER BY; add covering indexes on exactly the filtered/joined columns; make the
index unique when the column is.
- **Portability & size:** sensible column lengths (avoid MariaDB off-row storage), truncate
before writing fixed-width columns, Oracle needs nullable booleans and treats empty
strings as `NULL`, Postgres/Oracle are strict about VARCHAR-vs-INT. Batch huge
UPDATE/DELETE and emit progress. Inline entity constants in migrations (a loaded class
can hold stale values mid-upgrade).

### Performance
- Push filters/limits/cursors into the DB query; scope by `user_id`; use `WHERE ... IN`
to avoid N+1; don't `array_merge` in a loop. Stream large result sets via generators
and guard against OOM — users can have address books with thousands of contacts. Prefer a local cache over a
distributed one for recomputable values and scope cache keys per user.

### Frontend (Vue / JS)
- **Async:** `async`/`await` with `try`/`catch`, never mixed with `.then`; never `await`
inside `forEach` (use `for...of`); a missing `await` is a real bug. Await sequential
per-item dispatches instead of flooding the backend, and don't fire one request per
list item — push it to the backend or preload via initial state.
- **Structure:** HTTP and CardDAV handling in the service layer, mutations inside store
actions, business logic out of components. Add a loading/disabled state to any control
that triggers an async action so a double click can't fire it twice. Don't make an
element look clickable when its action is unavailable.
- **Style of code:** early returns over nested conditions, named constants over magic
numbers, `const`/`let` never `var`, pure helpers free of side effects and store access.
Sanitize user-controlled values before they reach the DOM. Use `isDarkTheme` from
`@nextcloud/vue`, not `window.matchMedia('(prefers-color-scheme: dark)')`. Follow the
dev-manual naming the linter can't check: multi-word PascalCase component names
(`SettingsView`, not `Settings`), prefixed sub-components, and acronyms with only the
first letter capitalised (`callHttpApi`).
- **CSS:** see [Styling](#styling); keep styles scoped, follow BEM, prefer a modifier class
over manipulating inline style, use grid/spacing/breakpoint CSS variables (no hard-coded
breakpoints), and remove now-unused styles. Avoid `::v-deep`/`!important` into upstream
component internals; where a deep selector is genuinely needed, comment why so it isn't
dropped by mistake.

### Internationalization
- Wrap every user-facing string, **including aria-labels**, in `t('contacts', …)`. Use one
string with placeholders — never concatenate translated fragments (translators reorder
words). Use `n('contacts', …)` with a `%n` placeholder for counts. Never compare against a
hard-coded English string or use a translated string as a key. No HTML inside a
translation string — translate the plain parts and HTML-encode the inserts.

### Accessibility
- Real anchor (`<a href … target="_blank">`) for links, not a JS click handler, so screen
readers and native middle-click work. Use semantically correct elements and let
`NcButton` inject the required a11y attributes rather than hand-rolling clickable markup.

## Testing

### Unit Tests
Expand Down Expand Up @@ -108,8 +239,18 @@ npm run test:e2e:ui # Run E2E tests with UI

## Git Workflow

### Ticket readiness

Bug fixes and small changes can go straight to a PR without opening a new ticket; still search for an existing ticket and reference it in the PR (e.g. `Closes #1234`) if there is one. New features and larger changes (touching several subsystems, needing an architectural decision, or without a clear approach yet) need a ticket that is ready to be picked up. Confirm this before starting implementation:
- A ticket still labeled `0. Needs triage` is **not** ready — it has not been accepted by a maintainer, and the approach (or whether the change is wanted at all) has not been discussed yet. Do not start coding from it.
- Only `1. to develop` (or a later pipeline label) signals the ticket has been triaged and discussed. That discussion must happen **before** the PR is opened, not in review after the fact.
- If no ticket exists, or it is still `0. Needs triage`, stop and tell the contributor to get it triaged and discussed first rather than starting an agent-driven implementation.
- If a bug fix turns out to need a larger change, stop and treat it as one.

Do NOT commit changes unless explicitly asked to do so.

Never fully automate the resolution of issues labeled [`good first issue`](https://github.com/issues?q=org%3Anextcloud+label%3A%22good+first+issue%22) or similar beginner-friendly labels.

After completing code changes:
1. Verify your work is complete and tests pass. Validate every change to runtime behavior on a live Nextcloud instance where you can, and give the contributor concrete steps to test it there themselves — your testing supports theirs, it does not replace it.
2. Never push directly to `main` — always create a feature branch with a descriptive name (e.g. `feat/org-chart`, `fix/vcard-parsing`, `chore/update-agents`).
Expand Down Expand Up @@ -165,6 +306,22 @@ Assisted-by: ClaudeCode:claude-sonnet-5-5
Signed-off-by: Name <email>
```

### Official documentation (user_manual / admin_manual)

Admin- and user-facing documentation for this app lives in the separate
[`nextcloud/documentation`](https://github.com/nextcloud/documentation) repository
(`admin_manual/groupware/contacts.rst`, `user_manual/groupware/contacts.rst`) — not in this
repository.

Not every change needs a doc update — a lot of small fixes and internal changes don't
touch anything a user or admin would need explained. But a change substantial enough to
need one (a new integration, a new settings area, a new concept the user has to learn)
should get it written right away, alongside the feature PR, not deferred to "later":
open a draft pull request in `nextcloud/documentation` with the
`admin_manual`/`user_manual` change. Keep it in draft and don't merge it until the
feature PR itself has merged — the feature can still change shape during review, and
docs merged early drift out of sync with what actually ships.

### Styling

For all CSS colors, spacing, and dimensions, you must use the standard Nextcloud CSS variables.
Expand Down
Loading