|
| 1 | +# Open Source Bazaar - GitHub Copilot Instructions |
| 2 | + |
| 3 | +Open Source Bazaar 是一个基于 Next.js 15、TypeScript、React Bootstrap 和 MobX 构建的开源项目展示平台。它包含许可证过滤器、Wiki 知识库、志愿者展示、Lark 集成等功能。 |
| 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 | +pnpm lint # Fix linting issues automatically |
| 60 | +pnpm test # Runs linting + staged file checks |
| 61 | +``` |
| 62 | + |
| 63 | +## Key Project Structure |
| 64 | + |
| 65 | +### Important Directories |
| 66 | + |
| 67 | +- `pages/` - Next.js pages and API routes |
| 68 | +- `components/` - Reusable React components with Bootstrap styling |
| 69 | +- `models/` - MobX stores and data models |
| 70 | +- `translation/` - i18n language files (zh-CN, en-US, zh-TW) |
| 71 | +- `styles/` - CSS and styling files |
| 72 | +- `public/` - Static assets |
| 73 | + |
| 74 | +### Configuration Files |
| 75 | + |
| 76 | +- `package.json` - Dependencies and scripts |
| 77 | +- `next.config.ts` - Next.js configuration with MDX support |
| 78 | +- `tsconfig.json` - TypeScript configuration |
| 79 | +- `eslint.config.ts` - ESLint configuration |
| 80 | +- `babel.config.js` - Babel configuration |
| 81 | + |
| 82 | +### Key Dependencies |
| 83 | + |
| 84 | +- **Next.js 15** - React framework |
| 85 | +- **React Bootstrap 2.10** - UI component library |
| 86 | +- **MobX 6.13** - State management |
| 87 | +- **mobx-github 0.4** - GitHub API integration |
| 88 | +- **mobx-i18n 0.7** - Internationalization |
| 89 | +- **license-filter 0.2** - License filtering functionality |
| 90 | +- **marked 16.2** - Markdown processing |
| 91 | + |
| 92 | +## Development Standards and Best Practices |
| 93 | + |
| 94 | +Based on comprehensive PR review analysis, follow these critical development standards: |
| 95 | + |
| 96 | +### Architecture and Code Organization |
| 97 | + |
| 98 | +#### Component and Import Standards |
| 99 | + |
| 100 | +- **ALWAYS use React Bootstrap components** instead of custom HTML elements |
| 101 | +- Use `<Button>`, `<Badge>`, `<Breadcrumb>`, `<Card>`, `<Container>` from 'react-bootstrap' |
| 102 | +- Import from existing configured clients: use `githubClient` from `models/Base.ts` |
| 103 | +- Use utilities from established libraries: `treeFrom` from 'web-utility' |
| 104 | +- Import `'./Base'` in model files for proper configuration |
| 105 | + |
| 106 | +#### Data and API Integration |
| 107 | + |
| 108 | +- Use **GitHub API** with ContentModel from mobx-github for content management |
| 109 | +- Use configured `githubClient` from `models/Base.ts` for authenticated API calls |
| 110 | +- **Base64 decode** content from GitHub API responses: `atob(item.content)` |
| 111 | +- Replace filesystem reading with GitHub Contents API calls |
| 112 | +- Use `ContentModel('owner', 'repo')` pattern for repository content access |
| 113 | + |
| 114 | +#### Error Handling and Static Generation |
| 115 | + |
| 116 | +- **Natural error throwing** for static generation - let errors bubble up to catch build issues |
| 117 | +- Don't catch errors in `getStaticProps` unless specifically handling them |
| 118 | +- Ensure build passes before pushing - resolve issues at compile time |
| 119 | + |
| 120 | +### UI/UX Standards |
| 121 | + |
| 122 | +#### Component Usage Patterns |
| 123 | + |
| 124 | +```typescript |
| 125 | +// ✅ Correct - use React Bootstrap components |
| 126 | +import { Button, Badge, Breadcrumb, Card, Container } from 'react-bootstrap'; |
| 127 | + |
| 128 | +<Button variant="outline-primary" size="sm" href={url} target="_blank"> |
| 129 | + {t('edit_on_github')} |
| 130 | +</Button> |
| 131 | + |
| 132 | +<Badge bg="secondary">{label}</Badge> |
| 133 | + |
| 134 | +// ❌ Wrong - custom HTML elements |
| 135 | +<a href={url} className="btn btn-outline-primary">Edit</a> |
| 136 | +<span className="badge bg-secondary">{label}</span> |
| 137 | +``` |
| 138 | + |
| 139 | +#### Semantic HTML Structure |
| 140 | + |
| 141 | +- Use ordered lists (`<ol>`) for countable items, unordered lists (`<ul>`) for navigation |
| 142 | +- Apply proper semantic structure: `<article>`, `<header>`, `<section>` |
| 143 | +- Use `list-unstyled` class for first-level lists to remove default styling |
| 144 | + |
| 145 | +### Code Quality Standards |
| 146 | + |
| 147 | +#### Modern ECMAScript Features |
| 148 | + |
| 149 | +```typescript |
| 150 | +// ✅ Correct - use optional chaining |
| 151 | +node.parent_path?.split('/') |
| 152 | +node.children?.length > 0 |
| 153 | + |
| 154 | +// ✅ Correct - let TypeScript infer types when possible |
| 155 | +const renderTree = (nodes: WikiNode[], level = 0) => ( |
| 156 | + // No need for explicit return type annotation |
| 157 | +) |
| 158 | + |
| 159 | +// ❌ Wrong - verbose type annotations where inference works |
| 160 | +const renderTree = (nodes: WikiNode[], level = 0): React.ReactElement => ( |
| 161 | +``` |
| 162 | +
|
| 163 | +#### Import and Type Management |
| 164 | +
|
| 165 | +```typescript |
| 166 | +// ✅ Correct - import from established sources |
| 167 | +import { ContentModel } from 'mobx-github'; |
| 168 | +import { treeFrom } from 'web-utility'; |
| 169 | +import './Base'; // For configuration |
| 170 | + |
| 171 | +// ✅ Correct - minimal exports |
| 172 | +export const policyContentStore = new ContentModel('fpsig', 'open-source-policy'); |
| 173 | + |
| 174 | +// ❌ Wrong - unnecessary custom implementations |
| 175 | +// Don't create new GitHub API clients when configured ones exist |
| 176 | +``` |
| 177 | +
|
| 178 | +### Translation and Internationalization |
| 179 | +
|
| 180 | +#### Critical Translation Requirements |
| 181 | +
|
| 182 | +- **ALL user-facing text** MUST be translated using i18n system |
| 183 | +- This includes button text, labels, error messages, placeholder text, and dynamic content |
| 184 | +- Use the `t()` function from I18nContext for all translations |
| 185 | +
|
| 186 | +#### Translation Patterns |
| 187 | +
|
| 188 | +```typescript |
| 189 | +// ✅ Correct - all text translated |
| 190 | +const { t } = useContext(I18nContext); |
| 191 | + |
| 192 | +<p>{t('no_docs_available')}</p> |
| 193 | +<Button>{t('contribute_content')}</Button> |
| 194 | +alert(t('operation_successful')); |
| 195 | + |
| 196 | +// ❌ Wrong - hardcoded text |
| 197 | +<p>暂无政策文档</p> |
| 198 | +<Button>贡献内容</Button> |
| 199 | +alert('操作成功'); |
| 200 | +``` |
| 201 | +
|
| 202 | +#### Translation Key Management |
| 203 | +
|
| 204 | +- Use generic terms unless specifically scoped: `t('knowledge_base')` not `t('policy_documents')` |
| 205 | +- Add translation keys to ALL language files: `zh-CN.ts`, `en-US.ts`, `zh-TW.ts` |
| 206 | +- Remove unused translation keys when replacing with generic ones |
| 207 | +
|
| 208 | +### Data Modeling and Content Management |
| 209 | +
|
| 210 | +#### Content Model Patterns |
| 211 | +
|
| 212 | +```typescript |
| 213 | +// ✅ Correct - use ContentModel with configured client |
| 214 | +import { ContentModel } from 'mobx-github'; |
| 215 | +import './Base'; // Ensures githubClient configuration |
| 216 | + |
| 217 | +export const policyContentStore = new ContentModel('fpsig', 'open-source-policy'); |
| 218 | + |
| 219 | +// Content processing with proper Base64 decoding |
| 220 | +const content = item.content ? atob(item.content) : ''; |
| 221 | +``` |
| 222 | +
|
| 223 | +#### Tree Structure and Navigation |
| 224 | +
|
| 225 | +```typescript |
| 226 | +// ✅ Correct - use treeFrom utility for hierarchical data |
| 227 | +import { treeFrom } from 'web-utility'; |
| 228 | + |
| 229 | +const tree = treeFrom(nodes, 'path', 'parent_path', 'children'); |
| 230 | +``` |
| 231 | +
|
| 232 | +### GitHub Integration Standards |
| 233 | +
|
| 234 | +#### API Usage Patterns |
| 235 | +
|
| 236 | +- Use `ContentModel` for repository content access |
| 237 | +- Always decode Base64 content: `atob(item.content)` |
| 238 | +- Import configured `githubClient` from `models/Base.ts` |
| 239 | +- Follow the pattern: `new ContentModel('owner', 'repository')` |
| 240 | +
|
| 241 | +#### Authentication and Rate Limiting |
| 242 | +
|
| 243 | +- GitHub API authentication is configured in `models/Base.ts` |
| 244 | +- Use the configured client to avoid rate limiting and authentication issues |
| 245 | +- Don't create separate GitHub API instances |
| 246 | +
|
| 247 | +### Build and Development Process |
| 248 | +
|
| 249 | +#### Pre-commit Standards |
| 250 | +
|
| 251 | +1. **Run linting**: `pnpm lint` to auto-fix formatting |
| 252 | +2. **Check build**: Ensure `pnpm build` passes |
| 253 | +3. **Validate translations**: Verify all text is properly translated |
| 254 | +4. **Remove unused code**: Clean up unused imports and translation keys |
| 255 | +
|
| 256 | +#### Code Review Compliance |
| 257 | +
|
| 258 | +- **Follow exact code suggestions** from reviews when provided |
| 259 | +- Use **minimal approach** - only include explicitly requested functionality |
| 260 | +- **Don't add extra features** not specified in requirements |
| 261 | +- **Address reviewer feedback completely** before requesting re-review |
| 262 | +
|
| 263 | +## Common Commands Reference |
| 264 | +
|
| 265 | +### Package Management |
| 266 | +
|
| 267 | +```bash |
| 268 | +pnpm install # Install dependencies (1-3 minutes) |
| 269 | +pnpm --version # Check pnpm version |
| 270 | +``` |
| 271 | +
|
| 272 | +### Development |
| 273 | +
|
| 274 | +```bash |
| 275 | +pnpm dev # Start development server (5-15s) |
| 276 | +pnpm build # Production build (30s-2min) |
| 277 | +pnpm start # Start production server |
| 278 | +``` |
| 279 | +
|
| 280 | +### Code Quality |
| 281 | +
|
| 282 | +```bash |
| 283 | +pnpm lint # Run ESLint with auto-fix (15s) |
| 284 | +pnpm test # Run tests (lint-staged + lint, 15s) |
| 285 | +``` |
| 286 | +
|
| 287 | +## Troubleshooting |
| 288 | +
|
| 289 | +### Common Issues and Solutions |
| 290 | +
|
| 291 | +#### Build and Development Issues |
| 292 | +
|
| 293 | +- **"Unsupported engine" warnings**: Expected on Node.js <22, development still works |
| 294 | +- **Build hangs**: Never cancel builds - they may take several minutes, set appropriate timeouts |
| 295 | +- **Missing dependencies**: Always run `pnpm install` first |
| 296 | +
|
| 297 | +#### Component and Styling Issues |
| 298 | +
|
| 299 | +- **Custom HTML not working**: Replace with React Bootstrap components |
| 300 | +- **Translation not showing**: Ensure all text uses `t()` function and keys exist in all language files |
| 301 | +- **GitHub API errors**: Verify you're using configured `githubClient` from `models/Base.ts` |
| 302 | +
|
| 303 | +#### Data and Content Issues |
| 304 | +
|
| 305 | +- **Base64 content errors**: Use `atob(item.content)` to decode GitHub API responses |
| 306 | +- **Missing content**: Check ContentModel configuration and repository access |
| 307 | +- **Tree structure problems**: Use `treeFrom()` utility from web-utility |
| 308 | +
|
| 309 | +### Development Environment Setup |
| 310 | +
|
| 311 | +- Clear browser cache if components don't render properly |
| 312 | +- Restart development server after major configuration changes |
| 313 | +- Verify all translation files are updated when adding new keys |
| 314 | +
|
| 315 | +## Project-Specific Patterns |
| 316 | +
|
| 317 | +### Wiki System Architecture |
| 318 | +
|
| 319 | +- Uses GitHub ContentModel to access policy documents from `fpsig/open-source-policy` repository |
| 320 | +- Renders markdown content with front-matter metadata |
| 321 | +- Supports hierarchical document structure with breadcrumb navigation |
| 322 | +
|
| 323 | +### License Filter Integration |
| 324 | +
|
| 325 | +- Interactive multi-step license selection process |
| 326 | +- Uses `license-filter` package for license recommendation logic |
| 327 | +- Supports multiple languages with comprehensive i18n coverage |
| 328 | +
|
| 329 | +### Volunteer Management |
| 330 | +
|
| 331 | +- Displays GitHub organization contributors |
| 332 | +- Integrates with OSS Insight widgets for contributor analytics |
| 333 | +- Uses GitHub API for real-time contributor data |
| 334 | +
|
| 335 | +Always prioritize these project-specific standards over generic Next.js or React guidance when working in this specific codebase. |
0 commit comments