diff --git a/README.md b/README.md index 1be70fd..ff425db 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Kork & Krone -**Last updated:** 12 November 2026 -**Submission:** 3 (first complete prototype, beta) -**Status:** In progress. See [Status for submission 3](#status-for-submission-3). +**Last updated:** 16 November 2026 +**Submission:** 4 (working system, ready for feedback on every aspect) +**Status:** In progress. See [Status for submission 4](#status-for-submission-4). +| Continuous integration (CI) | Not yet started | Needs a self-hosted runner | ### What we want feedback on -Although the project is currently a bit behind schedule, we would still like relevant feedback on what is implemented and planned. - -Some suggested options are design and accessibility of the website, API design found in docs/api.md, architectural and technological choices, implemented and planned features and sustainability. +We would like feedback on anything, but these are the parts we are least sure about: +- The landing page: is it too much at once, and is the order of the sections right? +- Student reviews: half stars with the mouse and the keyboard, and whether the distribution is understandable. +- Accessibility, especially with a screen reader, which we have not tested with ourselves. +- Architectural and technological choices, and the API design in docs/api.md. ## Get started @@ -105,12 +106,12 @@ This section describes what users can do. "Backend" means the API supports the f | Sorting | Done | Done | Top rated, most rated, name and alcohol. Always sorts the whole result, not only the loaded page | | Pagination | Done | Done | Pages behind an opaque cursor that holds an offset. The user loads more results with a button, not with infinite scroll. Focus moves to the first new wine | | Search state in the URL | Not needed | Done | `?q=&type=&land=&drue=&mat=&vurdering=&alkohol=&sort=`. Survives reloads. Typing replaces the history entry, so the back button leaves the search instead of stepping through every word | -| Wine detail page | Done (`wine(id)`) | Done | Name, winery, region, grapes, alcohol, body, acidity, vintages and food pairing in Norwegian. Grapes and food link to the search. | +| Wine detail page | Done (`wine(id)`) | Done | Name, winery, region, grapes, alcohol, body, acidity, vintages and food pairing in Norwegian. Grapes and food link to the search | | Student reviews | Done | Done | 0.5–5 stars in half stars and an optional comment, stored in PostgreSQL. Hover the left half of a star for half a star, or use the arrow keys. The page updates at once without a reload. One review per student per wine | | Shared average and distribution | Done | Done | Student reviews count in the average together with X-Wines, also when sorting and filtering. The wine page shows how many gave each score | -| Wishlist ("Vil prøve") | Planned | Done, stored in the browser | Moves to the backend when users and reviews are in place | -| User | Done (Anonymous ID) | Done | An anonymous ID stored in browser until we have login (#29) | - +| Wishlist ("Vil prøve") | Planned | Done | Saved in the browser and shown on «Mine anmeldelser». Moves to the backend when login is in the interface | +| User accounts | Done | Planned | Register, login, logout and `me` in the API. Sessions in PostgreSQL with an `httpOnly` cookie. The interface comes next | +| Anonymous ID | Done | Done | Reviews use a random ID stored in the browser until login is in the interface | ## Architecture and technology choices @@ -137,18 +138,17 @@ Each row explains what we chose, why, and what else we considered. Added as the | Styling | CSS Modules and design tokens in `styles/tokens.css` | No runtime cost and no extra dependency. Tokens make dark mode and consistent colours easy | Tailwind, styled-components | | API | GraphQL with Apollo Server on Express | Required by the course. The client asks only for the fields it shows, which saves data | REST | | Database | PostgreSQL with the `pg_trgm` extension | Fast text search with `ILIKE` also on many rows. Already available on the VM | MongoDB, SQLite | +| Database changes | Migrations with node-pg-migrate | Everyone and the VM get the same database by running one command, without deleting and rebuilding it | Editing a single schema file by hand | | Pagination | GraphQL connection with an opaque cursor that holds an offset. Pages are merged in the Apollo cache | Simple, and works with every sort order. The frontend never reads the cursor, so we can switch to keyset pagination later without changing it | Keyset pagination: faster deep into large results, but harder to combine with many sort orders | | Search, filtering and sorting | In the database | Scales to large datasets. The frontend never loads the whole catalogue | Filtering in the browser | +| Rating average | Stored on the wine and recalculated when a review is saved or deleted | Sorting and filtering by rating never has to count millions of rows | Calculating the average for every query | +| Batched lookups | DataLoader for reviews and ratings per wine | A page of wines runs one query per field instead of one per wine (the N+1 problem) | One query per wine | | Search state flow | Field text in React state, debounced into the URL, and the query reads only the URL | One source of truth for the search, so reload, shared links and the back button all give the same result | Sending a request directly from the input | | Filter panel on small screens | Native `` with `showModal()` | The browser handles focus trapping, Escape and returning focus, with no extra JavaScript | A dialog library | | Filter counts | One count query per group that leaves out the group's own filter | The user can see what each choice gives before choosing, and values can be combined | Fixed counts for the whole catalogue | | Testing | Vitest, React Testing Library, Playwright, axe | Vitest shares configuration with Vite. Playwright tests real browsers, also on mobile | Jest, Cypress | | Deployment | Apache serves static files, the backend runs with `nohup` | Matches the course VM | systemd service (possible improvement) | - - See [API](docs/api.md) for the schema and example queries. ## Data @@ -211,8 +211,9 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing, - Semantic HTML: landmarks (`header`, `nav`, `main`, `footer`), one `h1` per page, lists for groups of cards, and `
` for each wine card. We try to use `div` and `span` only for layout. See [conventions](#code-quality-and-conventions). - A skip link to the main content, and visible focus on all interactive elements. - After navigation, focus moves to the page's `h1`. Screen reader users then hear that the page has changed. -- Ratings are always shown as text, for example "4,6 av 5 · 23 dommer". The die has a text alternative for screen readers. -- Loading states are announced in a live region. Errors use `role="alert"` and have a "Prøv igjen" button. +- Ratings are always shown as text, for example "4,6 av 5 · 23 dommer". The stars have a text alternative, so a screen reader reads «3,5 av 5 stjerner» instead of five images. +- Giving a review works with the keyboard: the stars are radio buttons, so the arrow keys move through every half star, and each half is at least 24 × 24 px to click (WCAG 2.5.8). +- Loading states are announced in a live region. Errors use `role="alert"` and have a "Prøv igjen" button. The message after saving a review stays in the same live region, so it is announced. - Click targets are at least 44 × 44 px. - Animations respect `prefers-reduced-motion`. - No horizontal scrolling at 320 px width (WCAG 1.4.10, reflow). @@ -226,8 +227,6 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing, - An automated test for reflow at 320 px. - Manual testing with only the keyboard. - - ### Some known gaps - We have not tested with a screen reader yet. @@ -249,6 +248,8 @@ We follow the principle from the course: measure, set a budget and show the numb - Code splitting per page with `React.lazy`. The landing page does not load the code for search and the detail page. - The landing page loads all its data in one GraphQL query, with only the fields it shows. An end-to-end test checks that only one request is sent. - Search, filtering, sorting and pagination run in the database. A page returns at most 50 wines. +- The rating average is stored on the wine, so no query counts millions of rows. +- DataLoader batches the lookups a page needs, so a page of wines runs one query per field instead of one per wine. - The Apollo cache, so we do not fetch the same data twice. - Debounce on the search field (300 ms). An end-to-end test checks that a whole word sends only one search. - Apache compresses HTML, CSS and JavaScript with gzip. The main JavaScript file goes from 435 kB to 136 kB. @@ -274,12 +275,12 @@ and because the test was run over VPN. These are the "before" numbers. Compressi | Level | Tools | What we test | Number of tests | |---|---|---|---| -| Unit and components (frontend) | Vitest, React Testing Library, user-event, vitest-axe | URL parameters, formatting, mapping of API data, data hooks, components, the landing page, loading, empty and error states, and axe on each component | 233 | -| Unit (backend) | Vitest | Parsing of X-Wines CSV files, and building SQL for search, filtering and sorting | 2 test files | +| Unit and components (frontend) | Vitest, React Testing Library, user-event, vitest-axe | URL parameters, formatting, mapping of API data, data hooks, components, the landing page, the wine page with reviews, the wishlist page, loading, empty and error states, and axe on each component | 269 in 28 files | +| Unit (backend) | Vitest | Parsing of X-Wines CSV files, building SQL for search, filtering and sorting, review validation, and passwords, sessions and rate limiting | 92 in 11 files (6 skipped: they need a test database) | | End-to-end | Playwright with axe-core, desktop and mobile | Landing, search and detail pages with a stubbed API: one request per page load, debounce, search, filters, sorting, load more, reload, back button, from search to wine and back, the filter dialog on mobile, no hits, wine not found, API errors, keyboard use, reflow at 320 px, and no axe violations (WCAG 2.1 AA) | 50 (24 tests in 2 browser projects, and 2 for mobile only) | | API | Not set up yet | Resolvers against a test database: search, filtering, sorting and pagination | Planned | -Counted on 7 November 2026. +Counted on 16 November 2026. The skipped backend tests run the user store against a real database, and need `TEST_DATABASE_URL`. **Coverage (frontend, 7 November 2026):** lines 98.93 %, branches 85.3 %, functions 97.14 %, statements 90.97 %. @@ -326,14 +327,16 @@ If git.ntnu.no has no CI runners, write that, and describe the alternative (for frontend/src/ app/ routes and the app shell components/ shared components (layout/ and ui/) - features/ one folder per feature: landing/, search/, ... + features/ one folder per feature: landing/, search/, wine/, my/ hooks/ shared React hooks lib/ pure functions and types styles/ design tokens and global CSS backend/src/ schema.ts GraphQL schema resolvers.ts GraphQL resolvers + loaders.ts DataLoader batching wine-query.ts builds the SQL for search, filtering and sorting + auth/ user accounts, passwords and sessions scripts/ import of X-Wines backend/migrations/ database migrations (node-pg-migrate) ``` @@ -349,11 +352,6 @@ backend/migrations/ database migrations (node-pg-migrate) - We always try to use the semantic element that exists for the purpose: `button`, `a`, `label`, `fieldset`, `ul`, `article`, `time` and so on. - `div` and `span` are only used for layout. If we use them where a semantic element could fit, a code comment should explain why. - - ## Use of AI We use AI tools as a sparring partner and as a code assistant. AI-generated code goes through the same review as other code, and we run and test it before it is merged. @@ -365,34 +363,35 @@ Claude and ChatGPT are the main models used. The usecases for the AI tools are a - Help with proper documentation - Help with keeping us in line with project guidelines - ## Plan ahead -### Next: complete the beta - -1. [x] Add Apollo Client to the frontend, with the endpoint `${import.meta.env.BASE_URL}graphql`. -2. [x] Search page: search field with debounce, list of results, number of hits, "Last inn flere", and empty and error states. -3. [x] Filter panel with counts from `filterOptions`, and sorting. All choices stored in the URL. -4. [x] Connect the landing page to the backend. -5. [x] Wine detail page. -6. [x] Start the backend on the VM and load the dataset. +### Next: towards the final submission -### Then: towards the next submission - -- [x] Student reviews: GraphQL mutation, database table, validation, and the new rating shown at once. -- [ ] Wishlist stored in the backend. -- [x] Larger dataset on the VM. -- [ ] Load test with the Full dataset. +- [ ] Login in the interface: forms for register and login, and reviews tied to the account instead of the anonymous ID. +- [ ] Wishlist stored in the backend, so it follows the user between devices. +- [ ] Calmer landing page: less text, a separate «Om» page, and a burger menu on mobile. - [ ] CI, an enforced coverage threshold, and eslint-plugin-jsx-a11y. - [ ] Measure sustainability and fill in the budget table. - [ ] Screen reader test and a written reflection on the use of AI. +- [ ] Prettier and ESLint in the backend, like in the frontend. + +### Done + +- [x] Search, filtering, sorting and pagination in the database, with the whole result set. +- [x] Wine detail page. +- [x] Student reviews: GraphQL mutation, database tables, validation, and the new rating shown at once. +- [x] Half stars, a shared average and the rating distribution. +- [x] «Mine anmeldelser» with the wishlist. +- [x] User accounts in the backend. +- [x] Database migrations. +- [x] Larger dataset on the VM. ### Some known issues -- Some documents in `docs/` still describe the old Vinmonopolet plan and the old test endpoint `/api/hello`. They will be updated. - Search matches the text as one phrase, so "noir pinot" finds nothing. Country is not part of the search text, because the country filter covers it. - The cursors in the API hold an offset, which is slower deep into large results. To be solved together with the larger dataset. -- `npm audit` reports warnings that all come from one dependency, `minimatch`: 7 moderate in the frontend through `typescript-eslint`, and 3 moderate in the backend through `node-pg-migrate`. Both are development tools. They never run in the browser or in the server that answers requests, and they are not part of what users download. The newest `typescript-eslint` (8.72.2) is still affected, so there is nothing to upgrade to, and `npm audit fix --force` would downgrade both packages to older versions instead. We ran the safe `npm audit fix`, which removed 2 of 12, and we watch for a real fix for the rest. +- The database and its user are still called `vinmonopolet` and `vinmonopolet_app`, from before we switched dataset. Renaming would mean everyone rebuilding their database, so we kept the names. +- Anyone can create any number of anonymous IDs, so there is nothing stopping someone from leaving many reviews. Login will fix that.