From 091c7dc6730cd4e2f50b85cffefe2b7458e0c9c4 Mon Sep 17 00:00:00 2001 From: Daniel Samson Date: Thu, 29 Oct 2026 15:59:14 +0000 Subject: [PATCH] feat: add react-router-dom v6.x dependency and configuration to M3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Key changes: - Added react-router-dom as required dependency (v6.x) - App.tsx now includes BrowserRouter wrapper with Routes - Route definitions map pages to URLs (/ → Home, /articles → ArticlePage, /categories → CategoriesPage) - Header navigation uses React Router components instead of anchor tags - Updated scoring rubric: 49 total points - New critical requirement: Agent must install BOTH lucide-react AND react-router-dom --- milestone/m3-setup-frontend-prompt.md | 168 +++++++++++++------------ milestone/m3-setup-frontend-scoring.md | 61 +++++---- 2 files changed, 127 insertions(+), 102 deletions(-) diff --git a/milestone/m3-setup-frontend-prompt.md b/milestone/m3-setup-frontend-prompt.md index e18d90f..15f8c16 100644 --- a/milestone/m3-setup-frontend-prompt.md +++ b/milestone/m3-setup-frontend-prompt.md @@ -35,7 +35,7 @@ Create the frontend infrastructure for **newzy** news web application using Reac │ │ │ ├── Header.test.tsx │ │ │ ├── ArticleCard.test.tsx │ │ │ └── components/ - │ │ ├── App.tsx # Root component with routing setup + │ │ ├── App.tsx # Root component with React Router setup │ │ └── main.tsx # React entry point │ ├── playwright/ │ │ └── e2e/ @@ -44,7 +44,7 @@ Create the frontend infrastructure for **newzy** news web application using Reac │ ├── .gitignore │ ├── Dockerfile │ ├── docker-compose.yml # Frontend service config - │ ├── package.json # Include lucide-react dependency + │ ├── package.json # Include react-router-dom dependency │ ├── tsconfig.json │ ├── vite.config.ts │ └── README.md # Setup and API documentation @@ -52,9 +52,10 @@ Create the frontend infrastructure for **newzy** news web application using Reac 2. Initialize Vite project with React, TypeScript template: - Use Node.js 18 or later - - Install dependencies including lucide-react for icons: + - Install dependencies including lucide-react for icons AND react-router-dom for routing: - react, react-dom, typescript, @types/react, @types/react-dom, vite - lucide-react (for UI icons) + - react-router-dom v6.x (for client-side routing) - class-variance-authority, clsx, tailwind-merge (for utility classes) 3. Install and configure Playwright and Vitest: @@ -67,7 +68,7 @@ Create the frontend infrastructure for **newzy** news web application using Reac - Base path configuration - Build output directory (dist/) - Development server on port 5173 - - Tailwind CSS integration if applicable + - React Router DOM plugin configuration if using router v6 dynamic imports 5. Create TypeScript type definitions in `src/types/`: - Article interface (id, title, content, author, category, published, createdAt) @@ -78,13 +79,13 @@ Create the frontend infrastructure for **newzy** news web application using Reac 6. Create UI components with lucide-react icons in `src/components/ui/`: - **Header.tsx**: - Logo/text brand representation - - Navigation placeholder links (Home, Articles, About) - - Use Lucide icons: Home, FileText, Settings for navigation + - Navigation links that use React Router for navigation + - Use Lucide icons: Home, FileText, Settings for navigation items - Responsive design with mobile menu consideration - **Layout.tsx**: - Wrapper component for page structure - - Header integration + - Header integration via routing-aware navigation - Content area placeholder - Footer section placeholder @@ -102,60 +103,68 @@ Create the frontend infrastructure for **newzy** news web application using Reac - **ArticlePage.tsx** and **CategoriesPage.tsx**: Basic layouts for future pages -9. Set up API client in `src/api/client.ts`: - - Base URL configuration (relative path /api) - - Fetch wrapper with error handling - - Type-safe request/response functions +9. Set up React Router in `App.tsx` with: + - BrowserRouter wrapper at root level + - Route definitions mapping pages to URLs + - Proper route-to-page component imports + - Link navigation using react-router-dom's `` component (not anchor tags) -10. Create component tests using Vitest: - - Test Header renders correctly with lucide icons +10. Set up API client in `src/api/client.ts`: + - Base URL configuration (relative path /api) + - Fetch wrapper with error handling + - Type-safe request/response functions + +11. Create component tests using Vitest: + - Test Header renders correctly with lucide icons and routing links - Test ArticleCard displays data correctly - Test Layout structure is properly implemented - Use @testing-library/react for rendering -11. Create Playwright E2E tests: +12. Create Playwright E2E tests: - Test home page accessibility and layout - Test article list renders with data - - Test navigation between pages works + - Test navigation between pages works (via React Router Links) -12. Create `package.json` scripts: +13. Create `package.json` scripts: - dev, build, preview, test, e2e, lint -13. Create `.gitignore` to exclude node_modules, dist/, .env files, IDE configs, playwright trace files +14. Create `.gitignore` to exclude node_modules, dist/, .env files, IDE configs, playwright trace files -14. Create `Dockerfile` with Nginx for serving static files in production (multi-stage) +15. Create `Dockerfile` with Nginx for serving static files in production (multi-stage) -15. Update `docker-compose.yml` at project root with frontend service: +16. Update `docker-compose.yml` at project root with frontend service: - Port mapping 3000:80 - Links to backend service for API calls -16. Document setup process in `frontend/README.md` with examples and lucide-react icon documentation +17. Document setup process in `frontend/README.md` with examples and lucide-react icon documentation -17. Configure ESLint rules for React and TypeScript best practices +18. Configure ESLint rules for React, TypeScript, and react-router best practices Remember: Focus ONLY on frontend infrastructure. No complex UI features required yet. ## Description -This milestone sets up the React + TypeScript frontend for newzy news application using Vite as the build tool. The scope includes project scaffolding, lucide-react icons integration, type definitions, properly structured components, and comprehensive testing setup with Playwright E2E tests—no complex UI implementations or user interactions. +This milestone sets up the React + TypeScript frontend for newzy news application using Vite as the build tool. The scope includes project scaffolding, lucide-react icons integration, React Router setup for navigation, type definitions, properly structured components, and comprehensive testing setup with Playwright E2E tests—no complex UI implementations or user interactions. **Purpose**: Create a responsive, type-safe frontend ready to consume the backend API built in M2, with robust test coverage from both unit and E2E perspectives. **Target Audience**: Frontend developers who need to understand the structure and extend components for features in subsequent milestones. -**Expected Outcomes**: A functioning React application that can load from browser or Docker container, with lucide-react icons integrated, typed interfaces matching backend models, properly separated page and component code, basic page layout in place, and a complete testing setup (unit tests + Playwright E2E). +**Expected Outcomes**: A functioning React application that can load from browser or Docker container, with lucide-react icons integrated, React Router configured for client-side navigation, typed interfaces matching backend models, properly separated page and component code, basic page layout in place, and a complete testing setup (unit tests + Playwright E2E). ## Acceptance Criteria -- [ ] Vite project initialized with React, TypeScript, and lucide-react +- [ ] Vite project initialized with React, TypeScript, lucide-react, AND react-router-dom v6.x - [ ] Project structure includes: public/, src/, assets/, components/, pages/, types/, api/, tests/ folders - [ ] Clear separation between `pages/` (page-level routing) and `components/` (reusable UI) -- [ ] Lucide-react installed with icons: Home, FileText, Settings, Search +- [ ] React Router DOM properly configured in App.tsx with BrowserRouter wrapper +- [ ] Route definitions mapped to page components in src/pages/ +- [ ] lucide-react installed with icons: Home, FileText, Settings, Search - [ ] TypeScript type definitions for Article, Author, Category models -- [ ] Header component created with lucide icons and navigation placeholder +- [ ] Header component created with lucide icons and React Router navigation links - [ ] Layout wrapper component implemented with proper structure - [ ] Reusable article components: ArticleCard, AuthorAvatar, CategoryBadge -- [ ] Page components: Home.tsx with article grid layout +- [ ] Page components: Home.tsx with article grid layout using router Links - [ ] API client configured with base URL and fetch wrapper - [ ] Unit tests in src/tests/ using Vitest (react-testing-library) - [ ] Playwright E2E tests in playwright/e2e/ covering core flows @@ -163,7 +172,7 @@ This milestone sets up the React + TypeScript frontend for newzy news applicatio - [ ] .gitignore excludes node_modules, dist/, IDE configs, and playwright artifacts - [ ] Dockerfile builds production-ready static files with Nginx serving - [ ] docker-compose.yml includes frontend service linked to backend -- [ ] ESLint rules configured and passing +- [ ] ESLint rules configured and passing for react-router best practices ## Technical Details @@ -180,7 +189,7 @@ newzy/ │ │ │ └── logo.svg # Brand logo (placeholder) │ │ ├── components/ │ │ │ ├── ui/ # Generic UI components with lucide icons -│ │ │ │ ├── Header.tsx # Navigation with icons +│ │ │ │ ├── Header.tsx # Navigation with icons and router Links │ │ │ │ └── Layout.tsx # Page wrapper layout │ │ │ └── articles/ # Domain-specific components │ │ │ ├── ArticleCard.tsx # Article preview component @@ -198,7 +207,7 @@ newzy/ │ │ │ ├── Header.test.tsx │ │ │ ├── ArticleCard.test.tsx │ │ │ └── components/ -│ │ ├── App.tsx # Root with Router setup +│ │ ├── App.tsx # Root with BrowserRouter and routes │ │ └── main.tsx # React entry point │ ├── playwright/ │ │ └── e2e/ # E2E tests (Playwright) @@ -207,7 +216,7 @@ newzy/ │ ├── .gitignore │ ├── Dockerfile │ ├── docker-compose.yml # Frontend service config -│ ├── package.json # Dependencies including lucide-react +│ ├── package.json # Dependencies including react-router-dom │ ├── tsconfig.json │ ├── vite.config.ts │ └── README.md # Setup and API documentation @@ -262,6 +271,7 @@ export interface ApiResponse { "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", + "react-router-dom": "^6.20.0", /* ← React Router v6.x */ "typescript": "^5.0.0", "@types/react": "^18.2.0", "@types/react-dom": "^18.2.0", @@ -280,49 +290,37 @@ export interface ApiResponse { } ``` -### Lucide React Icons Usage +### React Router Configuration in App.tsx ```tsx -import { Home, FileText, Settings, Search } from 'lucide-react'; +import { BrowserRouter, Routes, Route, Link } from 'react-router-dom'; +import Home from './pages/Home'; +import ArticlePage from './pages/ArticlePage'; +import CategoriesPage from './pages/CategoriesPage'; +import Layout from './components/ui/Layout'; -// In Header component -
- /* brand logo */ - } label="Home" /> - } label="Articles" /> - } label="Settings" /> - -
-``` - -### Component Structure Examples - -**ArticleCard.tsx:** -```tsx -import { Article } from '../types'; -import { FileText } from 'lucide-react'; -import AuthorAvatar from './AuthorAvatar'; -import CategoryBadge from './CategoryBadge'; - -interface ArticleCardProps { - article: Article; -} - -export function ArticleCard({ article }: ArticleCardProps) { +function App() { return ( -
-

{article.title}

- - - -
+ + + + } /> + } /> + } /> + + + ); } + +export default App; ``` -**Header.tsx:** +### Header Component with React Router Links + ```tsx import { Home, FileText, Settings } from 'lucide-react'; +import { Link } from 'react-router-dom'; interface HeaderProps {} @@ -331,9 +329,16 @@ export function Header({}: HeaderProps) {

newzy

); @@ -343,25 +348,25 @@ export function Header({}: HeaderProps) { ### Page Separation Strategy **pages/ (routing - one per route):** -- Home.tsx → / (main landing page) -- ArticlePage.tsx → /articles/:id (individual article) -- CategoriesPage.tsx → /categories (list of categories) +- `Home.tsx` → `/` (main landing page with featured article) +- `ArticlePage.tsx` → `/articles/:id` (individual article view with useParams) +- `CategoriesPage.tsx` → `/categories` (list of categories placeholder) **components/ui/ (generic UI with icons):** -- Header.tsx → Navigation with lucide icons -- Layout.tsx → Page wrapper structure +- `Header.tsx` → Navigation with lucide icons AND React Router `` components +- `Layout.tsx` → Page wrapper structure accepting props from App routes **components/articles/ (domain-specific):** -- ArticleCard.tsx → Article preview component -- AuthorAvatar.tsx → Author profile indicator -- CategoryBadge.tsx → Category label pill +- `ArticleCard.tsx` → Article preview component for Home page +- `AuthorAvatar.tsx` → Author profile indicator +- `CategoryBadge.tsx` → Category label pill ## QA Notes ### Unit Testing Checklist (Vitest + React Testing Library) - [ ] Tests discover and run correctly with `npm test` -- [ ] Header renders with lucide icons correctly -- [ ] Layout component structure verified +- [ ] Header renders with lucide icons and router Links correctly +- [ ] Layout component structure verified with routing context available - [ ] ArticleCard displays data properly - [ ] Component props are type-safe - [ ] Test coverage >50% on tested components @@ -369,12 +374,12 @@ export function Header({}: HeaderProps) { ### E2E Testing Checklist (Playwright) - [ ] Playwright configured in playwright.config.ts - [ ] Tests discover and run with `npm run e2e` -- [ ] Home page accessibility verified (a11y checks pass) +- [ ] Home page accessibility verified (a11y checks pass for Links) - [ ] Article list renders with data -- [ ] Navigation between pages works via lucide icons +- [ ] Navigation between pages works via React Router Links (not anchor tags) - [ ] API requests complete successfully via browser - [ ] Browser console has no errors during E2E tests -- [ ] Tests use proper selectors and wait conditions +- [ ] Tests use proper selectors for routing elements ### Performance Considerations - Vite uses ESBuild for fast HMR during development @@ -383,6 +388,7 @@ export function Header({}: HeaderProps) { - Multi-stage Docker builds reduce image size - Playwright tests run in headless mode for faster execution - Lucide-react icons use SVG format (no font download) +- React Router uses client-side navigation (no page reloads) ### Security Notes - No sensitive data in client-side code @@ -397,6 +403,7 @@ export function Header({}: HeaderProps) { - Vite HMR doesn't work in Docker without hot-reload support - TypeScript path aliases not configured (using relative imports) - Playwright E2E tests may fail when backend service not available +- React Router state preservation not implemented ### Success Metrics - `npm run dev` starts within 30 seconds @@ -409,3 +416,4 @@ export function Header({}: HeaderProps) { - E2E tests complete in under 1 minute for core flows - Playwright traces and video artifacts excluded from version control - Lucide-react icons render correctly without fallback errors +- React Router navigation works without full page reloads diff --git a/milestone/m3-setup-frontend-scoring.md b/milestone/m3-setup-frontend-scoring.md index 2d43ccd..f243d91 100644 --- a/milestone/m3-setup-frontend-scoring.md +++ b/milestone/m3-setup-frontend-scoring.md @@ -4,12 +4,12 @@ | Score | Criteria | |-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 0 | Agent failed to implement acceptance criteria:
- No Vite/React project created
- TypeScript not configured
- Missing multiple required folders
- Components incomplete
- Missing tests (unit + E2E)
- Missing lucide-react icons
- No Dockerfile or docker-compose missing | -| 1 | Agent partially implemented acceptance criteria that builds successfully:
- Basic React app with vite but no lucide-icons
- Missing page/component separation
- Components render but have errors
- npm scripts incomplete
- No test setup at all | -| 2 | Agent fully implemented acceptance criteria that builds successfully:
- Vite + React + TypeScript project in frontend/ folder
- All required directories (assets/, components/, pages/, types/, api/, tests/) created
- lucide-react installed with core icons (Home, FileText, Settings, Search)
- Article, Author, Category TypeScript interfaces defined
- Header component with navigation placeholder and lucide icons- .gitignore excludes node_modules, dist/, IDE configs
- Playwright installed and configured | -| 3 | Agent fully implemented acceptance criteria that builds successfully, includes reusable article components created
- ArticleCard.tsx displays article data correctly- Header rendering and icon display50% on components | -| 5 | Agent fully implemented acceptance criteria that builds successfully, includes all content from Score 4 AND:
- Playwright E2E tests in playwright/e2e/ passing successfully60% across unit and E2E tests- No Vite/React project created
- TypeScript not configured
- Missing multiple required folders
- Components incomplete
- Missing tests (unit + E2E)
- Missing lucide-react icons
- Missing React Router setup
- No Dockerfile or docker-compose missing | +| 1 | Agent partially implemented acceptance criteria that builds successfully:
- Basic React app with vite but no lucide-icons
- Missing react-router-dom dependency
- Missing page/component separation
- Components render but have errors
- npm scripts incomplete
- No test setup at all | +| 2 | Agent fully implemented acceptance criteria that builds successfully:
- Vite + React + TypeScript project in frontend/ folder
- All required directories (assets/, components/, pages/, types/, api/, tests/) created
- lucide-react installed with core icons (Home, FileText, Settings, Search)
- react-router-dom v6.x installed and imported correctly- Header component with navigation placeholder and lucide icons AND router Links- .gitignore excludes node_modules, dist/, IDE configs
- Playwright installed and configured | +| 3 | Agent fully implemented acceptance criteria that builds successfully, includes reusable article components created
- ArticleCard.tsx displays article data correctly- Header rendering and icon display50% on components | +| 5 | Agent fully implemented acceptance criteria that builds successfully, includes all content from Score 4 AND:
- Playwright E2E tests in playwright/e2e/ passing successfully60% across unit and E2E tests- Missing pages/, components/ separation - **2 pts**: Complete directory structure with all required folders (public/, src/, assets/, components/, pages/, types/, api/, tests/) -### TypeScript & Dependencies (Max 4 points) -- **0 pts**: No TypeScript or tsconfig.json
- lucide-react not installed -- **1 pt**: TypeScript enabled but no type definitions
- Partial interfaces +### TypeScript & Dependencies (Max 5 points) +- **0 pts**: No TypeScript or tsconfig.json
- Neither lucide-react nor react-router-dom installed +- **1 pt**: TypeScript enabled but no type definitions
- Partial interfaces
- Missing react-router-dom - **2 pts**: Article, Author, Category interfaces properly defined
- lucide-react with core icons imported correctly -- **3 pts**: Comprehensive types including ApiResponse, function signatures
- Proper type exports across modules -- **4 pts**: All type definitions validated and used in components, function signatures No TypeScript errors on build +- **5 pts**: React Router Link components typed correctly with proper navigation types ### UI Components (Max 5 points) - **0 pts**: No UI components or Header missing
- Application doesn't render properly @@ -33,11 +34,19 @@ - **4 pts**: ArticleCard renders article data properly with all sub-components- App.tsx missing BrowserRouter or Routes +- **1 pt**: react-router-dom imported but no configuration
- Link components not working +- **2 pts**: BrowserRouter wrapper exists in App.tsx
- Basic routes defined (at least / and /articles) +- **3 pts**: Route definitions mapped to page components` components instead of anchor tags- Routes not defined in App.tsx - **1 pt**: Only Home page created- Cannot make requests to backend @@ -49,7 +58,7 @@ - **1 pt**: Tests folder exists but no actual tests
- Test runner not configured in package.json - **2 pts**: Vitest configured, Header.test.tsx created=50% coverage on tested components=50% coverage on tested components- playwright.config.ts missing @@ -57,8 +66,8 @@ - **2 pts**: playwright/e2e folder created with home.spec.ts and api.spec.ts- Cannot containerize frontend @@ -69,15 +78,15 @@ ### Code Quality (Max 2 points) - **0 pts**: No ESLint or linting fails
- Poor code organization - **1 pt**: Basic ESLint rules configured but warnings present
- Inconsistent formatting -- **2 pts**: ESLint passing with zero critical warnings
- Consistent React + TypeScript best practices +- **2 pts**: ESLint passing with zero critical warnings
- Consistent React + TypeScript + react-router best practices ### Documentation (Max 3 points) - **0 pts**: No README.md or incomplete
- No setup instructions - **1 pt**: README exists with basic info only
- Missing lucide-react documentation -- **2 pts**: Comprehensive README with setup guide, API documentation, and usage examples` components for navigation (not anchor tags) + ## Bonus Points Consideration **+1 point** for: -- ESLint rules properly configured and enforcing React/TypeScript best practices +- ESLint rules properly configured and enforcing React/TypeScript + react-router best practices - .eslintrc.cjs or vite.config.ts includes meaningful linting rules **+2 points** for: -- TypeScript strict mode enabled in tsconfig.json -- Components use proper TypeScript generics and props typing with lucide icons typed +- TypeScript strict mode enabled in tsconfig.json with react-router types +- Components use proper TypeScript generics and props typing with lucide icons typed as ReactNode **+3 points** for: - docker-compose.yml at project root orchestrating both services - Nginx configuration properly routes SPA (try_files with index.html fallback) +- E2E tests verify client-side routing without page reloads