|
| 1 | +# Copilot Instructions for Learningmap |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Learningmap is an open-source tool for creating, sharing, and exploring learning pathways. It's a monorepo built with React, TypeScript, and pnpm workspaces. |
| 6 | + |
| 7 | +- **Website**: https://learningmap.app |
| 8 | +- **Documentation**: https://learningmap.openpatch.org |
| 9 | +- **Repository**: https://github.com/openpatch/learningmap |
| 10 | +- **Maintainer**: Mike Barkmin (@mikebarkmin) |
| 11 | + |
| 12 | +## Repository Structure |
| 13 | + |
| 14 | +This is a **pnpm monorepo** with multiple packages and platforms: |
| 15 | + |
| 16 | +``` |
| 17 | +learningmap/ |
| 18 | +├── packages/ |
| 19 | +│ ├── learningmap/ # Core React component library |
| 20 | +│ └── web-component/ # Web component wrapper |
| 21 | +├── platforms/ |
| 22 | +│ └── web/ # Web application (learningmap.app) |
| 23 | +├── docs/ # Documentation (Hyperbook) |
| 24 | +└── scripts/ # Build and development scripts |
| 25 | +``` |
| 26 | + |
| 27 | +## Tech Stack |
| 28 | + |
| 29 | +- **Language**: TypeScript |
| 30 | +- **UI Framework**: React 19 |
| 31 | +- **Package Manager**: pnpm (required - version >= 8) |
| 32 | +- **Build Tool**: Vite + esbuild |
| 33 | +- **Visual Editor**: ReactFlow (@xyflow/react) |
| 34 | +- **Layout Engine**: ELK.js for auto-layout |
| 35 | +- **Testing**: Vitest |
| 36 | +- **Documentation**: Hyperbook |
| 37 | +- **Version Management**: Changesets |
| 38 | +- **Code Quality**: Prettier, Husky |
| 39 | + |
| 40 | +## Development Workflow |
| 41 | + |
| 42 | +### Installation and Setup |
| 43 | + |
| 44 | +```bash |
| 45 | +pnpm install # Install all dependencies |
| 46 | +pnpm build # Build all packages |
| 47 | +pnpm test # Run tests across all packages |
| 48 | +pnpm lint # Type-check with TypeScript |
| 49 | +pnpm docs:dev # Start documentation dev server |
| 50 | +pnpm dev # Watch mode for development |
| 51 | +``` |
| 52 | + |
| 53 | +### Making Changes |
| 54 | + |
| 55 | +1. **Always use pnpm** - The project enforces pnpm usage via preinstall hook |
| 56 | +2. **Build before testing** - Packages depend on each other's built artifacts |
| 57 | +3. **Use Changesets** - For version management and changelog generation |
| 58 | +4. **Follow existing patterns** - Match code style and structure of existing files |
| 59 | + |
| 60 | +### Package Scripts |
| 61 | + |
| 62 | +Each package has its own scripts defined in its `package.json`: |
| 63 | +- `build`: Compiles TypeScript and bundles with esbuild |
| 64 | +- `lint`: Type-checks with TypeScript (tsc --noEmit) |
| 65 | +- `test`: Runs tests with Vitest |
| 66 | + |
| 67 | +## Code Style and Conventions |
| 68 | + |
| 69 | +### TypeScript |
| 70 | + |
| 71 | +- Use strict TypeScript with proper type definitions |
| 72 | +- Prefer interfaces for props and types for unions/intersections |
| 73 | +- Export types alongside components |
| 74 | +- No implicit `any` - always define types |
| 75 | + |
| 76 | +### React Components |
| 77 | + |
| 78 | +- Use functional components with hooks |
| 79 | +- Prefer named exports for components |
| 80 | +- Use TypeScript interfaces for component props |
| 81 | +- Follow existing patterns for event handlers (e.g., `on` prefix) |
| 82 | +- Keep components focused and modular |
| 83 | + |
| 84 | +### File Organization |
| 85 | + |
| 86 | +- Components in PascalCase (e.g., `EditorToolbar.tsx`) |
| 87 | +- Utilities and helpers in camelCase (e.g., `helper.ts`, `translations.ts`) |
| 88 | +- Index files export public API |
| 89 | +- Keep related code together |
| 90 | + |
| 91 | +### Translations |
| 92 | + |
| 93 | +The project supports internationalization (i18n): |
| 94 | +- Translations are defined in `packages/learningmap/src/translations.ts` |
| 95 | +- Use the `getTranslations(language)` helper |
| 96 | +- Default language is English (`en`), German (`de`) is also supported |
| 97 | +- Always add translations for both languages when adding new strings |
| 98 | + |
| 99 | +## Common Tasks |
| 100 | + |
| 101 | +### Adding a New Feature |
| 102 | + |
| 103 | +1. Implement the feature in the appropriate package |
| 104 | +2. Add TypeScript types for all new props/interfaces |
| 105 | +3. Update translations if adding user-facing text |
| 106 | +4. Consider both editor and viewer modes |
| 107 | +5. Test in both debug and preview modes |
| 108 | +6. Update documentation if it's a public API change |
| 109 | + |
| 110 | +### Working with the Editor |
| 111 | + |
| 112 | +The core editor (`LearningMapEditor`) has two modes: |
| 113 | +- **Edit Mode**: Full editing capabilities with toolbar |
| 114 | +- **Preview Mode**: View-only mode for testing the learner experience |
| 115 | + |
| 116 | +Key components: |
| 117 | +- `EditorToolbar`: Main menu and controls |
| 118 | +- `EditorDrawer`: Side panel for node/edge editing |
| 119 | +- Node types: `TopicNode`, `TaskNode`, `TextNode`, `ImageNode` |
| 120 | +- Edge types: Regular edges, completion edges, unlock edges |
| 121 | + |
| 122 | +### Styling |
| 123 | + |
| 124 | +- CSS is bundled with components |
| 125 | +- Use existing CSS classes and patterns |
| 126 | +- Follow the visual design of existing components |
| 127 | +- Test in both light and dark modes (if applicable) |
| 128 | + |
| 129 | +## Testing |
| 130 | + |
| 131 | +- Tests are run with Vitest |
| 132 | +- Test files should be placed alongside source files |
| 133 | +- Currently minimal test coverage - focus on core functionality |
| 134 | +- Run tests with `pnpm test` before submitting PRs |
| 135 | + |
| 136 | +## Documentation |
| 137 | + |
| 138 | +Documentation is built with Hyperbook and located in the `docs/` directory: |
| 139 | +- `docs/book/index.md`: Main documentation entry |
| 140 | +- `docs/book/development.md`: Development guide |
| 141 | +- `docs/book/contributing.md`: Contribution guidelines |
| 142 | +- Update docs when adding features that affect the public API |
| 143 | + |
| 144 | +## CI/CD |
| 145 | + |
| 146 | +GitHub Actions workflows: |
| 147 | +- `pull-request.yml`: Runs tests and build on PRs |
| 148 | +- `changeset-version.yml`: Manages version bumps and releases |
| 149 | +- `docs.yml`: Deploys documentation |
| 150 | + |
| 151 | +All PRs must pass: |
| 152 | +1. TypeScript type checking (`pnpm lint`) |
| 153 | +2. Tests (`pnpm test`) |
| 154 | +3. Build (`pnpm build`) |
| 155 | + |
| 156 | +## Important Notes |
| 157 | + |
| 158 | +- **No force pushes** - Git force push is disabled |
| 159 | +- **No rebase** - Use merge commits for combining branches |
| 160 | +- **Minimal changes** - Make the smallest possible changes to achieve goals |
| 161 | +- **Preserve working code** - Don't remove or modify working code unless necessary |
| 162 | +- **Follow existing patterns** - Match the style and structure of existing code |
| 163 | +- **Use ecosystem tools** - Prefer pnpm scripts and package tools over manual changes |
| 164 | + |
| 165 | +## Dependencies |
| 166 | + |
| 167 | +When adding new dependencies: |
| 168 | +- Add to the appropriate package's `package.json` |
| 169 | +- Use `pnpm add <package>` in the package directory |
| 170 | +- Consider bundle size impact for the web component |
| 171 | +- Prefer peer dependencies for React and related packages |
| 172 | + |
| 173 | +## Common Pitfalls |
| 174 | + |
| 175 | +- ❌ Don't use `npm` or `yarn` - always use `pnpm` |
| 176 | +- ❌ Don't commit built artifacts (`dist/` folders) |
| 177 | +- ❌ Don't modify `node_modules` or `pnpm-lock.yaml` manually |
| 178 | +- ❌ Don't skip the build step - packages depend on each other |
| 179 | +- ❌ Don't add tests that don't exist - follow existing test patterns |
| 180 | +- ✅ Do run `pnpm install` after pulling changes |
| 181 | +- ✅ Do run `pnpm build` before running tests |
| 182 | +- ✅ Do commit your changes using the Changesets workflow |
| 183 | +- ✅ Do test in both editor and preview modes |
| 184 | + |
| 185 | +## Getting Help |
| 186 | + |
| 187 | +- **Issues**: Open an issue on GitHub for bugs or feature requests |
| 188 | +- **Community**: Join the Matrix community at https://matrix.to/#/#openpatch:matrix.org |
| 189 | +- **Contact **: Reach out to [email protected] for support |
| 190 | + |
| 191 | +## License |
| 192 | + |
| 193 | +MIT License - maintained by OpenPatch (https://openpatch.org) |
0 commit comments