Giter Club home page Giter Club logo

pocketbase-sveltekit-starter's Introduction

PocketBase / SvelteKit Starter App

Use this app as a starting point for your own customized PocketBase backend with SvelteKit frontend. This is a high-performance frontend+backend combination, since frontend is static and backend is a single compiled Golang binary (JAMstack baby!).

  • SvelteKit frontend is fully static, client-side only, so that here is no need for NodeJS at runtime. It is generated using adapter-static and ssr is OFF.
  • PocketBase provides complete (and fast) backend including:
    • databse (SQLite)
    • CRUD API for database
    • realtime subscriptions for LIVE data (server push to browser)
    • Authentication and Authorization (email + social login/oauth2)
    • file storage (local filesystem or S3)
    • Extend with hooks and API endpoints in ...
  • PocketBase can be downloaded as binary, and yet be extended with JavaScript. But if you want to extend it with custom Golang code then code is included to compile it locally with extensions such as custom endpoints (e.g. /api/hello) and database event hooks (e.g. executing Go handler functions when a database row is created)
  • A full live development setup is included
    • Hot Module Reloading (HMR) of your frontend app when you edit Svelte code (including proxying requests to the PocketBase backend via vite)
    • Hot reloading (restarting) of the PocketBase server using modd when you edit Go code
    • Hot reloading (restarting) of the PocketBase server when JS code is changed in ./pb/pb_hooks

To understand the backend, see ./pb/README.md ("pb" == PocketBase) To understand the frontend, see ./sk/README.md ("sk" == SvelteKit)

Read those README files before proceeding.

Setup

Follow these steps CAREFULLY, or else it won't work. Also read the README files referred above before proceeding.

With Docker

This method is the most recommended method for setting up this application in most use cases, especially when customizing with Go code.

Make sure your Docker daemon is running then complete the following steps:

  1. Copy.env.example to .env and then edit it to match your environment. Also, if you wish, copy docker-compose.override.yml to docker-compose.override.yml and edit it to your taste before proceeding. And then just run docker compose up -d.
  2. Open a new terminal and navigate to the /sk directory. Install dependencies by running npx pnpm install
  3. In the same terminal, after the dependencies are installed, run the command npm run dev:backend This runs go build in the /pb directory and runs modd for live development on a backend server
  4. Open a seperate terminal, navigate to the /sk directory, and run the command npm run dev. This starts the frontend dev server.
  5. Both sides are working if you navigate to the "Hello" page on the development server and there is an API response that says "Hello World!"

With pocketbase binary

This method is a good alternative for simple use cases that don't use either Docker or Go, and instead uses JavaScript-exclusive customizations.

  1. Download the latest version of PocketBase.
    • The versions support Darwin, Linux, and Windows. Make sure that you download the correct version that supports itself within the OS that you are using.
  2. Extract the pocketbase.exe from the .zip file you downloaded into the /pb folder within your project.
  3. Set up the backend
    • Open a new terminal, navigate to the /sk directory and run the command npm run backend
      • For Windows: You will have to edit the "backend" script in the ./sk/package.json file to cd .. && cd pb && pocketbase serve --publicDir=../sk/build
      • For Mac: Please contribute
  4. Set up the frontend
    • Open a new terminal, navigate to the /sk directory and run the following
      • First install dependencies using npx pnpm install
      • Then, npm run dev
  5. Extend JavaScript by checking out this documentation here..

With Go Tools

This method works if you have Go Tools installed and want to set up the machine directly on your specific OS and you don't want to use Docker.

  1. Verify that the Go compiler is installed on your machine by opening a terminal and running go version. If there is an error, set up the go compiler in acccordance with the type of OS you are using.
  2. Make sure you go.mod file is ready to be built by navigating to the /pb directory and running go mod tidy in the terminal, especially if the file is throwing errors.
  3. In the same terminal, run go build. This may take a moment
    • If you want to use modd for live devlopment, after building, install the latest version by running go install github.com/cortesi/modd/cmd/modd@latest, test the installation by running modd. If successful, data migration should occur and a backend development server should be running. You can learn more by reading about it in the README located in the /pb directory.
  4. Open a new terminal, and run cd sk && npm run develop. When you open the localhost page in your browser, the “Hello” page should have an “Hello World” message coming from the API response

