Techstack to host a small webapp on a raspberry pi at home? reddit / selfhosted ---------------------------------------------------------------------- w2g · 2023-10-28 12:41 Hey guys, I want to do my first little project. Asking the title question probably means I'm in over my head, but we shall see! Here's what I want to do: On my raspberry pi 4 B 4GB (currently only running pihole), I want to host a small webapp to track game statistics for a game I play with friends somewhat regularly. There should be: Authorization (login form), a database to keep track of the games played, a simple UI where a ranking and other stats are displayed and a form to enter new games. The only thing I have experience with is SQL, Python and FastAPI (very little). The raspberry pi is running ubuntu server. SO, what do I need to look into to get this off the ground? Here are my thoughts so far: Docker to have everything working together and easy to deploy. Cloudflare DNS so as not to expose my home network IP to the internet. SQLite as a database to keep the game records. FastAPI to handle requests. React for frontend (also to learn about Javascript) Nginx as a reverse proxy (not even sure what this means) Am I missing something? Is what I want to do possible only with the technologies I listed? Also, could you give some general advice on the security aspect? What do I definitely have to do so as not to endanger my home network? The webapp is only to be used by around 10 close friends. Sorry for all the questions, I hope this is the right place and not too much. ---------------------------------------------------------------------- Door_Vegetable · 2023-10-28 12:58 If you’re using cloudflare tunnels you should be pretty safe. I use a docker network that I have my web apps and cloudflare tunnel on. For security I would just make sure your coding to a proper standards and ensure that you don’t accidentally create some vulnerability. ---------------------------------------------------------------------- dazchad · 2023-10-28 14:28 For backend you can do Django since you are familiar with Python. Don’t worry about docker if this is small stuff, unless of course you want to learn it as a personal goal. For RPI just be aware SD Cards weren’t meant to be used as boot disks, so use an external drive via usb as your database volume. Because the SD card will fail and corrupt your database. ---------------------------------------------------------------------- isleepbad · 2023-10-28 14:40 I'm using an almost identical stack as you to develop my own app. The only difference being I use PostgreSQL as my dB as it performs better, traefik as my reverse proxy and tailscale for my tunnel. The only thing I'd recommend is to use PostgreSQL instead of sqlite and as another user said, a hard drive instead of an SD card. Otherwise you're definitely going in the right direction. 👍🏽 ---------------------------------------------------------------------- opiper · 2023-10-28 15:22 , za sa#20 w ---------------------------------------------------------------------- port8080dev · 2023-10-28 16:46 +1 on the SD card warning. If you do end up using an SD card, remember to automate backups to a more reliable storage device. ---------------------------------------------------------------------- w2g · 2023-10-28 21:06 Oh shit thats good advice, thank you. Can I just use a cheap USB stick or is that the same as an SD card and it should be an actual ssd or something? I think I have a small one lying around somewhere anyway. And yep, docker is to learn it as well! Why Django over FastAPI? That's Python as well ---------------------------------------------------------------------- w2g · 2023-10-28 21:06 Could I just upload the db to a google drive or something with a cronjob every night? ---------------------------------------------------------------------- w2g · 2023-10-28 21:08 Thank you! Is that on a raspi as well? I thought SQLite would be better for that, but I'm actually more familiar with postgre ---------------------------------------------------------------------- desnudopenguino · 2023-10-28 21:15 Django is a good py web framework. Sqlite should suffice for such a small app. Once you get a bunch of users and writing action, a rdbms like postgress might be required. ---------------------------------------------------------------------- dazchad · 2023-10-28 21:21 I don't have a lot of experience with FastAPI, but Django is amazingly easy to build internal tools, or to kickstart a larger project. It Just Works (tm). But again, it's up to you! If you feel more familiar with FastAPI, go for it. As for USB stick, I'd splurge a bit and get a SSD with USB 3 enclosure (2.5" or M.2). They are built to be used 24/7. No need to spend on a fancy m.2 since USB 3 tops at 5Gbps (625MB/s) ---------------------------------------------------------------------- port8080dev · 2023-10-28 21:40 Sure. And if you used SQLite, it'd be a simple 1 file copy. ---------------------------------------------------------------------- bouni2022 · 2023-10-29 07:39 Django has "batteries included". ORM and DB migrations are the most underrated features included in Django that do not come with FastAPI ---------------------------------------------------------------------- issa62 · 2023-10-29 09:38 https://github.com/piku/piku ---------------------------------------------------------------------- xDerEdx · 2023-10-29 10:26 Foto small personal projects I like to use pocketbase. (https://pocketbase.io) It uses Sqlite under the hood and provides a good admin interface, allows static file hosting, creates an API for your tables automatically which you can secure with security rules and has several authentication providers built in. ---------------------------------------------------------------------- w2g · 2023-10-29 12:06 This seems super cool. I really like having an admin interface too, as I'm currently struggling to truncate a table out of a jupyter notebook with sqlalchemy haha ---------------------------------------------------------------------- xDerEdx · 2023-10-29 18:11 Exactly, it would replace Sqlite, FastAPI and also solve authentication. In theory it could also replace your form to enter new values, since you could do it directly in the admin UI as well. Or you could write a small frontend app (with React or whatever framework you want to use) interacting with your Pocketbase instance and host its static files in the pb_public directory, solving your need for hosting your frontend as well.