diff --git a/.vscode/extensions.json b/.vscode/extensions.json index ff7b3ae9..c63b244e 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,6 +5,7 @@ "dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "YoavBls.pretty-ts-errors", - "bradlc.vscode-tailwindcss" + "bradlc.vscode-tailwindcss", + "yzhang.markdown-all-in-one" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 9fddbe2d..46cbb2a5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,12 @@ { - "js/ts.preferences.importModuleSpecifier": "non-relative" + "js/ts.preferences.importModuleSpecifier": "non-relative", + "cSpell.words": [ + "configtest", + "enconf", + "enmod", + "Goodreads", + "ntnu", + "Readr", + "usermod" + ] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bba548bb..89c6ed4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,27 @@ -# Contributing to Readr +# Contributing to Readr + +- [Overview](#overview) +- [Git usage](#git-usage) + - [Commits](#commits) + - [Branches](#branches) +- [Creating issues](#creating-issues) +- [Code style](#code-style) + - [Function definitions](#function-definitions) + - [Exports](#exports) + - [Generated files](#generated-files) + - [Lucide icons](#lucide-icons) + - [SQL Code](#sql-code) +- [Components](#components) + - [Folder structure](#folder-structure) + - [Definitions](#definitions) +- [VS Code Extensions](#vs-code-extensions) + - [Documentation tables of contents](#documentation-tables-of-contents) +- [Pull requests](#pull-requests) + - [Checklist beforehand](#checklist-beforehand) + - [Creating a pull request](#creating-a-pull-request) +- [Working in this repository](#working-in-this-repository) + +## Overview Thank you for contributing to the project! We appreciate all issues, pull requests and other comments regarding the project. @@ -223,10 +246,17 @@ Recommended extensions (in alphabetical order): - [Auto Rename Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag) - [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) - [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) +- [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) - [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - [Pretty TypeScript Errors](https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors) - [Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss) +### Documentation tables of contents + +The table of contents of a documentation file MUST be updated when its headings change. Markdown All in One does this when you save the file, so installing it is RECOMMENDED. + +Headings that should not be in the table of contents, such as the page title, SHOULD be marked with ``. + ## Pull requests ### Checklist beforehand diff --git a/README.md b/README.md index cfb270ee..e4c76e81 100644 --- a/README.md +++ b/README.md @@ -49,13 +49,13 @@ Check out [CONTRIBUTING.md](./CONTRIBUTING.md) for further details regarding cod - Tech stack and tool choices, discussions and reasoning behind the decisions - [Infrastructure](./docs/infrastructure.md) - Describes our infrastructure and how it works in practice -- [Deployment](/docs/deployment.md) +- [Deployment](./docs/deployment.md) - How the app is deployed on the provided VM -- [Sustainability](/docs/sustainability.md) +- [Sustainability](./docs/sustainability.md) - More about how we've kept sustainability in mind when developing the application -- [Accessibility](/docs/accessibility.md) +- [Accessibility](./docs/accessibility.md) - What steps we've taken to make the app accessible to everyone -- [AI documentation](/docs/ai-documentation.md) +- [AI documentation](./docs/ai-documentation.md) - How AI was used during development - [AGENTS.md](./AGENTS.md) - Instructions for AI agents working in this repository, with [CLAUDE.md](./CLAUDE.md) and [.claude](./.claude/) for Claude Code diff --git a/backend/README.md b/backend/README.md index 32d9a0c4..bbe88f2c 100644 --- a/backend/README.md +++ b/backend/README.md @@ -1,11 +1,25 @@ -# Readr - backend +# Readr - backend + +- [Getting started](#getting-started) + - [Install PostgreSQL](#install-postgresql) + - [Linux](#linux) + - [Windows](#windows) + - [MacOS](#macos) + - [Set the environment variables](#set-the-environment-variables) + - [Download the dataset](#download-the-dataset) + - [Set up the database](#set-up-the-database) + - [Use the database](#use-the-database) + - [After changing the database schema](#after-changing-the-database-schema) +- [Run the backend](#run-the-backend) +- [Testing the API](#testing-the-api) +- [GraphQL types](#graphql-types) ## Getting started This guide assumes you have set up `pnpm` and have a running frontend app. If not, please follow the frontend guide in the [README.md for the frontend](../frontend/README.md) first. -### Installing PostgreSQL +### Install PostgreSQL As we do not use Docker, a local installation of PostgreSQL will be required. @@ -46,7 +60,7 @@ The simplest way to install Postgres on MacOS is to use [homebrew](https://brew. brew install postgresql@18 ``` -### Setting the environment variables +### Set the environment variables Start by copying the [.env.example](./.env.example) to `.env`: @@ -64,7 +78,7 @@ Proceed to do the following: - Create and insert the Discord client ID and client secret: - This can be done by creating an application in [Discord's Developer Portal](https://discord.com/developers/applications) -### Downloading the book dataset +### Download the dataset The book dataset is quite large (~70 MB), so we prefer to not keep it inside the Git repository. @@ -85,7 +99,7 @@ After downloading: Now you're ready to insert the data to the database! -### Setting up the database +### Set up the database Copy the `.env.example` file and create your own, private and gitignored version: @@ -96,7 +110,7 @@ cp .env.example .env The default values work fine for local development. -### Using the database +### Use the database When running the database and backend, please go into the backend folder using `cd backend`. @@ -137,7 +151,7 @@ pnpm db:generate --name [short_migration_name] > If you need to test changes locally, use `pnpm db:setup` to start a completely new database immediately, > or use `pnpm db:push` to add changes to a database that is running already. -## Running the backend along with the frontend +## Run the backend Make sure the frontend is running in another terminal window or background process. @@ -185,7 +199,7 @@ that users must be logged in, and only see their own favorites). > The test database is very small, so the tests do not check or verify the performance of our database. > This is rather done by careful planning of indexes and checking the results of `EXPLAIN` queries to see if indexes and efficient strategies are used. -## GraphQL automatically generated types +## GraphQL types Whenever you change the GraphQL schema in the folder [./src/schema](./src/schema/), please run the following command: diff --git a/docs/accessibility.md b/docs/accessibility.md index 89a3dfe0..ad3e7d28 100644 --- a/docs/accessibility.md +++ b/docs/accessibility.md @@ -1,4 +1,9 @@ -# Accessibility +# Accessibility + +- [What we do well](#what-we-do-well) +- [Pointer cursor](#pointer-cursor) +- [Automatic testing](#automatic-testing) +- [Limitations and future work](#limitations-and-future-work) ## What we do well @@ -20,13 +25,13 @@ - **Responsive layout.** The book grid goes from four columns to one as the screen gets narrower, and the book page stacks vertically on small screens, so the app can be used on phones. -## Pointer cursor on interactive elements +## Pointer cursor Tailwind CSS v4 changed buttons to use `cursor: default` instead of `cursor: pointer`. We have deliberately chosen to keep the pointer cursor, which differs from the shadcn defaults. We have added cursor-pointer to the relevant shadcn class names. A pointer cursor is a visual signal that an element can be clicked. Using it consistently on every button and dropdown item makes it easier to see what is interactive and avoids some elements looking like they cannot be clicked. Consistent cursors make the interface more predictable, which fits the WCAG principle that components should behave in a consistent way. Because the cursor only helps people who use a mouse, it is only one part of our accessibility work, and we also follow the other accessibility requirements described in this document. -## Automatic testing using Playwright +## Automatic testing We use [Playwright](https://playwright.dev/) to perform automatic accessibility checks. @@ -46,7 +51,7 @@ We're glad to share that we pass the automatic Playwright checks for all of the Testing all of the WCAG requirements is difficult, and Playwright only tests for a subset of these. We have rectified multiple issues highlighted by Playwright. -## Limitations/Future work +## Limitations and future work This section is meant as an overview of potential improvements with regard to accessibility, and also shows that we are aware of the downsides of our implementation. The table has a column for the status at delivery 3, and the same table will be used to show what work has been done from delivery 3 to 4. @@ -57,5 +62,5 @@ This section is meant as an overview of potential improvements with regard to ac | An error when loading books is announced with `role="status"`, which screen readers may read later or not at all. | Use `role="alert"` for errors, and keep `role="status"` for loading and empty results. | Not done | Done. Errors when loading books, genres and favorites now use `role="alert"`. | | There is no "Skip to main content" link, so keyboard users have to tab through the header on every page. | Add a skip link as the first focusable element. | Not done | Done. A "Skip to main content" link is the first focusable element on every page, and is shown when it gets focus. | | Animations, such as the cover zooming in on hover, don't respect the user's setting for reduced motion. | Turn off these animations with Tailwind's `motion-reduce:` variant. | Not done | Done. The cover zoom uses `motion-safe:`, like the animations on the home page, and changing page scrolls to the top without animation when the user prefers reduced motion. | -| We have not tested the app with automatic tools, and color contrast has not been measured. | Run Lighthouse and axe on all pages. | Not done | Done. Lighthouse, which uses axe for its accessibility checks, gives 100 on all pages after we made `--muted-foreground` darker (the breadcrumb links were 4.29:1). See the [Lighthouse results](/docs/sustainability.md#lighthouse). | +| We have not tested the app with automatic tools, and color contrast has not been measured. | Run Lighthouse and axe on all pages. | Not done | Done. Lighthouse, which uses axe for its accessibility checks, gives 100 on all pages after we made `--muted-foreground` darker (the breadcrumb links were 4.29:1). See the [Lighthouse results](./sustainability.md#lighthouse). | | We have not tested the main flows with only a keyboard or with a screen reader. | Test the main flows with only a keyboard and with a screen reader (VoiceOver or NVDA). | Not done | Done. We tabbed through every page: the order follows the layout, and every element shows a focus ring. Playwright tests search, filter, sort, opening a book, saving it as a favorite and going back using only the keyboard. Testing with a screen reader is done manually, and showed links being read correct, tabs listed (e.g. "tab 1 out of 3"), etc. | diff --git a/docs/ai-documentation.md b/docs/ai-documentation.md index 39a41e5f..492f4ac8 100644 --- a/docs/ai-documentation.md +++ b/docs/ai-documentation.md @@ -1,4 +1,14 @@ -# Use of AI in this project +# Use of AI in this project + +- [Overview](#overview) +- [How we keep humans in the loop](#how-we-keep-humans-in-the-loop) +- [Shared context for AI agents](#shared-context-for-ai-agents) +- [Learning and AI](#learning-and-ai) +- [Code quality](#code-quality) +- [LLM restrictions](#llm-restrictions) +- [Examples of rejecting AI advice](#examples-of-rejecting-ai-advice) + +## Overview We have used Claude (through Claude Code) as a tool during development. In short, it was used for: @@ -44,7 +54,7 @@ Furthermore, if used correctly, AI can be used to help explain concepts when you No matter whether the code was written manually or using help from LLMs, all issues and pull requests must have a proper description, as required by our [CONTRIBUTING.md](../CONTRIBUTING.md) file. This forces all group members to explain their thought process, reasoning for their code, and makes it obvious if someone does not understand the code at all. Fortunately, we have not had such issues in our group, and practically all pull requests have had coherent descriptions which are easy to understand. -## Code generated by AI is quality-checked in the same strict way as all other code +## Code quality All code that LLMs (and humans) write should be checked by ESLint, Prettier and our Vitest tests and E2E tests before pushing to git. Furthermore, we have checks in CI (GitHub Actions) which run all of these, excluding the E2E tests (see the [project choices and reasoning documentation](./choices-and-reasoning.md) for further details). @@ -52,7 +62,7 @@ These checks confirm whether the code passes these strict requirements, and if i Some things cannot be checked automatically, such as some of the practices described in our [CONTRIBUTING.md](../CONTRIBUTING.md) file, so after the automatic checks, we still perform human review on all pull requests. In order for a pull request to be merged, all conversations must be resolved, and it needs at least one explicit approving review. -## LLMs are unpredictable - and their access is restricted based on that +## LLM restrictions The LLMs used by our group do not have access to run any write operations using git. This means no automatic committing, pushing or otherwise adding code that has not been quality checked. Furthermore, the LLMs only have access to the fewest tools they need to get the job done. That means reading and editing only the files they need, and performing only the terminal commands that are needed. diff --git a/docs/choices-and-reasoning.md b/docs/choices-and-reasoning.md index 4188fc52..d83d7bb9 100644 --- a/docs/choices-and-reasoning.md +++ b/docs/choices-and-reasoning.md @@ -1,4 +1,26 @@ -# Readr - project choices and reasoning +# Project choices and reasoning + +- [Overview](#overview) +- [PostgreSQL as the database](#postgresql-as-the-database) +- [Drizzle ORM](#drizzle-orm) + - [Drizzle vs Prisma](#drizzle-vs-prisma) +- [GraphQL Codegen](#graphql-codegen) +- [Authentication (better-auth)](#authentication-better-auth) +- [Search state in the URL](#search-state-in-the-url) +- [Pagination](#pagination) +- [Missing ratings](#missing-ratings) +- [Sorting](#sorting) + - [Rating sort filter](#rating-sort-filter) + - [No author sorting](#no-author-sorting) +- [Suggest similar titles](#suggest-similar-titles) +- [Genre selection](#genre-selection) +- [UI components: shadcn/ui on top of Base UI](#ui-components-shadcnui-on-top-of-base-ui) +- [Filter design](#filter-design) +- [Only relevant filter options](#only-relevant-filter-options) +- [E2E testing](#e2e-testing) +- [Specification changes](#specification-changes) + +## Overview Some parts of the stack were given by the course: React with TypeScript and Vite, a GraphQL backend, and our own database running directly on the VM without Docker. The choices below are the ones we made ourselves. @@ -9,13 +31,13 @@ We ended up doing some things differently - this is described at the end of this Our data can be modeled using relations: books belong to many genres, and users have favorites that point to books. PostgreSQL handles this well with foreign keys and joins, and supports case-insensitive search with `ILIKE`. It is also one of the most used databases in real production applications, comfortably handling hundreds of thousands to millions of records (i.e. SQL rows in the tables). -## Drizzle ORM and migrations +## Drizzle ORM We define the database schema in TypeScript with [Drizzle](https://orm.drizzle.team/), which gives us type-checked queries in the resolvers in the Apollo Server backend. -### The (seemingly) difficult choice: Drizzle ORM vs Prisma ORM +### Drizzle vs Prisma -Drizzle is not yet fully released - v1 is a release candidate. Therefore, some changes could still happen, but they are less likely compared to a beta version. +Drizzle ORM is not yet fully released - v1 is a release candidate. Therefore, some changes could still happen, but they are less likely compared to a beta version. There is also another ORM that's popular in the Node.js community, namely Prisma ORM. We have decided to go with Drizzle ORM. Let's explain why. @@ -40,15 +62,15 @@ In general, Drizzle ORM has worked great for Readr. We generate TypeScript types from our GraphQL schema for both the backend resolvers and the frontend queries. If the schema changes, type errors show us every place that needs to be updated. -## better-auth for user accounts +## Authentication (better-auth) better-auth stores users and sessions in our own PostgreSQL database through its Drizzle adapter, and gives us email/password login as well as GitHub and Discord login with little code. We added user accounts because favorites (and later reviews) are user-generated data that should be stored on our server. Our first version stored favorites in `localStorage`, which meant they only existed in one browser. With accounts, the data belongs to a user and follows them across devices. -## The URL holds the search state +## Search state in the URL The search text, filters, sorting and page number are stored in the URL (`?q=...&genres=...&sort=...&page=...`) instead of in component state. This means a search can be shared as a link, survives a page reload, and the browser's back button works as expected. Together with Apollo Client's cache for data from the server, this covers our need for state management without a separate global store. -## Pagination with page numbers +## Pagination Search results are fetched 12 at a time with `limit` and `offset`, together with the total number of matches (`totalCount`). Filtering, sorting and counting happen in the database, so the client never loads more than one page, no matter how large the dataset is. This lets us show page numbers and the number of results, and any page can be opened directly from the URL (`?page=40`), for example from a shared link. @@ -56,7 +78,7 @@ We chose offset pagination based on how we expect the app to be used. Most users Keeping the first pages fast depends on database indexes. We have added indexes on the columns we sort by (number of ratings, rating, title, pages and publish year), on the language and book format filters, and trigram indexes for the search on title and author (see `backend/src/db/schema/books.ts`). If the dataset grows much larger, the total count could be capped or estimated instead of counting every match. -## Books without ratings are stored as NULL +## Missing ratings The dataset uses a rating of 0.0 for books nobody has rated. We store these as `NULL` instead, so they aren't treated as the worst-rated books, and they are placed last when sorting by rating. @@ -66,7 +88,7 @@ The search results can be sorted by relevance (the default), rating, title, publ Relevance shows the books with the most ratings first, so well-known books come before books that few people have rated. When a search has no exact matches and we show books with similar titles or authors instead, the closest match comes first. -### Sorting by highest rating adds a minimum number of ratings +### Rating sort filter When the user chooses "Rating: high to low", we also add the filter "10,000+ ratings", unless the user has already chosen a minimum number of ratings. A toast tells the user that the filter was added, and that it can be changed in the filters. @@ -74,11 +96,11 @@ Without a minimum, this sort order is not very useful. More than 800 books in ou We discussed whether a filter that is chosen for the user is more annoying than useful (#117). We kept it because it is easy to notice and easy to remove: the toast explains it, the filter button shows how many filters are active, and the minimum can be set back to "Any". We also never replace a minimum that the user has chosen. The filter stays when the user switches to another sort order, since filters and sorting are independent everywhere else. -### No sorting by author +### No author sorting We do not offer sorting by author (#100). The author field in the dataset is free text and can hold several names, like "Author One, Author Two". We have no guarantee that the authors of a book are always listed in the same order, or whether a name is written as "First Last" or "Last, First", so sorting on this field would often give an order that looks random. Authors can be found with the search field instead, which searches both titles and authors. -## A search without results only suggests similar titles +## Suggest similar titles When a search has no results, we look for books with a title or author that is similar to the search text, and show those with a text that explains why. This helps with typos: "Lord fo the rings" finds The Lord of the Rings. If nothing is similar, or the user has only used filters, we show that no books were found, with a hint to check the spelling and a button that resets the filters when some are active. @@ -95,7 +117,7 @@ Similar titles are found with the `pg_trgm` extension in PostgreSQL, which compa So the suggestions help with one typo in a longer search, but not with several typos or a typo in a short word. A lower threshold would catch more typos, but it also risks showing "similar" books for searches that have nothing to do with them, which is what we wanted to get rid of. We have kept the default, and a typo that is not caught gets the hint to check the spelling instead. -## Selecting several genres shows books in any of them +## Genre selection When several genres are selected, we show books that belong to at least one of them (OR), not all of them (AND). This is because it widens the search instead of quickly ending up with no results. @@ -103,7 +125,7 @@ When several genres are selected, we show books that belong to at least one of t Base UI provides accessible components (keyboard navigation, focus handling and ARIA attributes), and shadcn/ui gives us styled versions whose code lives in our repository, so we can adjust them to our needs. We use Tailwind CSS for styling, which replaced our CSS module files. -## Design of book filters +## Filter design The filters were first placed in a popover, with several of the filters being dropdowns inside it. This meant opening one menu right on top of another which was awkward to use and harder for keyboard and screen reader users to navigate. We tried a drawer which reduced the problem, but the dropdowns still opened inside it, so the double layer remained for both mobile and desktop users. @@ -123,7 +145,7 @@ The options are counted in the database by the `bookFacets` query. It takes the Without a search or filters, the counts for all books are computed once and cached, like the lists on the home page. We measured `bookFacets` on the whole dataset (52,478 books): narrow searches take a few milliseconds, and the broadest search we tried (the letter "a", which matches almost every book) about 55 ms, in the same range as `searchBooks` itself. We therefore didn't add any more caching. -## Playwright E2E testing +## E2E testing We use [Playwright](https://playwright.dev/) to run end-to-end (E2E) tests. @@ -146,7 +168,7 @@ How many workers a machine can handle differs, so one worker gives the same resu We do not use CI for E2E tests. Our VM only has 1 CPU core available and the tests take a very long time. They also slow down our app, which is running on the same server. Instead, we use CI for other tasks, such as linting and formatting. -## Changes/not implemented yet from our specification +## Specification changes - **Filters:** We filter on genres, language, book format, number of pages and a minimum number of ratings. The specification also mentioned author, publisher, place and person. Authors are covered by the search field, which searches both titles and authors, and we have not implemented filters for publisher, place and person. The dataset has columns for these: `publisher`, `setting` (places) and `characters` (persons). `publisher` is filled in for 93% of the books, but `setting` and `characters` only for 22% and 26%, so filters on those two would leave out most of the books. - **Login:** Instead of Google login, we support email/password and GitHub and Discord login. Google was rejected since it required https connection, which we do not provide. diff --git a/docs/deployment.md b/docs/deployment.md index ca4f330f..4eb70d78 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -1,4 +1,19 @@ -# Deployment +# Deployment + +- [Overview](#overview) +- [Install dependencies](#install-dependencies) +- [Set up the project](#set-up-the-project) + - [Environment variables](#environment-variables) + - [Build the frontend](#build-the-frontend) + - [Build the backend](#build-the-backend) + - [Prepare the database](#prepare-the-database) + - [Apply migrations](#apply-migrations) +- [Run the project](#run-the-project) +- [VM setup](#vm-setup) + - [Install packages](#install-packages) + - [Set up Apache config](#set-up-apache-config) + +## Overview We have been provided with a virtual machine running Ubuntu 26.04 LTS. Following the project requirements, we will not be using Docker. @@ -35,7 +50,7 @@ source .profile This will ensure that the PostgreSQL binaries and binaries installed with pnpm (like pm2) are added to PATH. -## Clone the project and set it up +## Set up the project Clone the project: @@ -78,11 +93,11 @@ sudo cp -r build/client/ /var/www/html/project2 > [!CAUTION] > We only move the `client/` folder from the build! > We do not use React Router's server-side functionality, because our frontend does not use server-side rendering (SSR). -> See [react-router.config.ts](./frontend/react-router.config.ts) +> See [react-router.config.ts](../frontend/react-router.config.ts) The move must be executed as sudo because the `/var` folders are owned by `root`. -### Building the backend +### Build the backend Build the backend like so: @@ -94,7 +109,7 @@ pnpm build ### Prepare the database We need the seed book data file. -For more details, please check the [backend README.md](./backend/README.md). +For more details, please check the [backend README.md](../backend/README.md). Let's download the dataset, unzip and place it in the correct folder: @@ -119,11 +134,13 @@ pnpm db:setup > `pnpm db:setup` deletes the whole database, including all users and their favorites. > Only use it for the initial setup. After that, apply schema changes with `pnpm db:migrate`. + + > [!NOTE] > If you receive permission errors, add your user to the `postgres` group by running the following command: > `sudo usermod -aG postgres $USER` -### Whenever the database schema changes +### Apply migrations If someone modifies the database schema and creates a migration using `pnpm db:generate`, we need to apply these on the deployment as well. @@ -134,7 +151,7 @@ cd backend pnpm db:migrate ``` -## Running the project +## Run the project The frontend is already handling by the Apache web server by being placed in `/var/www/html/project2`. @@ -154,12 +171,12 @@ Afterwards, after changing the backend and building it, it's enough to restart i pm2 restart backend ``` -## Our VM setup +## VM setup This is what is set up on our VM (`it2810-37.idi.ntnu.no`, Ubuntu 26.04). Apache was already installed and running. -### Installed packages +### Install packages ```sh # Node 24 from NodeSource @@ -173,7 +190,7 @@ sudo npm install -g pnpm@12 sudo apt install -y postgresql ``` -### Apache config +### Set up Apache config The config below does two things, and only applies to the `project2` folder: diff --git a/docs/infrastructure.md b/docs/infrastructure.md index d65293ea..29516503 100644 --- a/docs/infrastructure.md +++ b/docs/infrastructure.md @@ -1,9 +1,15 @@ -# Readr - infrastructure +# Infrastructure -Readr is a full-stack application using modern technologies, allowing users to interact with books, save them as favorites, rate them (soon) and write reviews (soon). +- [Overview](#overview) +- [Common technologies](#common-technologies) +- [Frontend](#frontend) +- [Backend](#backend) +- [An Example: The Journey from Start to Finish](#an-example-the-journey-from-start-to-finish) ## Overview +This document describes the technologies Readr is built with and how its parts fit together. + The diagram gives a general overview of how the parts of Readr talk to each other when it runs on our VM. It is meant to give an understanding of the setup, and doesn't follow a formal notation such as UML or C4, and was created with AI ```mermaid diff --git a/docs/specifications.md b/docs/specifications.md index 60d3e01b..2096095f 100644 --- a/docs/specifications.md +++ b/docs/specifications.md @@ -1,4 +1,8 @@ -# Specification +# Specification + +- [Data](#data) +- [Design](#design) +- [User interaction](#user-interaction) ## Data diff --git a/docs/sustainability.md b/docs/sustainability.md index fe8b8448..f4b74d57 100644 --- a/docs/sustainability.md +++ b/docs/sustainability.md @@ -1,4 +1,8 @@ -# Sustainability +# Sustainability + +- [What we do well](#what-we-do-well) +- [Limitations and future work](#limitations-and-future-work) +- [Lighthouse](#lighthouse) ## What we do well @@ -7,9 +11,9 @@ - **Small responses from GraphQL.** The book cards only fetch what is actually being displayed: `id`, `title`, `author`, `publishDate`, `coverImgUrl` and `rating`, and not the description and other heavy fields. - **No unnecessary queries.** Queries are skipped when their result is not needed (with Apollo's `skip` option and `skipToken`), for example the favorites of a user who is not logged in. - **Cache.** Apollo uses the cache before the network. The lists of genres and languages on the home page are only fetched once per page load, since they only change when the dataset changes. The filter options on the books page depend on the search (see [Only relevant filter options](./choices-and-reasoning.md#only-relevant-filter-options)), so they are fetched again when the search or filters change. They are not fetched again when the user changes page or sorting, and a search that has been made before is read from the cache. Without a search or filters, the backend uses the counts it has already computed for all books. -- **Covers are not stored on the server.** As mentioned in the [specification documentation](/docs/specifications.md), we only store the URL of each cover image. This was mainly done because of the limited storage on the VM, but it also means we don't keep a second copy of tens of thousands of images that are already hosted on Goodreads' image servers. The downside is that we can't control the size of the images, see [Limitations/Future work](#limitationsfuture-work). +- **Covers are not stored on the server.** As mentioned in the [specification documentation](./specifications.md), we only store the URL of each cover image. This was mainly done because of the limited storage on the VM, but it also means we don't keep a second copy of tens of thousands of images that are already hosted on Goodreads' image servers. The downside is that we can't control the size of the images, see [Limitations and future work](#limitations-and-future-work). -## Limitations/Future work +## Limitations and future work This section is meant as an overview of potential improvements with regard to sustainability, and also shows that we are aware of the downsides of our implementation. The table has a column for the status at delivery 3, and the same table will be used to show what work has been done from delivery 3 to 4. More items can be added after delivery 3, and will be written inside the same table, with "Added after delivery 3" mark. @@ -19,7 +23,7 @@ This section is meant as an overview of potential improvements with regard to su | We use the cover URLs from the dataset as they are, which may be larger images than the size we display them at. | Measure the image sizes, and use a smaller image variant if the image host offers one. | Not done | Won't do. Different covers are available from Goodreads through guesses regarding the correct URL, but the API is undocumented and may change at any time. This means our code loading images could stop working at any time, so we prefer to use URLs we know are working correctly. | | The app loads two font families: Inter (self-hosted with `@fontsource`) and Open Sans (from Google Fonts). | Use one font family and host it ourselves, which removes an external request and one set of font files. | Not done | Done. Open Sans was not used anywhere, so we removed it. | | Apollo caches the lists of genres, languages and formats in each browser, but the backend computes them again with a `GROUP BY` over the whole `books` table every time a browser without them asks. | Cache the lists in the backend, so they are computed once and shared between all users. They only change when the dataset changes. | Not done | Done. The backend computes each list once and keeps it in memory until the server restarts. The server must also be restarted if we ever change the book dataset. | -| Added after delivery 3: Apache sent our own JS, CSS and font files without cache headers, so browsers asked for them again on every visit. | Let browsers keep the files in `assets/` for a year, since their names change whenever their content changes. See the [deployment documentation](/docs/deployment.md#apache-config). | - | Done | +| Added after delivery 3: Apache sent our own JS, CSS and font files without cache headers, so browsers asked for them again on every visit. | Let browsers keep the files in `assets/` for a year, since their names change whenever their content changes. See the [deployment documentation](./deployment.md#apache-config). | - | Done | ## Lighthouse diff --git a/frontend/README.md b/frontend/README.md index fe39db9b..2adc6571 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,4 +1,14 @@ -# Readr - frontend +# Readr - frontend + +- [Getting started](#getting-started) +- [Note on Shadcn CLI](#note-on-shadcn-cli) +- [Testing](#testing) + - [Vitest](#vitest) + - [What is tested](#what-is-tested) + - [Mocking](#mocking) + - [Playwright (E2E tests)](#playwright-e2e-tests) + - [Browsers and devices](#browsers-and-devices) +- [ESLint](#eslint) ## Getting started @@ -120,7 +130,7 @@ The tests never send real requests. We mock two things: The API itself is tested in the backend, see the [backend README](../backend/README.md#testing-the-api). -### Playwright (end-to-end tests) +### Playwright (E2E tests) Before running tests for the first time, make sure to install the browsers we will use to test: @@ -137,7 +147,7 @@ cd frontend pnpm e2e ``` -The tests will take a while to complete, because we test against multiple browsers and run one test at a time (see [project choices and reasoning](../docs/choices-and-reasoning.md#playwright-e2e-testing)). +The tests will take a while to complete, because we test against multiple browsers and run one test at a time (see [project choices and reasoning](../docs/choices-and-reasoning.md#e2e-testing)). The E2E tests cover signing up, logging in and out, searching, filtering, sorting and paging, favorites, profile settings, the home page, dark mode and using the app with only the keyboard. They also run automatic accessibility checks with [axe](https://github.com/dequelabs/axe-core) on every page, in both light and dark mode. @@ -188,7 +198,7 @@ iPhone we found one problem, which is fixed and described under the table. #154, and the books were shown when we checked the deployed application on the phone again. -## Linting using ESLint +## ESLint We have enabled the most strict rules for Typescript using [`typescript-eslint`](https://typescript-eslint.io/) and the most strict rules for React using [Eslint React](https://eslint-react.xyz/).