+
Skip to content

refactor: create a new search frontend using SvelteKit #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed

refactor: create a new search frontend using SvelteKit #203

wants to merge 15 commits into from

Conversation

xynydev
Copy link

@xynydev xynydev commented Sep 8, 2024

As per discussions on the Matrix, here's a PR for tracking development of a new SvelteKit-based frontend for Mwmbl search (and eventually other features).

Also see, development README: https://github.com/xynydev/mwmbl/blob/main/sveltekit-frontend/README.md

Screenshots

(from commit 5fbde32)
(use the "edited" dropdown at the top of the post to see progress)

Front page

image
image
image
image

SERP

image
image

Design

The current design is loosely based on this image posted on the Matrix by Daoud showcasing a design draft by @realmytheman on the Matrix channel (who does not appear to be using Matrix anymore). It's still missing most of the basic correct design details: fonts, colors, gradients, correct icons and rounding constants.

I'm hoping to get in touch with @realmytheman either in this thread or on Discord if that's not possible, to figure out the design details and collaborate on the design.

Technical decisions

Framework and programming language

I opted for using SvelteKit (with Svelte 5 (runes) preview, though that may be reconsidered if issues arise) and TypeScript, because it is a combination I find very pleasing to work with, while enforcing a structured codebase and supporting filesystem routing. Svelte is especially nice since it works through kind of a compiler, making the client bundle smaller and more efficient. The new rune system with Svelte 5 implements a signal-based reactivity system very similar to other popular frameworks, which should make it pretty easy to adopt for developers new to Svelte.

CSS and UI

I opted for using TailwindCSS for styling, since it makes it easy to develop style and layout alongside the semantic HTML structure, without having to come up with classnames or context-switch to CSS. Additionally, it works as it's own standard and has nice defaults, making it possible to read HTML and understand how it looks, without having to learn what a bunch of custom classnames look like.

I like to pair Tailwind with shadcn-svelte, which is a "component library", a set of accessible and well-styled (with Tailwind) prebuilt components that are inserted directly into the codebase where they are used. shadcn-svelte is great because you always get something functional and accessible that follows best practices, while getting free rein to customize components as you see fit.

Misc

  • unplugin-icons for icons, because I saw it recommended somewhere, and solutions I've used previously have not been ideal.
  • pnpm as the main supported package manager, because the lock files etc. make package installation much faster than regular npm and some of the command line syntax is nicer. Using pnpm is totally optional, though, and the project works with or without.
  • ESLint and Prettier for formatting and linting, because they're pretty much the default choice, and cooler options such as Biome just aren't well-supported enough yet

Where to host?

SvelteKit can be trivially hosted on any platform for which an adapter exists. I've personally enjoyed "serverless" PaaS hosting on Cloudflare Pages, which does not charge for bandwidth, which should be enough to prevent Mwmbl from getting a $104K hosting bill.

Hosting on bare metal (or VPS) is also possible with the NodeJS adapter, if hosting the frontend in the same place as the backend would be preferred.

TODO

  • Implement SERP
    • The SERP is now at /search, whereas with the old frontend it's in the root path. If someone queries / with the ?q= queryparam, they get transparently redirected to /search?q=.
    • The current SERP does not bundle together results from the same domain like the old one does, nor are the results refreshed constantly while typing in the search bar. These are both features that I am unsure about; the bundling decreases readability (and often gives tons of unrelated results from the same domain), and the results refreshing while typing is just slow enough that I don't find it useful (and I ususally just want the results for the whole query, not a partial one). Let me know, though, if you wish to see these features implemented.
  • Implement OpenSearch
    • b6b6013: I added an opensearch.xml based on the pre-existing one with small edits, but I was unable to see it working in development.
  • Fix unresponsive header on mobile (hamburger menu? move links elsewhere?)
  • Add Dockerfile
  • Add dark mode + toggle
  • Implement design
  • Discuss header links and content implementation
    • Are these pages something that will exist, or just examples in the design?
    • Should these pages be just added into the book or do they need their own pages?
    • Probably could just remove them for the time being, but need some example content on the page.
  • Requires backend API discussion and implementation
    • Implement user authentication
    • Implement search result curation
    • Add list of curations somewhere, implement curation flagging

@RealmyTheMan
Copy link

