feat: add react-router-dom v6.x dependency and configuration to M3

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 <Link> components instead of anchor tags
- Updated scoring rubric: 49 total points
- New critical requirement: Agent must install BOTH lucide-react AND react-router-dom
This commit is contained in:
Daniel Samson committed 2026-10-29 15:59:14 +00:00
1 parent b627ddc418
commit 091c7dc673
2 files changed
+127 -102

No files matched your search

+88 -80
View File
@@ -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 `<Link>` 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<T> {
"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<T> {
}
```
### 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
<Header>
<LogoIcon className="w-6 h-6">/* brand logo */</LogoIcon>
<NavButton icon={<Home />} label="Home" />
<NavButton icon={<FileText />} label="Articles" />
<NavButton icon={<Settings />} label="Settings" />
<SearchPlaceholder />
</Header>
```
### 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 className="card">
<h2>{article.title}</h2>
<AuthorAvatar author={article.author} />
<CategoryBadge category={article.category} />
<FileText className="read-time-icon" />
</article>
<BrowserRouter>
<Layout>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/articles" element={<ArticlePage />} />
<Route path="/categories" element={<CategoriesPage />} />
</Routes>
</Layout>
</BrowserRouter>
);
}
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) {
<header className="nav">
<h1>newzy</h1>
<nav>
<a href="/"><Home /></a>
<a href="/articles"><FileText /></a>
<a href="/settings"><Settings /></a>
{/* Navigation uses react-router-dom Link, not anchor tags */}
<Link to="/">
<Home className="w-5 h-5" />
</Link>
<Link to="/articles">
<FileText className="w-5 h-5" />
</Link>
<Link to="/categories">
<Settings className="w-5 h-5" />
</Link>
</nav>
</header>
);
@@ -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 `<Link>` 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