Developing

Visit http://localhost:5173 (sk) or http://localhost:8090 (pb)

If you are running modd, making changes in the Svelte code (frontend) or Go code (backend) will show results (almost) immediately.

Usage

To use the app as a user / tester ...

  • visit the frontend URL (e.g. http://localhost:5173)
  • Navigate around. The Home page is not very interesting.
  • The hello page shows and example of frontend calling a custom backend API implemented in Go.
  • The posts page shows all existing posts. If that page is empty, then you might want to create some posts. You must be logged in to be able to create posts.
  • Into the Login form, you can enter an existing username/password, or check the register checkbox to create a new account (it registers the user and log in immediately).

The above are just some sample features. Now go ahead and implement all kinds of new features.

  • Create new collections.
  • Create new pages that manipulate the above collections.

Building

See the build process details in the README files for backend and frontend.

Configurable Hooks

Please read about the "hooks" system in ./pb/README.md It is a very easy and powerful way to extend your application with minimal configuration and perhaps no code.

Feedback

Please provide feedback by opening an issue or starting a discussion.

pocketbase-sveltekit-starter's People

Contributors

boomclear avatar carter-johnston avatar j2l avatar jkdoshi avatar miguelgargallo avatar williamrelken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pocketbase-sveltekit-starter's Issues

FR: More details about how to use prebuilt pockebase binary?

I'm a bit confused about how to use this if we don't really care to modify and compile a custom pocketbase binary

The backend folder just says to copy the pocketbase binary into the backend folder.

But is that all we need to do?

It seems like the top-level docker-compose setup calls the Dockerfile in backend, but backend/Dockerfile always recompiles from source.

Is it possible to add a ARG prebuilt_pocketbase_version to backend/Dockerfile that downloads that specific version of the binary instead of compiling it? Then we could modify the docker-compose.override.yaml to supply that.

docker example doesn't work

exact command ran:

git clone https://github.com/spinspire/pocketbase-sveltekit-starter; cd pocketbase-sveltekit-starter; docker compose up -d

error:

[+] Running 2/3
 ✔ Network pocketbase-sveltekit-starter_default  Created                                                           0.7s
 - Container pocketbase-sveltekit-starter-pb-1   Starting                                                          2.1s
 ✔ Container pocketbase-sveltekit-starter-sk-1   Started                                                           1.8s
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/app/pb/entrypoint.sh": stat /app/pb/entrypoint.sh: no such file or directory: unknown

inside docker the directories are simply empty
image

Unable to run development version using docker compose

Hi,
I'm running into some trouble getting the docker development environment running.

I cloned the project and tried standing up the repo using docker compose. I updated the .env and other files as mentioned in the READMEs.

I'm running into this error:

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/go/bin/air": stat /go/bin/air: no such file or directory: unknown

Its downloading the cosmtrek/air repo but for some reason the executable isn't being found. Am I missing a step somewhere?

I'm on a Mac M1 device, if that could be a problem.

/api/hello 404

at /backend

go run main.go serve

when i visited /api/hello return :

Hello world!

after npm run build,at /frontend

npm run dev:backend
npm run dev

when i visited /api/hello return :

{"code":404,"message":"Not Found.","data":{}}

How to hot reload the frontend and backend at the same time?

I found I have to build the frontend first before i run npm run dev:backend,
but when i builded the frontend,I editing the frontend's code ,It may not change at the same time.

"dev:backend": "cd ../backend && air serve --publicDir=../frontend/build",

404 Not Found

docker compose logs -f pss

infra-pss-1 |
infra-pss-1 | __ _ ___
infra-pss-1 | / /\ | | | |)
infra-pss-1 | /
/--\ || || _ , built with Go 1.19.4
infra-pss-1 |
infra-pss-1 | mkdir /app/tmp
infra-pss-1 | watching .
infra-pss-1 | watching hooks
infra-pss-1 | watching pb_migrations
infra-pss-1 | !exclude tmp
infra-pss-1 | building...
infra-pss-1 | !exclude .cache
infra-pss-1 | go: downloading github.com/pocketbase/pocketbase v0.10.3
infra-pss-1 | go: downloading github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198
infra-pss-1 | go: downloading github.com/fatih/color v1.13.0
infra-pss-1 | go: downloading github.com/mattn/go-sqlite3 v1.14.16
infra-pss-1 | go: downloading github.com/pocketbase/dbx v1.8.0
infra-pss-1 | go: downloading github.com/AlecAivazis/survey/v2 v2.3.6
infra-pss-1 | go: downloading github.com/spf13/cobra v1.6.1
infra-pss-1 | go: downloading github.com/dop251/goja v0.0.0-20221118162653-d4bf6fde1b86
infra-pss-1 | go: downloading github.com/dop251/goja_nodejs v0.0.0-20221009164102-3aa5028e57f6
infra-pss-1 | go: downloading github.com/go-ozzo/ozzo-validation/v4 v4.3.0
infra-pss-1 | go: downloading github.com/spf13/cast v1.5.0
infra-pss-1 | go: downloading golang.org/x/oauth2 v0.3.0
infra-pss-1 | go: downloading github.com/mattn/go-colorable v0.1.13
infra-pss-1 | go: downloading github.com/mattn/go-isatty v0.0.16
infra-pss-1 | go: downloading golang.org/x/sync v0.1.0
infra-pss-1 | go: downloading golang.org/x/crypto v0.4.0
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go v1.44.165
infra-pss-1 | go: downloading github.com/disintegration/imaging v1.6.2
infra-pss-1 | go: downloading github.com/gabriel-vasile/mimetype v1.4.1
infra-pss-1 | go: downloading gocloud.dev v0.27.0
infra-pss-1 | go: downloading github.com/domodwyer/mailyak/v3 v3.3.4
infra-pss-1 | go: downloading golang.org/x/net v0.4.0
infra-pss-1 | go: downloading github.com/ganigeorgiev/fexpr v0.1.1
infra-pss-1 | go: downloading github.com/spf13/pflag v1.0.5
infra-pss-1 | go: downloading github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
infra-pss-1 | go: downloading golang.org/x/term v0.3.0
infra-pss-1 | go: downloading github.com/valyala/fasttemplate v1.2.2
infra-pss-1 | go: downloading golang.org/x/time v0.3.0
infra-pss-1 | go: downloading github.com/golang-jwt/jwt/v4 v4.4.3
infra-pss-1 | go: downloading github.com/dlclark/regexp2 v1.7.0
infra-pss-1 | go: downloading golang.org/x/text v0.5.0
infra-pss-1 | go: downloading golang.org/x/sys v0.3.0
infra-pss-1 | go: downloading github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
infra-pss-1 | go: downloading golang.org/x/image v0.2.0
infra-pss-1 | go: downloading go.opencensus.io v0.24.0
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.29.6
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.46
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2 v1.17.3
infra-pss-1 | go: downloading github.com/aws/smithy-go v1.13.5
infra-pss-1 | go: downloading github.com/google/wire v0.5.0
infra-pss-1 | go: downloading github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
infra-pss-1 | go: downloading github.com/go-sourcemap/sourcemap v2.1.3+incompatible
infra-pss-1 | go: downloading github.com/valyala/bytebufferpool v1.0.0
infra-pss-1 | go: downloading golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
infra-pss-1 | go: downloading google.golang.org/grpc v1.51.0
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.18
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.27
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.22
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.21
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.21
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/config v1.18.7
infra-pss-1 | go: downloading github.com/googleapis/gax-go/v2 v2.7.0
infra-pss-1 | go: downloading github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
infra-pss-1 | go: downloading github.com/jmespath/go-jmespath v0.4.0
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.21
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/credentials v1.13.7
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.21
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/internal/ini v1.3.28
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/sso v1.11.28
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.11
infra-pss-1 | go: downloading github.com/aws/aws-sdk-go-v2/service/sts v1.17.7
infra-pss-1 | go: downloading google.golang.org/api v0.105.0
infra-pss-1 | go: downloading google.golang.org/protobuf v1.28.1
infra-pss-1 | go: downloading google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37
infra-pss-1 | go: downloading github.com/golang/protobuf v1.5.2
infra-pss-1 | running...
infra-pss-1 | !exclude pb_data
infra-pss-1 | > Server started at: http://0.0.0.0:8090
infra-pss-1 | - REST API: http://0.0.0.0:8090/api/
infra-pss-1 | - Admin UI: http://0.0.0.0:8090/_/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.