# Copilot Instructions for Opendesk ## Skills For Frappe development tasks, reference the frappe-dev skill: - **Location**: `~/.agents/skills/frappe-dev/` - **Usage**: When working on DocType, controllers, whitelisted APIs, background jobs, permissions, or frontend tasks, read the relevant skill reference files: - `doctype.md` — Creating/modifying DocTypes and fields - `controllers.md` — Document lifecycle and server logic - `api.md` — REST endpoints with `@frappe.whitelist()` - `database.md` — `frappe.db`, queries, raw SQL - `background-jobs.md` — `frappe.enqueue`, scheduled jobs - `permissions.md` — Roles, DocType permissions - `frontend-desk.md`, `frontend-vue.md`, `frontend-portal.md` — Frontend references ## Project Overview Opendesk is an open-source ticket management tool built on the [Frappe Framework](https://github.com/frappe/frappe) (Python backend) and [Frappe UI](https://github.com/frappe/frappe-ui) (Vue.js frontend). It provides agent/customer portals, SLAs, assignment rules, a knowledge base, and saved replies. ## Tech Stack & Architecture - **Backend**: Frappe Framework with Python - **Frontend**: Vue 3 + TypeScript SPA with Vite dev server - **Database**: MariaDB with structured doctypes - **Real-time**: WebSockets via Socket.IO for live updates - **UI Library**: frappe-ui for consistent design components - **Styling**: Tailwind CSS with semantic design tokens ## Architecture - **Backend (Python):** Located in `opendesk/`. - API endpoints: `opendesk/api/` - Business logic: `opendesk/utils.py`, `opendesk/search.py`, etc. - Extensibility: `opendesk/extends/`, `opendesk/overrides/` - **Frontend (Vue.js):** Located in `desk/`. - Main entry: `desk/src/main.js`, `desk/src/App.vue` - Components: `desk/src/components/` - State: `desk/src/stores/` - Routing: `desk/src/router/` - Styles: Tailwind via `desk/index.css`, config in `desk/tailwind.config.js` - **Customer portal and knowledge base (Studio app):** Located in `studio/opendesk/`, served at `/help`. Read `studio/README.md` and `studio/KNOWLEDGE_BASE.md` before working on them. - **Shared frontend code:** `shared/src`, imported as `@opendesk/shared` by the desk and the portal. # Frontend: Vue 3 Development Standards ## Frontend Project Context - `desk/src/` contains the main Vue 3 frontend source code - Vue 3.x with Composition API as default approach - TypeScript for type safety and better development experience - Single File Components (`.vue`) with ` ``` ## Key Files & Directories ### Backend - `opendesk/api/` — Backend API endpoints with @frappe.whitelist() decorators - `opendesk/utils.py` — Shared backend utilities and helper functions - `opendesk/hooks.py` — Frappe hooks - `opendesk/overrides/` — Custom logic and extensions ### Frontend - `desk/src/` — Main Vue 3 frontend source code - `desk/src/components/` — Reusable Vue components - `desk/src/pages/` — Page-level components and routes - `desk/src/stores/` — Pinia stores for state management - `desk/tailwind.config.js` — Tailwind CSS configuration with semantic tokens - `desk/components.d.ts` — Auto-generated component type definitions ### Development - `docker/` — Docker setup for containerized development ## Code Quality & Standards - Follow Vue's official style guide and best practices - Use ESLint with Vue 3 recommended rules and Prettier for consistency - Write meaningful commit messages and maintain clean git history - Document complex logic with JSDoc/TSDoc comments - Keep a comment to 2 lines at most. If it needs more to explain, simplify the code instead - Keep dependencies updated and audit for security vulnerabilities ## References - [README.md](../README.md) — Full setup and feature list - [Frappe Docs](https://frappeframework.com/docs/) — Framework documentation - [Opendesk Docs](https://github.com/ikhsanddy/opendesk) — Project-specific docs - [Vue 3 Style Guide](https://vuejs.org/style-guide/) — Vue.js best practices - [Tailwind CSS](https://tailwindcss.com/docs) — Utility-first CSS framework --- ## Agent Working Rules These rules apply to all agents working in this codebase. Follow them without exception. ### 1. Site Data — Read Before You Write When a Frappe site is referenced in the conversation (e.g. `erp-od.localhost`, `od-tests`), treat it as the **source of truth for current data state**. - Before assuming anything about existing records, custom fields, settings, or DocType state — query the site first using the bench venv Python or `bench execute`. - **Never write data to a site unless the user explicitly asks you to.** Querying is always safe. Mutations (insert, update, delete, migrate, patch) require explicit user instruction. - If you need to verify a fix worked, re-query the site — do not assume success from code inspection alone. ```python # Safe pattern for querying a site import sys, os sys.path.insert(0, 'apps/frappe') os.chdir('sites') import frappe frappe.init(site='', sites_path='.') frappe.connect() # ... read-only queries here ... frappe.destroy() ``` Run via: `cd /path/to/frappe-bench && env/bin/python /tmp/your_script.py` --- ### 2. Spec-Driven Development — Keep the Spec Current When a feature has a spec document (e.g. `docs/erpnext-customer-sync.md`), the spec is the **living source of truth** for that feature. It must be kept in sync with the actual implementation at all times. **Rules:** - **Update the spec in the same session as the code change.** Never defer spec updates to a later session. - **The spec reflects what is implemented, not what was originally planned.** If a decision changes mid-build (e.g. removing a scheduler job, changing how a field is set), update the spec immediately after the code change. - **Removed features must be removed from the spec.** Do not leave stale sections, blockers, or file manifest entries for things that no longer exist. - **New features must be added to the spec.** If a new API, component, or behaviour is introduced, add a corresponding section. - **Decisions and their rationale belong in the spec.** If something was done a specific way to avoid a bug or framework limitation (e.g. not setting `customer_group` to avoid the group-node error), document that in the relevant Blocker section. - When in doubt about whether a spec update is needed — update it. --- ### 3. Test Utilities — Always Use `opendesk/test_utils.py` All backend test helpers must live in `opendesk/test_utils.py` and be imported from there. Never define helper functions (factories, enable/disable toggles, fixture builders) directly inside individual test files. **Rules:** - **Before writing a helper in a test file**, check `opendesk/test_utils.py` first — it may already exist. - **If a helper doesn't exist**, add it to `opendesk/test_utils.py` and import it in the test file. Do not leave it inline. - **If you write helpers inline during development**, move them to `test_utils.py` before finishing the task. - Helper functions in `test_utils.py` must have a docstring explaining what they create or do. Only if the function is completely self-explanatory (e.g. `enable_erpnext_sync`) can the docstring be omitted. - Naming conventions: - Factories: `make_(...)` — e.g. `make_od_customer`, `make_ticket`, `make_team` - Toggle helpers: `enable_()` / `disable_()` — e.g. `enable_erpnext_sync` - Query helpers: descriptive verb — e.g. `get_latest_ticket_communication` **For updates, merge new conventions here. If anything is unclear or missing, ask for clarification.** **In the end your code will be reviewed by Codex, but following these rules will help ensure a smooth review process and a high-quality codebase.**