Files
news-benchmark/milestone/m3-setup-frontend-prompt.md
T
Daniel Samson b627ddc418 feat: update M3 frontend setup with comprehensive requirements
- Add lucide-react dependency with Home, FileText, Settings icons
- Create assets/ folder with styles/ subdirectory for global.css
- Establish clear separation between pages/ (route-level) and components/ui/, components/articles/
- Implement Layout.tsx wrapper component for page structure
- Update component list: Header, Layout, ArticleCard, AuthorAvatar, CategoryBadge
- Add ArticlePage.tsx and CategoriesPage.tsx as placeholders in pages/
- Update scoring rubric to 40 points reflecting all new requirements
2026-10-29 15:56:43 +00:00

412 lines
16 KiB
Markdown

# M3: Setup Frontend
## Prompt
Create the frontend infrastructure for **newzy** news web application using React + TypeScript with Vite. Follow these steps:
1. Set up project structure in `frontend/` folder with clear separation between pages and components:
```
newzy/
├── frontend/
│ ├── public/
│ │ └── index.html # Vite entry HTML file
│ ├── src/
│ │ ├── assets/
│ │ │ ├── styles/
│ │ │ │ └── globals.css # Global styles
│ │ │ └── logo.svg # Brand logo (placeholder)
│ │ ├── components/
│ │ │ ├── ui/
│ │ │ │ ├── Header.tsx # Main navigation header with lucide icons
│ │ │ │ └── Layout.tsx # Wrapper component with layout structure
│ │ │ └── articles/
│ │ │ ├── ArticleCard.tsx # Reusable article display component
│ │ │ ├── AuthorAvatar.tsx # Author profile component
│ │ │ └── CategoryBadge.tsx # Category label component
│ │ ├── pages/
│ │ │ ├── Home.tsx # Homepage with article feed layout
│ │ │ ├── ArticlePage.tsx # Individual article view (placeholder)
│ │ │ └── CategoriesPage.tsx # Categories listing page (placeholder)
│ │ ├── types/
│ │ │ └── index.ts # TypeScript interfaces
│ │ ├── api/
│ │ │ └── client.ts # API request wrapper
│ │ ├── tests/
│ │ │ ├── Header.test.tsx
│ │ │ ├── ArticleCard.test.tsx
│ │ │ └── components/
│ │ ├── App.tsx # Root component with routing setup
│ │ └── main.tsx # React entry point
│ ├── playwright/
│ │ └── e2e/
│ │ ├── home.spec.ts # E2E test for homepage
│ │ └── api.spec.ts # E2E test for API interactions
│ ├── .gitignore
│ ├── Dockerfile
│ ├── docker-compose.yml # Frontend service config
│ ├── package.json # Include lucide-react dependency
│ ├── tsconfig.json
│ ├── vite.config.ts
│ └── README.md # Setup and API documentation
```
2. Initialize Vite project with React, TypeScript template:
- Use Node.js 18 or later
- Install dependencies including lucide-react for icons:
- react, react-dom, typescript, @types/react, @types/react-dom, vite
- lucide-react (for UI icons)
- class-variance-authority, clsx, tailwind-merge (for utility classes)
3. Install and configure Playwright and Vitest:
- @playwright/test for E2E testing
- vitest for unit testing
- @testing-library/react for component testing
- Run npx playwright install
4. Configure Vite with:
- Base path configuration
- Build output directory (dist/)
- Development server on port 5173
- Tailwind CSS integration if applicable
5. Create TypeScript type definitions in `src/types/`:
- Article interface (id, title, content, author, category, published, createdAt)
- Author interface (id, name, email, bio)
- Category interface (id, name, slug)
- API response types
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
- Responsive design with mobile menu consideration
- **Layout.tsx**:
- Wrapper component for page structure
- Header integration
- Content area placeholder
- Footer section placeholder
7. Create article-specific components in `src/components/articles/`:
- **ArticleCard.tsx**: Displays article summary with thumbnail placeholder, title, author info, category badge, read time
- **AuthorAvatar.tsx**: Shows author initials or profile image, hover tooltip with name
- **CategoryBadge.tsx**: Color-coded category pill component
8. Create page components in `src/pages/`:
- **Home.tsx**:
- Hero section with featured article
- Article grid layout using ArticleCard
- Pagination or infinite scroll placeholder
- Search/filter bar placeholder
- **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
10. Create component tests using Vitest:
- Test Header renders correctly with lucide icons
- Test ArticleCard displays data correctly
- Test Layout structure is properly implemented
- Use @testing-library/react for rendering
11. Create Playwright E2E tests:
- Test home page accessibility and layout
- Test article list renders with data
- Test navigation between pages works
12. 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 `Dockerfile` with Nginx for serving static files in production (multi-stage)
15. 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. Configure ESLint rules for React and TypeScript 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.
**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).
## Acceptance Criteria
- [ ] Vite project initialized with React, TypeScript, and lucide-react
- [ ] 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
- [ ] TypeScript type definitions for Article, Author, Category models
- [ ] Header component created with lucide icons and navigation placeholder
- [ ] Layout wrapper component implemented with proper structure
- [ ] Reusable article components: ArticleCard, AuthorAvatar, CategoryBadge
- [ ] Page components: Home.tsx with article grid layout
- [ ] 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
- [ ] package.json has dev, build, preview, test, e2e scripts working correctly
- [ ] .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
## Technical Details
### Project Root Structure
```
newzy/
├── frontend/
│ ├── public/
│ │ └── index.html # Vite entry HTML file
│ ├── src/
│ │ ├── assets/
│ │ │ ├── styles/
│ │ │ │ └── globals.css # Tailwind + global styles
│ │ │ └── logo.svg # Brand logo (placeholder)
│ │ ├── components/
│ │ │ ├── ui/ # Generic UI components with lucide icons
│ │ │ │ ├── Header.tsx # Navigation with icons
│ │ │ │ └── Layout.tsx # Page wrapper layout
│ │ │ └── articles/ # Domain-specific components
│ │ │ ├── ArticleCard.tsx # Article preview component
│ │ │ ├── AuthorAvatar.tsx # Author profile indicator
│ │ │ └── CategoryBadge.tsx # Category label pill
│ │ ├── pages/ # Page-level components (routes)
│ │ │ ├── Home.tsx # Homepage with article feed
│ │ │ ├── ArticlePage.tsx # Individual article view
│ │ │ └── CategoriesPage.tsx # Categories listing page
│ │ ├── types/
│ │ │ └── index.ts # TypeScript interfaces
│ │ ├── api/
│ │ │ └── client.ts # API request wrapper
│ │ ├── tests/ # Unit test files (Vitest)
│ │ │ ├── Header.test.tsx
│ │ │ ├── ArticleCard.test.tsx
│ │ │ └── components/
│ │ ├── App.tsx # Root with Router setup
│ │ └── main.tsx # React entry point
│ ├── playwright/
│ │ └── e2e/ # E2E tests (Playwright)
│ │ ├── home.spec.ts # Homepage flow test
│ │ └── api.spec.ts # API integration test
│ ├── .gitignore
│ ├── Dockerfile
│ ├── docker-compose.yml # Frontend service config
│ ├── package.json # Dependencies including lucide-react
│ ├── tsconfig.json
│ ├── vite.config.ts
│ └── README.md # Setup and API documentation
├── backend/ # Backend from M2
├── LICENSE # MIT License
├── README.md # Main project docs
└── docker-compose.yml # Full application orchestration
```
### TypeScript Type Definitions
```typescript
// src/types/index.ts
export interface Article {
id: number;
title: string;
content: string;
authorId: number;
author?: Author;
categoryId: number;
category?: Category;
createdAt: Date | string;
published: boolean;
}
export interface Author {
id: number;
name: string;
email: string;
bio?: string;
avatar?: string;
}
export interface Category {
id: number;
name: string;
slug: string;
}
export interface ApiResponse<T> {
success: boolean;
data?: T;
error?: string;
message?: string;
}
```
### package.json Dependencies
```json
{
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.0.0",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"vite": "^4.4.0",
"lucide-react": "^0.263.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"tailwind-merge": "^2.1.0"
},
"devDependencies": {
"@testing-library/react": "^14.0.0",
"@playwright/test": "^1.39.0",
"vitest": "^0.34.0",
"@vitejs/plugin-react": "^4.2.0"
}
}
```
### Lucide React Icons Usage
```tsx
import { Home, FileText, Settings, Search } from 'lucide-react';
// 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) {
return (
<article className="card">
<h2>{article.title}</h2>
<AuthorAvatar author={article.author} />
<CategoryBadge category={article.category} />
<FileText className="read-time-icon" />
</article>
);
}
```
**Header.tsx:**
```tsx
import { Home, FileText, Settings } from 'lucide-react';
interface HeaderProps {}
export function Header({}: HeaderProps) {
return (
<header className="nav">
<h1>newzy</h1>
<nav>
<a href="/"><Home /></a>
<a href="/articles"><FileText /></a>
<a href="/settings"><Settings /></a>
</nav>
</header>
);
}
```
### 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)
**components/ui/ (generic UI with icons):**
- Header.tsx → Navigation with lucide icons
- Layout.tsx → Page wrapper structure
**components/articles/ (domain-specific):**
- ArticleCard.tsx → Article preview component
- 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
- [ ] ArticleCard displays data properly
- [ ] Component props are type-safe
- [ ] Test coverage >50% on tested components
### 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)
- [ ] Article list renders with data
- [ ] Navigation between pages works via lucide icons
- [ ] API requests complete successfully via browser
- [ ] Browser console has no errors during E2E tests
- [ ] Tests use proper selectors and wait conditions
### Performance Considerations
- Vite uses ESBuild for fast HMR during development
- TypeScript checks on build, not incremental dev
- Nginx serves static files efficiently in production
- 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)
### Security Notes
- No sensitive data in client-side code
- API credentials should use backend proxy (not direct fetch)
- CORS must be configured on backend to accept frontend origin
- CSRF protection TBD for future milestones
- Playwright test artifacts (.vscode, traces) excluded from git
### Known Issues / Limitations
- No authentication flow implemented yet
- Static file serving requires nginx restart on rebuild
- 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
### Success Metrics
- `npm run dev` starts within 30 seconds
- `npm run build` produces <10MB production bundle
- TypeScript compilation completes under 5 minutes
- Docker frontend image size <200MB
- All ESLint rules pass with zero warnings in critical code
- Browser console has no errors on page load
- Unit tests achieve >=50% coverage on components
- 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