Hi there, Realmy here. Personally I prefer using a chat application rather than a thread because it's more fast paced. I don't mind using Matrix, but I prefer to use Discord if that's not a problem.

@xynydev
Copy link
Author

xynydev commented Sep 8, 2024

Cheers @RealmyTheMan! You can find my discord @ on my GitHub profile and send a DM, if you're better reachable there. I'm available both in the Mwmbl Matrix and on Discord.

@daoudclarke
Copy link
Contributor

Re hosting, we can host on our existing server. It's easy enough to create new dokku app and subdomain pointing at it (we do this for beta.mwmbl.org) - let me know if this would be good.

For deploying, we can implement CD so that we deploy on merging to a branch - I've been meaning to do that for a while.

Re communicating, if you're using Discord, please can you create a new room and add me so I can be in the loop, thanks.

@xynydev
Copy link
Author

xynydev commented Sep 8, 2024

Re hosting, we can host on our existing server. It's easy enough to create new dokku app and subdomain pointing at it (we do this for beta.mwmbl.org) - let me know if this would be good.

For deploying, we can implement CD so that we deploy on merging to a branch - I've been meaning to do that for a while.

Yeah, that would be great! Dokku requires a Dockerfile, right? I could make one too, I'm pretty knowledgeable.

@daoudclarke
Copy link
Contributor

daoudclarke commented Sep 8, 2024

Yup that would be great. Check out the existing one if you want to adapt it. Static files are served by nginx

@xynydev
Copy link
Author

xynydev commented Sep 9, 2024

Docker file made. The static files are built in to the application automatically. Is it vital that they be served by Nginx? It shouldn't add much server load if it's just favicons and opensearch and such.

@daoudclarke
Copy link
Contributor

Not vital but I'm not sure what the benefit would be?

@xynydev
Copy link
Author

xynydev commented Sep 9, 2024

Benefit of what? I was just responding to:

Static files are served by nginx

The only benefit to not doing that is that it's just easier; node serves them just fine by default.

@daoudclarke
Copy link
Contributor

Ah yes, that explains it, so do we need node? because we already have Django and I'd rather avoid the complexity of multiple servers.

@xynydev
Copy link
Author

xynydev commented Sep 9, 2024

SvelteKit uses SSR by default, which obviously requires Node. It can be changed to SSG mode, but then some features are lost. I had planned to use a SvelteKit server endpoint for relaying the auth, since that would enable storing a JWT refresh token in a HttpOnly cookie, making the auth slightly better secured from XSS. Otherwise we wouldn't be using any features that require Node, so we could just switch to SSG mode and just forget securing cookies with HttpOnly.

An additional benefit of SSR is that dynamically rendered elements, such as search results, would not require JS to render initially. This would make the site more accessible to clients that disable JS or otherwise have limited computing power.

If Nginx or another reverse proxy is already used (as should IMO), I see no problem with running a separate NodeJS server for the frontend, considering the benefits and just letting the reverse proxy handle requests to that. Isn't it pretty normal for an API and a frontend to be hosted in different processes?

If computing power is a concern, but Cloudflare is not, it's also still possible to host the entire SSR frontend there for free with no bandwidth costs.

@daoudclarke
Copy link
Contributor

Yup if we get it to work without JS then it's worth it. That's one thing that a lot of people complained about with the original spa. Let's keep it as you have it. We can use api.mwmbl.org for the API as we did originally

@daoudclarke
Copy link
Contributor

In which case, let's use a separate repo. I was thinking we could do some weird mix of Django and svelte but with another server I don't think that will work

@xynydev
Copy link
Author

xynydev commented Sep 9, 2024

You can create another repo and add me as a maintainer. I'm not sure how to transfer the commit history from here, but git might have something figured out for it.

Edit: I found https://gist.github.com/trongthanh/2779392

@daoudclarke
Copy link
Contributor

Re search as you type, let's leave it for now and consider adding it again at a later stage

@daoudclarke
Copy link
Contributor

Again re bundling results, not sure fussed and definitely not needed for a first iteration. Curation etc is more important.

@xynydev
Copy link
Author

xynydev commented Sep 11, 2024

Moved to the new repository successfully: https://github.com/mwmbl/front-end

I'm going to close this PR now, and move the main content to an initial issue in the new repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载