# 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 React Router 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 react-router-dom 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 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: - @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 - 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) - 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 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 via routing-aware navigation - 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 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. 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 12. Create Playwright E2E tests: - Test home page accessibility and layout - Test article list renders with data - Test navigation between pages works (via React Router Links) 13. Create `package.json` scripts: - dev, build, preview, test, e2e, lint 14. Create `.gitignore` to exclude node_modules, dist/, .env files, IDE configs, playwright trace files 15. Create `Dockerfile` with Nginx for serving static files in production (multi-stage) 16. Update `docker-compose.yml` at project root with frontend service: - Port mapping 3000:80 - Links to backend service for API calls 17. Document setup process in `frontend/README.md` with examples and lucide-react icon documentation 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, 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, 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, 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) - [ ] 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 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 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 - [ ] 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 for react-router best practices ## 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 and router Links │ │ │ │ └── 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 BrowserRouter and routes │ │ └── 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 react-router-dom │ ├── 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 { success: boolean; data?: T; error?: string; message?: string; } ``` ### package.json Dependencies ```json { "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", "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" } } ``` ### React Router Configuration in App.tsx ```tsx 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'; function App() { return ( } /> } /> } /> ); } export default App; ``` ### Header Component with React Router Links ```tsx import { Home, FileText, Settings } from 'lucide-react'; import { Link } from 'react-router-dom'; interface HeaderProps {} export function Header({}: HeaderProps) { return (

newzy

); } ``` ### Page Separation Strategy **pages/ (routing - one per route):** - `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 AND React Router `` components - `Layout.tsx` → Page wrapper structure accepting props from App routes **components/articles/ (domain-specific):** - `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 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 ### 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 for Links) - [ ] Article list renders with data - [ ] 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 for routing elements ### 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) - React Router uses client-side navigation (no page reloads) ### 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 - React Router state preservation not implemented ### 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 - React Router navigation works without full page reloads