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
This commit is contained in:
Daniel Samson committed 2026-10-29 15:56:43 +00:00
1 parent 85490bc0a2
commit b627ddc418
2 files changed
+255 -201

No files matched your search

+213 -170
View File
@@ -4,51 +4,70 @@
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:
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/
│ │ │ └── Header.tsx
│ │ │ ├── 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
│ │ │ ├── Home.tsx # Homepage with article feed layout
│ │ │ ├── ArticlePage.tsx # Individual article view (placeholder)
│ │ │ └── CategoriesPage.tsx # Categories listing page (placeholder)
│ │ ├── types/
│ │ │ └── index.ts
│ │ │ └── index.ts # TypeScript interfaces
│ │ ├── api/
│ │ │ └── client.ts
│ │ │ └── client.ts # API request wrapper
│ │ ├── tests/
│ │ │ ├── Header.test.tsx
│ │ │ ├── ArticleCard.test.tsx
│ │ │ └── components/
│ │ ├── App.tsx
│ │ └── main.tsx
│ │ ├── App.tsx # Root component with routing setup
│ │ └── main.tsx # React entry point
│ ├── playwright/
│ │ └── e2e/
│ │ ├── home.spec.ts
│ │ └── api.spec.ts
│ │ ├── home.spec.ts # E2E test for homepage
│ │ └── api.spec.ts # E2E test for API interactions
│ ├── .gitignore
│ ├── Dockerfile
│ ├── docker-compose.yml
│ ├── package.json
│ ├── docker-compose.yml # Frontend service config
│ ├── package.json # Include lucide-react dependency
│ ├── tsconfig.json
│ ├── vite.config.ts
│ └── README.md
│ └── README.md # Setup and API documentation
```
2. Initialize Vite project with React and TypeScript template:
2. Initialize Vite project with React, TypeScript template:
- Use Node.js 18 or later
- Install dependencies: react, react-dom, typescript, @types/react, @types/react-dom, vite, vitest (test runner)
- 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. Configure Vite with:
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
4. Install Playwright and configure for E2E testing:
- @playwright/test
- Run npx playwright install
- Configure paths in playwright.config.ts
- Tailwind CSS integration if applicable
5. Create TypeScript type definitions in `src/types/`:
- Article interface (id, title, content, author, category, published, createdAt)
@@ -56,71 +75,87 @@ Create the frontend infrastructure for **newzy** news web application using Reac
- Category interface (id, name, slug)
- API response types
6. Create React components:
- `Header.tsx` with logo and navigation placeholder
- `Home.tsx` page component for listing articles
- Reusable UI components (ArticleCard, AuthorAvatar, CategoryBadge)
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. Set up API client in `src/api/client.ts`:
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
8. Create component tests using Vitest in `src/tests/`:
- Test Header renders correctly
- Test Home page loads without errors
- Use react-dom/testing-library for rendering
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
9. Create Playwright E2E tests in `playwright/e2e/`:
- Test home page accessibility and layout
- Test article list renders with data
- Test API client makes requests correctly
11. Create Playwright E2E tests:
- Test home page accessibility and layout
- Test article list renders with data
- Test navigation between pages works
10. Create `package.json` scripts:
- dev: Development server
- build: Production build
- preview: Preview production build
- test: Run unit tests (vitest)
- e2e: Run Playwright E2E tests
- lint: ESLint check
12. Create `package.json` scripts:
- dev, build, preview, test, e2e, lint
11. Create `.gitignore` to exclude node_modules, dist/, .env files, IDE configs, playwright trace files
13. Create `.gitignore` to exclude node_modules, dist/, .env files, IDE configs, playwright trace files
12. Create `Dockerfile` for React + Vite with:
- Node.js base image
- Install dependencies
- Build frontend
- Nginx layer for serving static files in production
- Multi-stage build for optimization
14. Create `Dockerfile` with Nginx for serving static files in production (multi-stage)
13. Update `docker-compose.yml` at project root with frontend service:
15. Update `docker-compose.yml` at project root with frontend service:
- Port mapping 3000:80
- Links to backend service for API calls
14. Document setup process in `frontend/README.md` with examples
16. Document setup process in `frontend/README.md` with examples and lucide-react icon documentation
15. Configure ESLint rules in .eslintrc.cjs or vite.config.ts
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, type definitions, basic 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, 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 typed interfaces matching backend models, 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, 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 and TypeScript
- [ ] Project structure includes: public/, src/, components/, pages/, types/, api/, tests/ folders
- [ ] Playwright installed and configured for E2E testing
- [ ] 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 navigation placeholder
- [ ] Home page component rendering article listing layout
- [ ] 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
@@ -140,36 +175,46 @@ newzy/
│ │ └── index.html # Vite entry HTML file
│ ├── src/
│ │ ├── assets/
│ │ │ ├── styles.css # Global styles
│ │ │ └── logo.svg # Brand logo (placeholder)
│ │ │ ├── styles/
│ │ │ │ └── globals.css # Tailwind + global styles
│ │ │ └── logo.svg # Brand logo (placeholder)
│ │ ├── components/
│ │ │ └── Header.tsx # Main navigation header
│ │ ├── pages/
│ │ │ └── Home.tsx # Homepage with article feed
│ │ │ ├── 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
│ │ │ └── index.ts # TypeScript interfaces
│ │ ├── api/
│ │ │ └── client.ts # API request wrapper
│ │ ├── tests/
│ │ │ ├── Header.test.tsx # Component unit test
│ │ │ └── components/ # Additional component tests
│ │ ├── App.tsx # Root component
│ │ └── main.tsx # React entry point
│ │ │ └── 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/
│ │ ├── home.spec.ts # E2E test for homepage
│ │ └── api.spec.ts # E2E test for API interactions
│ │ └── 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
│ ├── 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
│ └── README.md # Setup and API documentation
├── backend/ # Backend from M2
├── LICENSE # MIT License
├── README.md # Main project docs
└── docker-compose.yml # Full application orchestration
├── README.md # Main project docs
└── docker-compose.yml # Full application orchestration
```
### TypeScript Type Definitions
@@ -185,7 +230,7 @@ export interface Article {
author?: Author;
categoryId: number;
category?: Category;
createdAt: string;
createdAt: Date | string;
published: boolean;
}
@@ -194,6 +239,7 @@ export interface Author {
name: string;
email: string;
bio?: string;
avatar?: string;
}
export interface Category {
@@ -210,119 +256,113 @@ export interface ApiResponse<T> {
}
```
### API Client Configuration
```typescript
// src/api/client.ts
const API_BASE_URL = '/api';
async function fetchApi<T>(endpoint: string): Promise<ApiResponse<T>> {
try {
const response = await fetch(`${API_BASE_URL}${endpoint}`);
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('API request failed:', error);
throw error;
}
}
export const apiClient = {
getArticles: () => fetchApi<Article[]>('/articles'),
getArticle: (id: number) => fetchApi<Article>(`/articles/${id}`),
getCategories: () => fetchApi<Category[]>('/categories'),
};
```
### package.json Scripts
### package.json Dependencies
```json
{
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint src/",
"test": "vitest",
"e2e": "playwright test"
"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"
}
}
```
### Dockerfile (Multi-stage Build)
### Lucide React Icons Usage
**Stage 1 - Build:**
```dockerfile
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
```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>
```
**Stage 2 - Serve:**
```dockerfile
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
```
### Component Structure Examples
### Nginx Configuration
```nginx
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
**ArticleCard.tsx:**
```tsx
import { Article } from '../types';
import { FileText } from 'lucide-react';
import AuthorAvatar from './AuthorAvatar';
import CategoryBadge from './CategoryBadge';
location / {
try_files $uri $uri/ /index.html;
}
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>
);
}
```
### docker-compose.yml (project root)
```yaml
version: '3.8'
**Header.tsx:**
```tsx
import { Home, FileText, Settings } from 'lucide-react';
services:
backend:
build: ./backend
ports:
- "8000:8000"
volumes:
- ./data/db:/app/data/db
environment:
- DATABASE_URL=sqlite:///./data/db/newzy.db
interface HeaderProps {}
frontend:
build: ./frontend
ports:
- "3000:80"
depends_on:
- backend
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>
);
}
```
### ESLint Configuration Rules
- No unused variables or imports
- TypeScript strict mode enabled
- Consistent indentation (2 spaces)
- No console.log in production code
- Prefer arrow functions for callbacks
### 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 component renders with correct structure
- [ ] Home page loads without TypeScript errors
- [ ] API client returns properly typed responses
- [ ] 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
@@ -330,7 +370,8 @@ services:
- [ ] 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 sample data
- [ ] 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
@@ -341,6 +382,7 @@ services:
- 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
@@ -366,3 +408,4 @@ services:
- 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