Files
news-benchmark/milestone/m3-setup-frontend-prompt.md
T
Daniel Samson 85490bc0a2 feat: update M2/M3 milestones to include testing infrastructure
M2 (Backend):
- Add tests/ folder with pytest test files
- Add pytest.ini for test configuration and coverage
- Update scoring to require unit tests (Score 4+)

M3 (Frontend):
- Add tests/ folder with Vitest component unit tests
- Add playwright/e2e/ folder with E2E Playwright tests
- Add @playwright/test dependency and configuration
- Update scoring to require both unit and E2E tests (Score 5)

README.md updated with all milestone links and test requirements
2026-10-29 15:54:10 +00:00

12 KiB

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:

    newzy/
    ├── frontend/
    │   ├── public/
    │   ├── src/
    │   │   ├── components/
    │   │   │   └── Header.tsx
    │   │   ├── pages/
    │   │   │   └── Home.tsx
    │   │   ├── types/
    │   │   │   └── index.ts
    │   │   ├── api/
    │   │   │   └── client.ts
    │   │   ├── tests/
    │   │   │   ├── Header.test.tsx
    │   │   │   └── components/
    │   │   ├── App.tsx
    │   │   └── main.tsx
    │   ├── playwright/
    │   │   └── e2e/
    │   │       ├── home.spec.ts
    │   │       └── api.spec.ts
    │   ├── .gitignore
    │   ├── Dockerfile
    │   ├── docker-compose.yml
    │   ├── package.json
    │   ├── tsconfig.json
    │   ├── vite.config.ts
    │   └── README.md
    
  2. Initialize Vite project with React and TypeScript template:

    • Use Node.js 18 or later
    • Install dependencies: react, react-dom, typescript, @types/react, @types/react-dom, vite, vitest (test runner)
  3. 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
  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 React components:

    • Header.tsx with logo and navigation placeholder
    • Home.tsx page component for listing articles
    • Reusable UI components (ArticleCard, AuthorAvatar, CategoryBadge)
  7. 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
  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
  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
  11. 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
  13. 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

  15. Configure ESLint rules in .eslintrc.cjs or vite.config.ts

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.

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).

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
  • TypeScript type definitions for Article, Author, Category models
  • Header component created with navigation placeholder
  • Home page component rendering article listing 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.css   # Global styles
│   │   │   └── logo.svg     # Brand logo (placeholder)
│   │   ├── components/
│   │   │   └── Header.tsx    # Main navigation header
│   │   ├── pages/
│   │   │   └── Home.tsx      # Homepage with article feed
│   │   ├── types/
│   │   │   └── 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
│   ├── 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
│   ├── 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

// src/types/index.ts

export interface Article {
  id: number;
  title: string;
  content: string;
  authorId: number;
  author?: Author;
  categoryId: number;
  category?: Category;
  createdAt: string;
  published: boolean;
}

export interface Author {
  id: number;
  name: string;
  email: string;
  bio?: string;
}

export interface Category {
  id: number;
  name: string;
  slug: string;
}

export interface ApiResponse<T> {
  success: boolean;
  data?: T;
  error?: string;
  message?: string;
}

API Client Configuration

// 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

{
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview",
    "lint": "eslint src/",
    "test": "vitest",
    "e2e": "playwright test"
  }
}

Dockerfile (Multi-stage Build)

Stage 1 - Build:

FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

Stage 2 - Serve:

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;"]

Nginx Configuration

server {
    listen 80;
    server_name localhost;
    
    root /usr/share/nginx/html;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

docker-compose.yml (project root)

version: '3.8'

services:
  backend:
    build: ./backend
    ports:
      - "8000:8000"
    volumes:
      - ./data/db:/app/data/db
    environment:
      - DATABASE_URL=sqlite:///./data/db/newzy.db

  frontend:
    build: ./frontend
    ports:
      - "3000:80"
    depends_on:
      - backend

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

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
  • 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 sample data
  • 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

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