7 Commits
Author SHA1 Message Date
Daniel Samson afa399776f feat(admin): rebuild admin area around the Article domain
The admin area was managing a Hacker News-style Item model that the
public site never consumed, so the homepage always fell back to sample
data. Rebuild the admin area around the real public content model.

Backend:
- Remove the Item model, schema and admin API
- Admin API now manages articles at /api/v1/admin/articles (CRUD) with
  /api/v1/admin/authors and /api/v1/admin/categories reference data
- Add public read-only article endpoints (/api/v1/articles,
  /api/v1/articles/{id}): no auth, published-only, newest-first
- Rewrite Article schemas; ArticleRead embeds author and category
- Add idempotent seed_content.py dev seeder (3 authors, 4 categories,
  6 published articles)

Frontend:
- Admin UI rewritten around articles: AdminDashboard list, new
  EditArticlePage (create/edit, author/category selects, published
  toggle, Lexical editor, debounced auto-save)
- Replace AdminItem types and api client with the article domain
- Update App routes, AdminLayout sidebar, DeleteConfirmation, Lexical
  editor labels and Home/client comments to article terminology

Tests:
- Rewrite admin unit tests and the Playwright admin e2e spec for the
  article domain; add test_articles.py for the public endpoints and
  seeder
2026-10-31 18:31:05 +00:00
Daniel Samson e62fad4a10 fix: append parsed nodes when loading initial HTML into the Lexical editor
EditorShell's ingest called $generateNodesFromDOM but discarded the
returned nodes, so stored content never appeared in the WYSIWYG editor
in edit mode (the E2E edit test only checked title/points and missed it).
The parsed nodes are now appended to the root (kept empty-paragraph
default when nothing parses).

Hardening tests added while auditing the M6 test checklist:
- E2E: edit view asserts the stored body renders in the editor; new
  hostile-HTML test loads <script> tags, onerror/onload handlers and
  javascript: links through the real editor and asserts none survive
  into the contenteditable and nothing executes.
- E2E/unit: create button is disabled while the request is in flight.
- Backend: SQL metacharacters in the search term behave as literal
  text and leave the table intact.

Milestone doc updated: QA checklist items now cite their tests, plus a
QA-findings note for the ingest bug.
2026-10-30 21:58:23 +00:00
Daniel Samson b440809548 feat: add admin area with item CRUD, Lexical editor and access control (M6)
Backend:
- Item model (title, url, points, username, content, created_at)
- is_admin flag on User + startup migration for pre-existing DBs
- get_current_admin dependency (401 without/invalid token, 403 for
  non-admins); server-side check on every admin endpoint
- /api/v1/admin/items CRUD: pagination, case-insensitive title/url
  search, sort by title/created_at/points, in-memory rate limiting
  (1000 req/60s per admin -> 429)
- seed_admin.py (ADMIN_USERNAME/ADMIN_PASSWORD), documented in
  backend/.env.example

Frontend:
- Auth context exposes is_admin; RequireAdmin route guard (redirects
  signed-out users, renders 403 page for non-admins)
- AdminLayout with responsive dark sidebar; Admin link in header for
  admins only
- AdminDashboard: paginated table (page size 10/20/50), 300ms
  debounced search, sortable title/points/created_at columns,
  edit/delete row actions
- EditItemPage: create + edit with client-side validation and a
  Lexical (0.25) WYSIWYG editor (bold/italic/underline, H1-H6,
  lists, code blocks, links, undo/redo), optional debounced auto-save
- DeleteConfirmation modal with warning icon and explicit
  "Yes, delete" confirmation
- Unit tests (34) and mocked E2E workflow tests (10)

All acceptance criteria for milestones/m6-setup-admin-area-prompt.md
verified: 108 backend, 87 frontend unit and 29 E2E tests pass.
2026-10-30 21:36:15 +00:00
Daniel Samson b186d0f797 feat: add JWT authentication with auth pages and tests (M5)
Backend (FastAPI):
- core/auth.py: PBKDF2-HMAC-SHA256 password hashing (120k iterations,
  random salt), HS256 JWT creation/verification (7-day expiry,
  HN_SECRET_KEY via config) and get_current_user Bearer dependency
