Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions docs/ai-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AI was used as an assistant throughout the development of the web application. T
- **Writing code:** suggestions for code, which were reviewed by the team before they were used.
- **Writing and reviewing tests:** drafting test files with mocked dependencies, and explaining the reasoning behind the test structure and snapshot testing. AI also suggested what should be tested to get better test coverage.
- **Writing documentation:** drafting and refining documentation and comments in the code.
- **Generating pictures:** the avatar pictures on the profile page were made with AI.
- **Generating pictures:** the avatar pictures on the profile page and the placeholder picture for plants without an image were made with AI.
- **Refactoring:** splitting large files containing a lot of logic into smaller components and hooks.

## Examples
Expand All @@ -24,9 +24,6 @@ AI helped us write [backend/seedDataFetch.js](../backend/seedDataFetch.js), whic

We decided which fields to keep and how they are mapped to the GraphQL schema, and we checked the data in the database after each run.

### Avatar pictures

The avatar pictures that the user can choose between on the profile page were generated with AI. We chose the plants and the style, and picked the pictures that fit the design of the app.

### Tests and end-to-end tests

Expand Down
8 changes: 8 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ When the app starts, `UserProvider` reads `userId` from `localStorage` and runs
- **Small responses.** GraphQL returns only the requested fields, and fields we do not use are kept out of the schema.
- **Small user documents.** Matches are stored as plant ids, and user updates only touch one document.
- **Less traffic from the client.** Search input is debounced, results are cached by Apollo, and pages other than the start page are lazy-loaded.
- **Limitation: plant images are stored as base64 in the database.** Each plant image is stored as a base64 data URI in `imageData` (see [Data source: the Perenual API](#data-source-the-perenual-api)), instead of as an image file on the VM. This limits how well the solution scales:
- **More space:** Base64 turns every 3 bytes into 4 characters, so an image takes about 33% more space than the same file on disk. This makes the database larger, and the difference grows with every plant that is added.
- **Larger responses:** The resolver returns `imageData` in the `imageURL` field, so the images are sent inside the GraphQL response. A page of 12 plants therefore contains 12 full images, and the response cannot be returned before all of them are included. The browser cannot start loading one image while it waits for the rest, or skip images that are not visible.
- **Weaker caching:** Image files could be cached by the browser and Apache, and reused across pages and visits. The base64 strings are instead stored in the Apollo cache together with the rest of the data, and are downloaded again each time a query is not answered from the cache.

**Why we chose it anyway:** The image URLs from Perenual expire after 24 hours, so the images had to be stored by us. Storing them in the same document as the rest of the plant data was the simplest solution: the seed script writes everything to MongoDB in one step, the backend and the frontend need no extra setup to serve or find image files, and the image always belongs to the right plant, since the plant and its image are stored and deleted together. With the number of plants in our database and with a reasonable number of more, the extra space and larger responses are acceptable, and pagination keeps each response limited to one page.

**How it could be improved:** If the collection grows much larger, the images should be stored as files on the VM (or in a separate file storage) and served by Apache, with only the path stored in MongoDB. The images would then take less space, be cached by the browser, and load separately from the plant data.

## Data source: the Perenual API

Expand Down
Loading
Loading