Massive training corpus for AI coding models containing: - 10 JSONL training datasets (641+ examples across coding, reasoning, planning, architecture, communication, debugging, security, workflows, error handling, UI/UX) - 11 agent behavior specifications (explorer, planner, reviewer, debugger, executor, UI designer, Linux admin, kernel engineer, security architect, automation engineer, API architect) - 6 skill definition files (coding, API engineering, kernel, Linux server, security architecture, server automation, UI/UX) - Master README with project origin story and philosophy Built by Pony Alpha 2 to help AI models learn expert-level coding approaches.
2 lines
3.5 KiB
JSON
2 lines
3.5 KiB
JSON
{"category":"REST API Design","scenario":"Resource naming conventions and URL structure for an e-commerce platform","approach":"RESTful resource naming with hierarchical structure, plural nouns, and consistent patterns","specification":"OpenAPI 3.1 specification showing proper resource naming","code":"// express-typescript/src/routes/product.routes.ts\nimport { Router, Request, Response } from 'express';\nimport { ProductService } from '../services/product.service';\nimport { validateProductQuery } from '../middleware/validation.middleware';\n\nconst router = Router();\nconst productService = new ProductService();\n\n// Good: Plural resource name, clear hierarchy\nrouter.get('/products', validateProductQuery, async (req: Request, res: Response) => {\n try {\n const { category, page = 1, limit = 20, sort } = req.query;\n const products = await productService.getProducts({\n category: category as string,\n page: Number(page),\n limit: Number(limit),\n sort: sort as string\n });\n res.json({\n data: products.data,\n pagination: {\n page: products.page,\n limit: products.limit,\n total: products.total,\n totalPages: Math.ceil(products.total / products.limit)\n }\n });\n } catch (error) {\n res.status(500).json({ error: 'Failed to fetch products' });\n }\n});\n\n// Good: Nested resource with proper hierarchy\nrouter.get('/products/:productId/reviews', async (req: Request, res: Response) => {\n try {\n const { productId } = req.params;\n const reviews = await productService.getProductReviews(productId);\n res.json({ data: reviews });\n } catch (error) {\n res.status(500).json({ error: 'Failed to fetch reviews' });\n }\n});\n\n// Good: Single resource access\nrouter.get('/products/:productId', async (req: Request, res: Response) => {\n try {\n const { productId } = req.params;\n const product = await productService.getProductById(productId);\n if (!product) {\n return res.status(404).json({ error: 'Product not found' });\n }\n res.json({ data: product });\n } catch (error) {\n res.status(500).json({ error: 'Failed to fetch product' });\n }\n});\n\n// Good: Filter sub-resource with query parameters\nrouter.get('/users/:userId/orders', async (req: Request, res: Response) => {\n try {\n const { userId } = req.params;\n const { status, from, to } = req.query;\n const orders = await productService.getUserOrders(userId, {\n status: status as string,\n from: from ? new Date(from as string) : undefined,\n to: to ? new Date(to as string) : undefined\n });\n res.json({ data: orders });\n } catch (error) {\n res.status(500).json({ error: 'Failed to fetch orders' });\n }\n});\n\nexport default router;\n\n// Alternative API patterns:\n// BAD: /getProducts - Verbs in URL\n// BAD: /product - Singular nouns\n// BAD: /products/get/:id - Unnecessary nesting\n// GOOD: /products - Simple, plural\n// GOOD: /products/:id - Direct resource access\n// GOOD: /users/:userId/orders - Logical hierarchy","explanation":"Proper REST resource naming follows conventions: 1) Use plural nouns for collections (/products not /product), 2) Use nouns not verbs (/products not /getProducts), 3) Create logical hierarchies (/users/:userId/orders), 4) Keep URLs shallow (prefer /products/:id/reviews over /products/:id/comments/ratings), 5) Use query parameters for filtering, sorting, and pagination, 6) Be consistent across all endpoints. This makes APIs predictable and easy to understand."}
|