|
| 1 | +# Obsidian Kanban Bases View Plugin - Copilot Instructions |
| 2 | + |
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +This is an **Obsidian plugin** that provides a **kanban board view** for Obsidian Bases (database functionality). The plugin integrates with Obsidian's Bases API to display data in a drag-and-drop kanban board layout with configurable grouping, virtual scrolling, and persistent column ordering. |
| 6 | + |
| 7 | +**Key Technologies:** |
| 8 | +- TypeScript (strict mode enabled) |
| 9 | +- React 19.2.0 with JSX |
| 10 | +- Vite for building |
| 11 | +- Vitest for testing |
| 12 | +- @dnd-kit for drag-and-drop |
| 13 | +- @tanstack/react-virtual for virtual scrolling |
| 14 | + |
| 15 | +## Build, Test, and Lint Commands |
| 16 | + |
| 17 | +### Package Manager |
| 18 | +**CRITICAL: Always use `pnpm` for package management, not npm.** The project uses pnpm workspaces and npm will timeout. |
| 19 | + |
| 20 | +### Installation |
| 21 | +```bash |
| 22 | +pnpm install --frozen-lockfile |
| 23 | +``` |
| 24 | + |
| 25 | +### Development |
| 26 | +```bash |
| 27 | +# Using mise (preferred for local development) |
| 28 | +mise run dev |
| 29 | + |
| 30 | +# Manual build with watch mode |
| 31 | +pnpm vite build --watch |
| 32 | +``` |
| 33 | + |
| 34 | +### Building |
| 35 | +```bash |
| 36 | +# Production build |
| 37 | +pnpm vite build --mode production |
| 38 | + |
| 39 | +# Development build |
| 40 | +pnpm vite build |
| 41 | +``` |
| 42 | + |
| 43 | +### Type Checking |
| 44 | +```bash |
| 45 | +tsc -noEmit |
| 46 | +``` |
| 47 | + |
| 48 | +### Testing |
| 49 | +```bash |
| 50 | +# Run all tests |
| 51 | +vitest run |
| 52 | + |
| 53 | +# Run tests in watch mode |
| 54 | +vitest watch |
| 55 | + |
| 56 | +# Run tests with coverage |
| 57 | +vitest run --coverage |
| 58 | + |
| 59 | +# Run specific test file |
| 60 | +vitest run src/__tests__/KanbanBoard.test.tsx |
| 61 | +``` |
| 62 | + |
| 63 | +### Linting |
| 64 | +```bash |
| 65 | +# Check for linting errors |
| 66 | +eslint src --ext .ts,.tsx |
| 67 | + |
| 68 | +# Auto-fix linting errors (if possible) |
| 69 | +eslint src --ext .ts,.tsx --fix |
| 70 | +``` |
| 71 | + |
| 72 | +### Full Check Suite |
| 73 | +```bash |
| 74 | +# Run all checks (typecheck, lint, test) |
| 75 | +mise run check |
| 76 | +``` |
| 77 | + |
| 78 | +Note: The `mise run check` command requires `VAULT_PATH` environment variable to be set to a valid Obsidian vault directory. |
| 79 | + |
| 80 | +## Project Structure |
| 81 | + |
| 82 | +``` |
| 83 | +obsidian-bases-kanban-view/ |
| 84 | +├── .github/ # GitHub workflows and configurations |
| 85 | +│ ├── workflows/ # CI/CD workflows (PR checks, releases) |
| 86 | +│ └── copilot-instructions.md # This file |
| 87 | +├── .mise/ # Mise task definitions |
| 88 | +│ └── tasks/ # Build automation scripts |
| 89 | +├── src/ |
| 90 | +│ ├── main.ts # Plugin entry point, registers with Obsidian Bases API |
| 91 | +│ ├── views/ |
| 92 | +│ │ └── KanbanBasesView.ts # Core kanban board (523 lines) - drag-drop, grouping, virtual scrolling |
| 93 | +│ ├── components/ # React components for kanban board UI |
| 94 | +│ ├── utils/ |
| 95 | +│ │ └── VirtualScroller.ts # Virtual scrolling implementation (99 lines) |
| 96 | +│ ├── context/ # React context providers |
| 97 | +│ ├── hooks/ # Custom React hooks |
| 98 | +│ ├── styles/ |
| 99 | +│ │ └── kanban.css # Card/column styling and drag-drop states (150+ lines) |
| 100 | +│ └── __tests__/ # Test files (vitest + testing-library) |
| 101 | +├── docs/ # Documentation |
| 102 | +├── manifest.json # Obsidian plugin manifest |
| 103 | +├── package.json # Dependencies and scripts |
| 104 | +├── tsconfig.json # TypeScript configuration (strict: true) |
| 105 | +├── vite.config.mjs # Vite build configuration |
| 106 | +├── vitest.config.mjs # Vitest test configuration |
| 107 | +└── AGENTS.md # Agent-specific development guidelines |
| 108 | +``` |
| 109 | + |
| 110 | +## Key Architecture |
| 111 | + |
| 112 | +### Plugin Entry Point |
| 113 | +- **`src/main.ts`**: Registers the plugin with Obsidian's Bases API, defines the custom view type |
| 114 | + |
| 115 | +### Core View |
| 116 | +- **`src/views/KanbanBasesView.ts`**: Main kanban board implementation |
| 117 | + - Manages data flow: `this.data.data` → grouped by `groupByPropertyId` → rendered |
| 118 | + - Handles drag-drop operations for cards and columns |
| 119 | + - Implements virtual scrolling for columns with 30+ items |
| 120 | + - Manual grouping (no API support yet) |
| 121 | + |
| 122 | +### Virtual Scrolling |
| 123 | +- **`src/utils/VirtualScroller.ts`**: Renders only visible cards in columns for performance |
| 124 | + - Uses @tanstack/react-virtual |
| 125 | + - Critical for handling 100+ items |
| 126 | + |
| 127 | +### Styling |
| 128 | +- **`src/styles/kanban.css`**: Card/column styling, drag-drop visual feedback |
| 129 | + |
| 130 | +### Data Flow |
| 131 | +``` |
| 132 | +Base data → KanbanBasesView → Grouped by property → Virtual Scroller → Rendered cards |
| 133 | +``` |
| 134 | + |
| 135 | +## Code Style & Conventions |
| 136 | + |
| 137 | +### TypeScript |
| 138 | +- **Strict mode enabled** (`strict: true` in tsconfig.json) |
| 139 | +- All functions **must have explicit return types** |
| 140 | +- Private methods use underscore prefix: `_methodName()` |
| 141 | +- No `any` types - use proper TypeScript types |
| 142 | +- Use `const` and `let` (never `var`) |
| 143 | + |
| 144 | +### Imports |
| 145 | +Organize imports in this order: |
| 146 | +1. Obsidian library imports |
| 147 | +2. Local utility imports |
| 148 | +3. CSS imports |
| 149 | + |
| 150 | +Always use **named imports**, not default imports. |
| 151 | + |
| 152 | +```typescript |
| 153 | +// Good |
| 154 | +import { Plugin, TFile } from 'obsidian'; |
| 155 | +import { VirtualScroller } from './utils/VirtualScroller'; |
| 156 | +import './styles/kanban.css'; |
| 157 | + |
| 158 | +// Bad |
| 159 | +import * as obsidian from 'obsidian'; |
| 160 | +``` |
| 161 | + |
| 162 | +### Formatting |
| 163 | +- **2-space indentation** (no tabs) |
| 164 | +- **Semicolons required** |
| 165 | +- **No trailing commas** |
| 166 | +- Use arrow functions for callbacks |
| 167 | + |
| 168 | +### Naming Conventions |
| 169 | +- **Classes**: PascalCase (e.g., `KanbanBasesView`) |
| 170 | +- **Methods/Properties**: camelCase (e.g., `updateColumnOrder`) |
| 171 | +- **Constants**: UPPER_SNAKE_CASE (e.g., `KANBAN_VIEW_TYPE`) |
| 172 | +- **Private methods**: underscore prefix (e.g., `_initializeView`) |
| 173 | + |
| 174 | +### Error Handling |
| 175 | +- Wrap data access in try-catch for localStorage/JSON parsing |
| 176 | +- Always check for null/undefined before accessing properties |
| 177 | +- Log errors with `[KanbanBasesView]` prefix for easy filtering |
| 178 | + |
| 179 | +```typescript |
| 180 | +try { |
| 181 | + const data = JSON.parse(localStorage.getItem('key')); |
| 182 | + if (data?.property) { |
| 183 | + // Safe to use |
| 184 | + } |
| 185 | +} catch (error) { |
| 186 | + console.error('[KanbanBasesView] Failed to parse data:', error); |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +### Logging |
| 191 | +- Use `console.debug()` for debugging information |
| 192 | +- Use `console.warn()` for warnings |
| 193 | +- Use `console.error()` for errors |
| 194 | +- Always prefix with `[KanbanBasesView]` for easy filtering |
| 195 | +- Log meaningful state during operations (see `src/views/KanbanBasesView.ts` lines 75-79 as reference) |
| 196 | + |
| 197 | +```typescript |
| 198 | +console.debug('[KanbanBasesView] Initializing with data:', this.data); |
| 199 | +console.warn('[KanbanBasesView] No grouping property found, using default'); |
| 200 | +console.error('[KanbanBasesView] Failed to update entry:', error); |
| 201 | +``` |
| 202 | + |
| 203 | +## Testing Guidelines |
| 204 | + |
| 205 | +### Test Framework |
| 206 | +- **Vitest** with happy-dom environment |
| 207 | +- **@testing-library/react** for component testing |
| 208 | +- Globals enabled (no need to import `describe`, `it`, `expect`) |
| 209 | + |
| 210 | +### Test Structure |
| 211 | +- Test files: `src/__tests__/**/*.test.ts` or `*.test.tsx` |
| 212 | +- Mock files: `src/__tests__/mocks/` |
| 213 | +- Setup: `src/__tests__/setup.ts` |
| 214 | + |
| 215 | +### Coverage Requirements |
| 216 | +- Lines: 80% |
| 217 | +- Functions: 80% |
| 218 | +- Branches: 80% |
| 219 | +- Statements: 80% |
| 220 | + |
| 221 | +### Writing Tests |
| 222 | +```typescript |
| 223 | +describe('ComponentName', () => { |
| 224 | + it('should do something specific', () => { |
| 225 | + // Arrange |
| 226 | + const props = { /* ... */ }; |
| 227 | + |
| 228 | + // Act |
| 229 | + const result = render(<Component {...props} />); |
| 230 | + |
| 231 | + // Assert |
| 232 | + expect(result.getByText('Expected Text')).toBeInTheDocument(); |
| 233 | + }); |
| 234 | +}); |
| 235 | +``` |
| 236 | + |
| 237 | +### Running Tests |
| 238 | +- Run all tests: `vitest run` |
| 239 | +- Watch mode: `vitest watch` |
| 240 | +- Specific file: `vitest run path/to/test.test.tsx` |
| 241 | +- Coverage: `vitest run --coverage` |
| 242 | + |
| 243 | +## Development Workflow |
| 244 | + |
| 245 | +### Initial Setup |
| 246 | +1. Clone repository |
| 247 | +2. Run `pnpm install --frozen-lockfile` |
| 248 | +3. For local development with Obsidian: |
| 249 | + - Run `mise run dev` (prompts for vault path on first run) |
| 250 | + - Vault path stored in `.notes/VAULT_PATH` (gitignored) |
| 251 | + |
| 252 | +### Making Changes |
| 253 | +1. Create a feature branch |
| 254 | +2. Make minimal, focused changes |
| 255 | +3. Run `tsc -noEmit` to check types |
| 256 | +4. Run `vitest run` to ensure tests pass |
| 257 | +5. Run `eslint src --ext .ts,.tsx` to check linting |
| 258 | +6. Build: `pnpm vite build` |
| 259 | + |
| 260 | +### Testing Changes in Obsidian |
| 261 | +1. Build with `pnpm vite build --watch` or `mise run dev` |
| 262 | +2. Changes are symlinked to vault's `.obsidian/plugins/` directory |
| 263 | +3. Reload Obsidian (Windows: Ctrl+R, Mac: Cmd+R, or use Command Palette → "Reload app") |
| 264 | +4. Filter console logs by `[KanbanBasesView]` to debug |
| 265 | + |
| 266 | +### CI/CD |
| 267 | +- PR checks run on every pull request |
| 268 | +- Checks include: TypeScript compilation, linting, tests |
| 269 | +- Release automation via release-please |
| 270 | + |
| 271 | +## Known Limitations and Context |
| 272 | + |
| 273 | +### Not Yet Implemented |
| 274 | +- Property updates from drag-drop not persisted (see `updateEntryProperty()` stub in `KanbanBasesView.ts`) |
| 275 | +- Swimlanes (2D grouping) |
| 276 | +- Filter integration |
| 277 | +- Create/edit items inline |
| 278 | +- Keyboard navigation |
| 279 | +- Custom card templates |
| 280 | +- Using a note as the template for rendering cards |
| 281 | + |
| 282 | +### Technical Debt |
| 283 | +- Grouping is manual (no API support from Obsidian Bases yet) |
| 284 | +- Virtual scrolling optimization for very large datasets (1000+ items) |
| 285 | + |
| 286 | +### Obsidian API Integration |
| 287 | +- Plugin uses Obsidian Bases API (still evolving) |
| 288 | +- View registration: `this.registerView(KANBAN_VIEW_TYPE, ...)` |
| 289 | +- Data access: `this.data.data` from base view |
| 290 | +- Property updates: Waiting for stable API |
| 291 | + |
| 292 | +### Performance Considerations |
| 293 | +- Virtual scrolling kicks in for columns with 30+ items |
| 294 | +- Drag-drop operations are optimized with React memoization |
| 295 | +- Re-rendering minimized with proper React hooks dependencies |
| 296 | + |
| 297 | +## Agent-Specific Notes |
| 298 | + |
| 299 | +For more detailed agent-specific guidelines, see `AGENTS.md` in the repository root. That file contains: |
| 300 | +- Command usage (mise tasks) |
| 301 | +- Vault configuration details |
| 302 | +- Debugging tips with DevTools |
| 303 | +- Context & notes workflow for persistent agent memory |
| 304 | + |
| 305 | +## Common Tasks |
| 306 | + |
| 307 | +### Adding a New Feature |
| 308 | +1. Read relevant code in `src/views/KanbanBasesView.ts` to understand data flow |
| 309 | +2. Create React components in `src/components/` |
| 310 | +3. Add tests in `src/__tests__/` |
| 311 | +4. Update styles in `src/styles/kanban.css` |
| 312 | +5. Run full check suite: `mise run check` |
| 313 | + |
| 314 | +### Fixing a Bug |
| 315 | +1. Filter console for `[KanbanBasesView]` to identify error location |
| 316 | +2. Write a failing test first |
| 317 | +3. Fix the bug with minimal changes |
| 318 | +4. Ensure test passes and no other tests break |
| 319 | +5. Run `mise run check` |
| 320 | + |
| 321 | +### Updating Dependencies |
| 322 | +1. Use `pnpm add <package>` or `pnpm add -D <package>` |
| 323 | +2. Test thoroughly after updates |
| 324 | +3. Update `pnpm-lock.yaml` by running `pnpm install` |
| 325 | +4. Verify build still works: `pnpm vite build` |
| 326 | + |
| 327 | +## External Resources |
| 328 | + |
| 329 | +- [Obsidian Plugin API](https://github.com/obsidianmd/obsidian-api) |
| 330 | +- [Obsidian Bases Documentation](https://docs.obsidian.md/Plugins/Bases) |
| 331 | +- [React DnD Kit Documentation](https://docs.dndkit.com/) |
| 332 | +- [TanStack Virtual Documentation](https://tanstack.com/virtual/latest) |
| 333 | + |
| 334 | +## Questions or Issues? |
| 335 | + |
| 336 | +- Check console logs filtered by `[KanbanBasesView]` |
| 337 | +- Review existing tests for examples |
| 338 | +- See `AGENTS.md` for agent-specific debugging tips |
| 339 | +- File issues with reproduction steps and console errors |
0 commit comments