diff --git a/milestone/m3-setup-frontend-prompt.md b/milestone/m3-setup-frontend-prompt.md index 61c38c0..e18d90f 100644 --- a/milestone/m3-setup-frontend-prompt.md +++ b/milestone/m3-setup-frontend-prompt.md @@ -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 { } ``` -### API Client Configuration - -```typescript -// src/api/client.ts - -const API_BASE_URL = '/api'; - -async function fetchApi(endpoint: string): Promise> { - 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('/articles'), - getArticle: (id: number) => fetchApi
(`/articles/${id}`), - getCategories: () => fetchApi('/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 +
+ /* brand logo */ + } label="Home" /> + } label="Articles" /> + } label="Settings" /> + +
``` -**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.title}

+ + + +
+ ); } ``` -### 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 ( +
+

newzy

+ +
+ ); +} ``` -### 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 diff --git a/milestone/m3-setup-frontend-scoring.md b/milestone/m3-setup-frontend-scoring.md index 29c1a01..2d43ccd 100644 --- a/milestone/m3-setup-frontend-scoring.md +++ b/milestone/m3-setup-frontend-scoring.md @@ -4,31 +4,40 @@ | Score | Criteria | |-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 0 | Agent failed to implement acceptance criteria:
- No Vite/React project created
- TypeScript not configured
- Project structure missing key folders
- Components incomplete
- Missing tests (unit + E2E)
- Dockerfile or docker-compose missing | -| 1 | Agent partially implemented acceptance criteria that builds successfully:
- Basic React app with vite but no typescript
- Missing multiple required folders
- Components render but have errors
- npm scripts incomplete
- No test setup at all | -| 2 | Agent fully implemented acceptance criteria that builds successfully:
- Vite + React + TypeScript project in frontend/ folder
- All required directories (components/, pages/, types/, api/, tests/) created
- Article, Author, Category TypeScript interfaces defined
- Header and Home components created
- package.json scripts (dev, build, preview, test, e2e) working
- .gitignore excludes node_modules, dist/, IDE configs
- Playwright installed and configured | -| 3 | Agent fully implemented acceptance criteria that builds successfully, includes properly configured API client with error handling
- Types exported for all interfaces match backend models
- ESLint configuration present and passing- Header component rendering and props validation
- Home page loads and renders article layout
- API client error handling scenarios | -| 5 | Agent fully implemented acceptance criteria that builds successfully, includes all content from Score 4 AND:
- Playwright E2E tests in playwright/e2e/ passing successfully
- E2E tests verify homepage accessibility and API interactions
- Combined test coverage >60% across unit and E2E tests- No Vite/React project created
- TypeScript not configured
- Missing multiple required folders
- Components incomplete
- Missing tests (unit + E2E)
- Missing lucide-react icons
- No Dockerfile or docker-compose missing | +| 1 | Agent partially implemented acceptance criteria that builds successfully:
- Basic React app with vite but no lucide-icons
- Missing page/component separation
- Components render but have errors
- npm scripts incomplete
- No test setup at all | +| 2 | Agent fully implemented acceptance criteria that builds successfully:
- Vite + React + TypeScript project in frontend/ folder
- All required directories (assets/, components/, pages/, types/, api/, tests/) created
- lucide-react installed with core icons (Home, FileText, Settings, Search)
- Article, Author, Category TypeScript interfaces defined
- Header component with navigation placeholder and lucide icons- .gitignore excludes node_modules, dist/, IDE configs
- Playwright installed and configured | +| 3 | Agent fully implemented acceptance criteria that builds successfully, includes reusable article components created
- ArticleCard.tsx displays article data correctly- Header rendering and icon display50% on components | +| 5 | Agent fully implemented acceptance criteria that builds successfully, includes all content from Score 4 AND:
- Playwright E2E tests in playwright/e2e/ passing successfully60% across unit and E2E tests- TypeScript missing entirely -- **1 pt**: Basic React app created but structure incomplete
- Missing api/, types/, pages/ folders -- **2 pts**: Complete directory structure with all required folders (public/, src/, components/, pages/, types/, api/, tests/) +- **1 pt**: Basic React app created but structure incomplete
- Missing pages/, components/ separation +- **2 pts**: Complete directory structure with all required folders (public/, src/, assets/, components/, pages/, types/, api/, tests/) -### TypeScript Implementation (Max 3 points) -- **0 pts**: No TypeScript or tsconfig.json
- Plain JavaScript only +### TypeScript & Dependencies (Max 4 points) +- **0 pts**: No TypeScript or tsconfig.json
- lucide-react not installed - **1 pt**: TypeScript enabled but no type definitions
- Partial interfaces -- **2 pts**: Article, Author, Category interfaces properly defined
- Types used in components -- **3 pts**: Comprehensive types including ApiResponse, function signatures, validation +- **2 pts**: Article, Author, Category interfaces properly defined
- lucide-react with core icons imported correctly +- **3 pts**: Comprehensive types including ApiResponse, function signatures
- Proper type exports across modules +- **4 pts**: All type definitions validated and used in components- Application doesn't render -- **1 pt**: Only Header component created
- Home page incomplete -- **2 pts**: Header and Home components implemented correctly
- Components mount without errors -- **3 pts**: Reusable UI components (ArticleCard, AuthorAvatar, CategoryBadge) created +### UI Components (Max 5 points) +- **0 pts**: No UI components or Header missing
- Application doesn't render properly +- **1 pt**: Only Header component created
- Layout wrapper missing +- **2 pts**: Header and Layout components implemented with lucide icons- Routes not defined in App.tsx +- **1 pt**: Only Home page created- Cannot make requests to backend @@ -38,17 +47,18 @@ ### Unit Testing (Max 4 points) - **0 pts**: No Vitest or testing-library setup
- requirements.txt missing test dependencies - **1 pt**: Tests folder exists but no actual tests
- Test runner not configured in package.json -- **2 pts**: Vitest configured, Header.test.tsx created=50% coverage on tested components +- **2 pts**: Vitest configured, Header.test.tsx created=50% coverage on tested components- playwright.config.ts missing - **1 pt**: Playwright installed but no tests created
- npx playwright install not run - **2 pts**: playwright/e2e folder created with home.spec.ts and api.spec.ts- Cannot containerize frontend @@ -59,14 +69,15 @@ ### Code Quality (Max 2 points) - **0 pts**: No ESLint or linting fails
- Poor code organization - **1 pt**: Basic ESLint rules configured but warnings present
- Inconsistent formatting -- **2 pts**: ESLint passing with zero critical warnings
- Consistent code style, type hints on all functions +- **2 pts**: ESLint passing with zero critical warnings
- Consistent React + TypeScript best practices -### Documentation (Max 2 points) +### Documentation (Max 3 points) - **0 pts**: No README.md or incomplete
- No setup instructions -- **1 pt**: README exists with basic info only
- Missing examples -- **2 pts**: Comprehensive README with setup guide, API documentation, and usage examples | +- **1 pt**: README exists with basic info only
- Missing lucide-react documentation +- **2 pts**: Comprehensive README with setup guide, API documentation, and usage examples