|
| 1 | +# Open Source Bazaar - GitHub Copilot Instructions |
| 2 | + |
| 3 | +Open Source Bazaar is an open-source project showcase platform built with Next.js 15, TypeScript, React Bootstrap, and MobX. It includes license filters, Wiki knowledge base, volunteer showcase, Lark integration, and other features. |
| 4 | + |
| 5 | +Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. |
| 6 | + |
| 7 | +## Critical Requirements |
| 8 | + |
| 9 | +⚠️ **MANDATORY NODE.JS VERSION**: This project requires **Node.js >=20**. The build works on Node.js 20+ but may have warnings. |
| 10 | + |
| 11 | +- Check Node.js version: `node --version` |
| 12 | +- Development and linting commands work on Node.js 20+ |
| 13 | +- Use **PNPM** as package manager, not NPM or Yarn |
| 14 | + |
| 15 | +## Working Effectively |
| 16 | + |
| 17 | +### Initial Setup (REQUIRED for all development) |
| 18 | + |
| 19 | +1. **Install global pnpm**: `npm install -g pnpm` |
| 20 | +2. **Install dependencies**: `pnpm install` -- takes 1-3 minutes. NEVER CANCEL. Set timeout to 5+ minutes. |
| 21 | +3. **Verify setup**: `pnpm --version` (should be 10.x+) |
| 22 | + |
| 23 | +**Important**: If you see "node_modules missing" error, you MUST run `pnpm install` first before any other commands. |
| 24 | + |
| 25 | +### Development Workflow (FULLY VALIDATED) |
| 26 | + |
| 27 | +- **Start development server**: `pnpm dev` -- starts in 5-15 seconds on http://localhost:3000 |
| 28 | +- **Run linting**: `pnpm lint` -- takes 15 seconds. NEVER CANCEL. Set timeout to 2+ minutes. |
| 29 | +- **Run tests**: `pnpm test` -- runs lint-staged + lint, takes 15 seconds. Set timeout to 2+ minutes. |
| 30 | + |
| 31 | +### Build Process |
| 32 | + |
| 33 | +- **Production build**: `pnpm build` -- works on Node.js 20+ (estimated 30s-2 minutes) |
| 34 | + - NEVER CANCEL. Set timeout to 5+ minutes. |
| 35 | +- **Static export**: Available but not commonly used in development |
| 36 | + |
| 37 | +## Validation Scenarios |
| 38 | + |
| 39 | +After making ANY changes, ALWAYS validate by running through these scenarios: |
| 40 | + |
| 41 | +### Manual Testing Requirements |
| 42 | + |
| 43 | +1. **Start development server**: `pnpm dev` and verify it starts without errors |
| 44 | +2. **Navigate to homepage**: Visit http://localhost:3000 and verify page loads with navigation menu |
| 45 | +3. **Test core pages**: |
| 46 | + - License filter: http://localhost:3000/license-filter (interactive license selection tool) |
| 47 | + - Wiki pages: http://localhost:3000/wiki (policy documents from GitHub) |
| 48 | + - Volunteer page: http://localhost:3000/volunteer (contributor showcase) |
| 49 | + - Projects: http://localhost:3000/project (GitHub repository listings) |
| 50 | +4. **Test API endpoints**: Verify GitHub API integrations work |
| 51 | +5. **Check responsive design**: Test mobile/desktop layouts with React Bootstrap components |
| 52 | +6. **Verify i18n functionality**: Check Chinese/English language switching works |
| 53 | + |
| 54 | +### Pre-commit Validation |
| 55 | + |
| 56 | +ALWAYS run before committing changes: |
| 57 | + |
| 58 | +```bash |
| 59 | +npm test # Runs linting + staged file checks |
| 60 | +``` |
| 61 | + |
| 62 | +## Key Project Structure |
| 63 | + |
| 64 | +### Important Directories |
| 65 | + |
| 66 | +- `pages/` - Next.js pages and API routes |
| 67 | +- `components/` - Reusable React components with Bootstrap styling |
| 68 | +- `models/` - MobX stores and data models |
| 69 | +- `translation/` - i18n language files (zh-CN, en-US, zh-TW) |
| 70 | +- `styles/` - CSS and styling files |
| 71 | +- `public/` - Static assets |
| 72 | + |
| 73 | +### Configuration Files |
| 74 | + |
| 75 | +- `package.json` - Dependencies and scripts |
| 76 | +- `next.config.ts` - Next.js configuration with MDX support |
| 77 | +- `tsconfig.json` - TypeScript configuration |
| 78 | +- `eslint.config.ts` - ESLint configuration |
| 79 | +- `babel.config.js` - Babel configuration |
| 80 | + |
| 81 | +### Key Dependencies |
| 82 | + |
| 83 | +- **Next.js 15** - React framework |
| 84 | +- **React Bootstrap 2.10** - UI component library |
| 85 | +- **MobX 6.13** - State management |
| 86 | +- **MobX-GitHub 0.4** - GitHub API integration |
| 87 | +- **MobX-i18n 0.7** - Internationalization |
| 88 | +- **License-Filter 0.2** - License filtering functionality |
| 89 | +- **Marked 16.2** - Markdown processing |
| 90 | + |
| 91 | +## Development Standards and Best Practices |
| 92 | + |
| 93 | +Based on comprehensive PR review analysis, follow these critical development standards: |
| 94 | + |
| 95 | +### Architecture and Code Organization |
| 96 | + |
| 97 | +#### Component and Import Standards |
| 98 | + |
| 99 | +- **ALWAYS use React Bootstrap components** instead of custom HTML elements |
| 100 | +- Use utilities from established libraries: 'web-utility' |
| 101 | +- Import `'./Base'` in model files for proper configuration |
| 102 | + |
| 103 | +#### Error Handling and Static Generation |
| 104 | + |
| 105 | +- **Natural error throwing** for static generation - let errors bubble up to catch build issues |
| 106 | +- Ensure build passes before pushing - resolve issues at compile time |
| 107 | + |
| 108 | +### UI/UX Standards |
| 109 | + |
| 110 | +#### Component Usage Patterns |
| 111 | + |
| 112 | +```typescript |
| 113 | +// ✅ Correct - use React Bootstrap components |
| 114 | +import { Button, Badge, Breadcrumb, Card, Container } from 'react-bootstrap'; |
| 115 | + |
| 116 | +<Button variant="outline-primary" size="sm" href={url} target="_blank"> |
| 117 | + {t('edit_on_github')} |
| 118 | +</Button> |
| 119 | + |
| 120 | +<Badge bg="secondary">{label}</Badge> |
| 121 | + |
| 122 | +// ❌ Wrong - custom HTML elements |
| 123 | +<a href={url} className="btn btn-outline-primary">Edit</a> |
| 124 | +<span className="badge bg-secondary">{label}</span> |
| 125 | +``` |
| 126 | + |
| 127 | +#### Semantic HTML Structure |
| 128 | + |
| 129 | +- Use ordered lists (`<ol>`) for countable items, unordered lists (`<ul>`) for navigation |
| 130 | +- Apply proper semantic structure: `<article>`, `<header>`, `<section>` |
| 131 | +- Use `list-unstyled` class for first-level lists to remove default styling |
| 132 | + |
| 133 | +### Code Quality Standards |
| 134 | + |
| 135 | +#### Modern ECMAScript Features |
| 136 | + |
| 137 | +- Use optional chaining and modern JavaScript features |
| 138 | +- Let TypeScript infer types when possible to avoid verbose annotations |
| 139 | +- Use modern ECMAScript patterns for cleaner, more maintainable code |
| 140 | + |
| 141 | +#### Import and Type Management |
| 142 | + |
| 143 | +- Import from established sources: ContentModel from mobx-github, utilities from web-utility |
| 144 | +- Import configuration files where needed: `'./Base'` for GitHub client setup |
| 145 | +- Use minimal exports and avoid unnecessary custom implementations |
| 146 | +- Use configured clients rather than creating new ones |
| 147 | + |
| 148 | +### Translation and Internationalization |
| 149 | + |
| 150 | +#### Critical Translation Requirements |
| 151 | + |
| 152 | +- **ALL user-facing text** MUST be translated using i18n system |
| 153 | +- This includes button text, labels, error messages, placeholder text, and dynamic content |
| 154 | +- Use the `t()` function from I18nContext for all translations |
| 155 | + |
| 156 | +#### Translation Patterns |
| 157 | + |
| 158 | +- Use the `t()` function from I18nContext for all user-facing text |
| 159 | +- Translate all button text, labels, error messages, and dynamic content |
| 160 | +- Avoid hardcoded text in any language |
| 161 | + |
| 162 | +#### Translation Key Management |
| 163 | + |
| 164 | +- Use generic terms unless specifically scoped: `t('knowledge_base')` not `t('policy_documents')` |
| 165 | +- Add translation keys to ALL language files: `zh-CN.ts`, `en-US.ts`, `zh-TW.ts` |
| 166 | +- Remove unused translation keys when replacing with generic ones |
| 167 | + |
| 168 | +### Data Modeling and Content Management |
| 169 | + |
| 170 | +#### Content Model Patterns |
| 171 | + |
| 172 | +- Use ContentModel with configured client from mobx-github |
| 173 | +- Import configuration via `'./Base'` to ensure proper GitHub client setup |
| 174 | +- Handle Base64 content decoding when processing GitHub API responses |
| 175 | + |
| 176 | +#### Tree Structure and Navigation |
| 177 | + |
| 178 | +- Use `treeFrom` utility from web-utility for hierarchical data structures |
| 179 | +- Follow established patterns for tree node organization and navigation |
| 180 | + |
| 181 | +### GitHub Integration Standards |
| 182 | + |
| 183 | +#### API Usage Patterns |
| 184 | + |
| 185 | +- Import configured `githubClient` from `models/Base.ts` |
| 186 | + |
| 187 | +#### Authentication and Rate Limiting |
| 188 | + |
| 189 | +- GitHub API authentication is configured in `models/Base.ts` |
| 190 | +- Use the configured client to avoid rate limiting and authentication issues |
| 191 | +- Don't create separate GitHub API instances |
| 192 | + |
| 193 | +### Build and Development Process |
| 194 | + |
| 195 | +#### Pre-commit Standards |
| 196 | + |
| 197 | +1. **Run linting**: `pnpm lint` to auto-fix formatting |
| 198 | +2. **Check build**: Ensure `pnpm build` passes |
| 199 | +3. **Validate translations**: Verify all text is properly translated |
| 200 | +4. **Remove unused code**: Clean up unused imports and translation keys |
| 201 | + |
| 202 | +#### Code Review Compliance |
| 203 | + |
| 204 | +- **Follow exact code suggestions** from reviews when provided |
| 205 | +- Use **minimal approach** - only include explicitly requested functionality |
| 206 | +- **Don't add extra features** not specified in requirements |
| 207 | +- **Address reviewer feedback completely** before requesting re-review |
| 208 | + |
| 209 | +## Common Commands Reference |
| 210 | + |
| 211 | +### Package Management |
| 212 | + |
| 213 | +```bash |
| 214 | +pnpm install # Install dependencies (1-3 minutes) |
| 215 | +pnpm --version # Check pnpm version |
| 216 | +``` |
| 217 | + |
| 218 | +### Development |
| 219 | + |
| 220 | +```bash |
| 221 | +pnpm dev # Start development server (5-15s) |
| 222 | +pnpm build # Production build (30s-2min) |
| 223 | +pnpm start # Start production server |
| 224 | +``` |
| 225 | + |
| 226 | +### Code Quality |
| 227 | + |
| 228 | +```bash |
| 229 | +pnpm lint # Run ESLint with auto-fix (15s) |
| 230 | +pnpm test # Run tests (lint-staged + lint, 15s) |
| 231 | +``` |
| 232 | + |
| 233 | +## Troubleshooting |
| 234 | + |
| 235 | +### Common Issues and Solutions |
| 236 | + |
| 237 | +#### Build and Development Issues |
| 238 | + |
| 239 | +- **"Unsupported engine" warnings**: Expected on Node.js <22, development still works |
| 240 | +- **Build hangs**: Never cancel builds - they may take several minutes, set appropriate timeouts |
| 241 | +- **Missing dependencies**: Always run `pnpm install` first |
| 242 | + |
| 243 | +#### Component and Styling Issues |
| 244 | + |
| 245 | +- **Custom HTML not working**: Replace with React Bootstrap components |
| 246 | +- **Translation not showing**: Ensure all text uses `t()` function and keys exist in all language files |
| 247 | +- **GitHub API errors**: Verify you're using configured `githubClient` from `models/Base.ts` |
| 248 | + |
| 249 | +#### Data and Content Issues |
| 250 | + |
| 251 | +- **Base64 content errors**: Use `atob(item.content)` to decode GitHub API responses |
| 252 | +- **Missing content**: Check ContentModel configuration and repository access |
| 253 | +- **Tree structure problems**: Use `treeFrom()` utility from web-utility |
| 254 | + |
| 255 | +### Development Environment Setup |
| 256 | + |
| 257 | +- Clear browser cache if components don't render properly |
| 258 | +- Restart development server after major configuration changes |
| 259 | +- Verify all translation files are updated when adding new keys |
| 260 | + |
| 261 | +## Project-Specific Patterns |
| 262 | + |
| 263 | +### Wiki System Architecture |
| 264 | + |
| 265 | +- Uses GitHub ContentModel to access policy documents from `fpsig/open-source-policy` repository |
| 266 | +- Renders markdown content with front-matter metadata |
| 267 | +- Supports hierarchical document structure with breadcrumb navigation |
| 268 | + |
| 269 | +### License Filter Integration |
| 270 | + |
| 271 | +- Interactive multi-step license selection process |
| 272 | +- Uses `license-filter` package for license recommendation logic |
| 273 | +- Supports multiple languages with comprehensive i18n coverage |
| 274 | + |
| 275 | +### Volunteer Management |
| 276 | + |
| 277 | +- Displays GitHub organization contributors |
| 278 | +- Integrates with OSS Insight widgets for contributor analytics |
| 279 | +- Uses GitHub API for real-time contributor data |
| 280 | + |
| 281 | +Always prioritize these project-specific standards over generic Next.js or React guidance when working in this specific codebase. |
0 commit comments