- models/user.py: User model (username unique/indexed, password_hash,
  created_at); schemas/auth.py: register/login/token/user schemas
- api/v1/auth.py: POST /api/v1/auth/register (201), /login, /logout
  (204), GET /me; 400 on duplicate username, 401 on bad credentials,
  invalid/expired/unknown tokens
- requirements: PyJWT; env templates + docker-compose expose
  HN_SECRET_KEY (dev default, override in production)
- tests: 24 new backend tests (hashing, tokens, all endpoints)

Frontend (React + TypeScript):
- api/client.ts: AUTH_TOKEN localStorage persistence, automatic
  Bearer token attachment, 401 clears the stored token, typed
  login/register/logout/me helpers
- auth.tsx: AuthProvider (session restore + login/register/logout)
  and RequireAuth route guard
- pages: Login, Register, SignOut and a protected /account
  placeholder; header shows sign-in/register or user/sign-out
- styles: auth component classes in globals.css
- tests: unit tests for the client, provider and pages; Playwright
  E2E spec covering register/login/logout, session restore, invalid
  token cleanup and protected-route redirects (API mocked)

Note: the milestone's /api/auth/* paths map to the project's
established /api/v1/* prefix (see M2); the HN_SECRET_KEY default is
newzy-dev-secret-change-me.
2026-10-30 17:03:00 +00:00
Daniel Samson ed7b30438e feat: add Docker Compose developer environment with Makefile shortcuts (M4)
- Root docker-compose.yml: backend (python:3.11-slim) + frontend
  (multi-stage node build -> nginx:alpine) on the newzy-network bridge
  network, frontend waits for the backend health check
- Persistent SQLite via bind mount ./data/db -> /app/data/db
- .env / .env.example documenting DATABASE_URL, DEBUG,
  BACKEND_CORS_ORIGINS and FRONTEND_API_URL
- Makefile: dev, stop, restart, build, logs, status, backend-start,
  frontend-start, test, e2e, shell-backend, shell-frontend, clean
- data/.gitignore keeps the data/ structure in git while excluding the
  database; root .gitignore drops the overly broad data/ rule and adds
  docker-compose.override.yml
- backend: .gitignore covers .env.*, Dockerfile sets unbuffered python
  and pre-creates the db volume dir; frontend: new .dockerignore
- README: full Docker setup docs (prerequisites, quick start, services,
  ports, network/storage, env vars, Makefile reference, troubleshooting)
2026-10-30 15:35:08 +00:00
Daniel Samson 9144411e0f fix: track frontend sample data hidden by overly broad data/ ignore rule
frontend/src/data/sample.ts (imported by Home/CategoriesPage) was never
committed because the root .gitignore ignored every path named data/.
A fresh clone would have failed the frontend build.
2026-10-30 15:34:50 +00:00
Daniel Samson ffe19272b3 feat: add React + TypeScript frontend with Vite, routing, tests and Docker setup
M3 frontend infrastructure for the newzy news application:

- Vite + React 18 + TypeScript project (Node >=18) in frontend/
- React Router v6: BrowserRouter in App.tsx, routes for /, /articles,
  /articles/:id and /categories, Link/NavLink-based navigation
- lucide-react icons (Home, FileText, Settings, Search, ...) in the
  responsive Header (desktop + mobile menu) and article components
- Reusable components: ArticleCard, AuthorAvatar, CategoryBadge (CVA),
  Layout shell with backend API status indicator in the footer
- Typed API client (fetch wrapper, ApiError, endpoint helpers) with
  types matching the backend models; sample-data fallback until the
  backend article endpoints exist
- Tailwind CSS global/component styles, cn() helper (clsx + tailwind-merge)
- Unit tests: Vitest + React Testing Library (23 tests, 100% statement
  coverage on components)
- E2E tests: Playwright (9 tests) covering page shell, feed rendering,
  client-side navigation, article route and API interactions
- ESLint (react + react-hooks + typescript) configured and passing
- Multi-stage Dockerfile (Vite build -> Nginx) with SPA fallback and an
  /api/ proxy to the backend service; docker-compose frontend service on
  port 3000 in both frontend/ and the root docker-compose.yml
- README with setup, API documentation, testing and Docker instructions
2026-10-30 14:10:29 +00:00