jonra1993 / fastapi-alembic-sqlmodel-async

This is a project template which uses FastAPI, Pydantic 2.0, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication and role base access control.
MIT License
878 stars 142 forks source link

Svelte instead of nextjs #54

Closed bazylhorsey closed 1 year ago

bazylhorsey commented 1 year ago

I think Svelte would be a more modern and fun choice here. It uses the actual DOM instead of the virutal DOM. It includes Redux-like functionality out-of-the-box. Shorter syntax. And if you need things outside of SPA (like SSR), there is SvelteKit (which to be honest I don't think is needed.)

jonra1993 commented 1 year ago

Hello, @bazylhorsey I think that Svelte is a modern good option but I do have no expertise in Svelte I am really feel more comfortable and confident coding on React with Nextjs which I think is also a good modern option for a sample frontend it has already a more developed ecosystem. Something I really like about Nextjs is that it is powered by Rust which I think is also a trend in python libraries to improve speed. I am going to meet this issue open so that in the future, we can create a Svelte version too.

bazylhorsey commented 1 year ago

Heya, yeah I understand completely (i love things built in rust too). One final note would be if this is just a frontend, nextjs supplies a full stack experience. If you are more comfortable in react I would go with vanilla React as you'd have no need for the backend related components. Nextjs is meant for full stack in js/ts.

Alternatively, why not just use jinja with FastAPI, it's in their docs.

bazylhorsey commented 1 year ago

I'd also add in that this doesn't have any blog or static type functionality based on the resources included in FastAPI. Also no need for SEO or page based routing. In my opinion you just want to show post and get requests off in a frontend, SPA sounds perfect for this. Maybe there is a direction with this I'm not understanding in your roadmap. But, a simple SPA could be deployed statically without any running service, which both React and Svelte are great options for. This could be done on nginx with port 80 via traefik based using the npm build output. Thus, I personally feel like Next.js doesn't provide much benefit for showcasing this architecture.

jonra1993 commented 1 year ago

I agree the idea is to use Nextjs in static site mode (SPA), not server-side rendering so there is not need for a dedicated server nginx can work perfectly to host static content. I think Svelte and Nextjs are just frontend frameworks they do the same at the end but I have more expertise on Nextjs than Svelte so it makes it easier to start (A Dashboard webapp with login and auth logic; in our team, we work with the stack of fastapi and nextjs using typescript already). But As I wrote before I am going to keep this issue open and add it to to-do list so we can replicate future frontend also with Svelte.

bazylhorsey commented 1 year ago

I don't think you understand my point. If you understand the React syntax, then you should use React. Nextjs is meant to be a replacement to Node+React... Nextjs is not a SPA, it is primarily for SSR. You already have FastAPI doing the API work, so it just adds unneeded complexity and compute.

bazylhorsey commented 1 year ago

https://www.geeksforgeeks.org/nextjs-vs-reactjs-which-one-to-choose/

bazylhorsey commented 1 year ago

@jonra1993 any more thoughts on this? I found out you can deploy next.js as a static site. If you use Next.js, do you plan to deploy this as an SPA or SSR? If you're planning on continuing next.js I can close this.

jonra1993 commented 1 year ago

Hello @bazylhorsey sorry for my late response, the plan export nextjs project into static content which does not use SSR https://beta.nextjs.org/docs/configuring/static-export it can use nginx container to serve static content but I would prefer that on dev we use the default nextjs dev server and for production deploy the static site webapp on services like s3 or by free on cloudflare pages which we already do; It is really easy to do using a GitHub action. I hope add this in the coming weeks. Yes, you can close the issue.

bazylhorsey commented 1 year ago

@jonra1993 Why not just sit it in the static dir with caddy?

jonra1993 commented 1 year ago

It can but on production, we can take advantage of CDN of Cloudflare by free or S3+Cloudfront so the performance and speed of the static websites are better. Our server where docker-compose will be deployed would not stress itself serving static content. Just for that but it is possible that Caddy hosts a frontend.

bazylhorsey commented 1 year ago

Okay, fair enough. I was thinking for the use case that someone wants to run this service in a production state without use of cloud, ie on-premise. Acknowledge this and I will close.

jonra1993 commented 1 year ago

In such particular cases, the static assets result of build export on nextjs project "out folder" can be hosted as a static site on cady as the first option. Another option could be to configure nginx as a static server and host the assets there and a third option could be to create a node container that hosts nextjs assets (this option could take advantage of SSR ). I think the first one is the most desired in the case you mention but for a cloud solution, I would prefer Cloudflare or S3+Cloudfront due to CDN, and the cost is almost $0 in both cases.