Skip to content

Commit 97d9be2

Browse files
Merge pull request #1 from powersync-community/init
Initial implementation of the template
2 parents f6abb27 + f5fa115 commit 97d9be2

31 files changed

+5239
-1
lines changed

.degitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# GitHub Actions and workflows
2+
.github/
3+
4+
# Development files
5+
.vscode/
6+
.idea/
7+
8+
# OS generated files
9+
.DS_Store
10+
.DS_Store?
11+
._*
12+
.Spotlight-V100
13+
.Trashes
14+
ehthumbs.db
15+
Thumbs.db

.env.local.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copy this template: `cp .env.local.template .env.local`
2+
# Edit .env.local and enter your Supabase and PowerSync project details.
3+
VITE_SUPABASE_URL=https://foo.supabase.co
4+
VITE_SUPABASE_ANON_KEY=foo
5+
VITE_POWERSYNC_URL=https://foo.powersync.journeyapps.com

.github/dependabot.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
day: "sunday"
8+
open-pull-requests-limit: 10
9+
reviewers:
10+
- "dean-journeyapps"
11+
- "joshua-journey-apps"
12+
- "michaelbarnes"
13+
ignore:
14+
# Ignore major version updates for critical deps
15+
- dependency-name: "react"
16+
update-types: ["version-update:semver-major"]
17+
- dependency-name: "react-dom"
18+
update-types: ["version-update:semver-major"]
19+
# Allow security updates for all dependencies
20+
allow:
21+
- dependency-type: "all"
22+
groups:
23+
react-ecosystem:
24+
patterns:
25+
- "react*"
26+
- "@types/react*"
27+
build-tools:
28+
patterns:
29+
- "webpack*"
30+
- "babel*"
31+
- "eslint*"
32+
- "vite*"
33+
powersync:
34+
patterns:
35+
- "@powersync/*"
36+
- "powersync*"
37+
testing:
38+
patterns:
39+
- "jest*"
40+
- "@testing-library/*"
41+
- "vitest*"

.github/pull_request_template.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Description
2+
3+
## Work Done
4+
5+
## How to Test

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: '20'
16+
cache: 'npm'
17+
- name: Install dependencies
18+
run: npm ci
19+
- name: Run linting
20+
run: npm run lint
21+
- name: Run type checking
22+
run: npm run type-check
23+
- name: Run build
24+
run: npm run build

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.env
2+
.env.local
3+
.idea
4+
node_modules
5+
dist
6+
.DS_Store
7+
.env.local
8+
.env
9+
.vscode

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.12.1

LICENSE

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Creative Commons Legal Code
2+
3+
CC0 1.0 Universal
4+
5+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12+
HEREUNDER.
13+
14+
Statement of Purpose
15+
16+
The laws of most jurisdictions throughout the world automatically confer
17+
exclusive Copyright and Related Rights (defined below) upon the creator
18+
and subsequent owner(s) (each and all, an "owner") of an original work of
19+
authorship and/or a database (each, a "Work").
20+
21+
Certain owners wish to permanently relinquish those rights to a Work for
22+
the purpose of contributing to a commons of creative, cultural and
23+
scientific works ("Commons") that the public can reliably and without fear
24+
of later claims of infringement build upon, modify, incorporate in other
25+
works, reuse and redistribute as freely as possible in any form whatsoever
26+
and for any purposes, including without limitation commercial purposes.
27+
These owners may contribute to the Commons to promote the ideal of a free
28+
culture and the further production of creative, cultural and scientific
29+
works, or to gain reputation or greater distribution for their Work in
30+
part through the use and efforts of others.
31+
32+
For these and/or other purposes and motivations, and without any
33+
expectation of additional consideration or compensation, the person
34+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35+
is an owner of Copyright and Related Rights in the Work, voluntarily
36+
elects to apply CC0 to the Work and publicly distribute the Work under its
37+
terms, with knowledge of his or her Copyright and Related Rights in the
38+
Work and the meaning and intended legal effect of CC0 on those rights.
39+
40+
1. Copyright and Related Rights. A Work made available under CC0 may be
41+
protected by copyright and related or neighboring rights ("Copyright and
42+
Related Rights"). Copyright and Related Rights include, but are not
43+
limited to, the following:
44+
45+
i. the right to reproduce, adapt, distribute, perform, display,
46+
communicate, and translate a Work;
47+
ii. moral rights retained by the original author(s) and/or performer(s);
48+
iii. publicity and privacy rights pertaining to a person's image or
49+
likeness depicted in a Work;
50+
iv. rights protecting against unfair competition in regards to a Work,
51+
subject to the limitations in paragraph 4(a), below;
52+
v. rights protecting the extraction, dissemination, use and reuse of data
53+
in a Work;
54+
vi. database rights (such as those arising under Directive 96/9/EC of the
55+
European Parliament and of the Council of 11 March 1996 on the legal
56+
protection of databases, and under any national implementation
57+
thereof, including any amended or successor version of such
58+
directive); and
59+
vii. other similar, equivalent or corresponding rights throughout the
60+
world based on applicable law or treaty, and any national
61+
implementations thereof.
62+
63+
2. Waiver. To the greatest extent permitted by, but not in contravention
64+
of, applicable law, Affirmer hereby overtly, fully, permanently,
65+
irrevocably and unconditionally waives, abandons, and surrenders all of
66+
Affirmer's Copyright and Related Rights and associated claims and causes
67+
of action, whether now known or unknown (including existing as well as
68+
future claims and causes of action), in the Work (i) in all territories
69+
worldwide, (ii) for the maximum duration provided by applicable law or
70+
treaty (including future time extensions), (iii) in any current or future
71+
medium and for any number of copies, and (iv) for any purpose whatsoever,
72+
including without limitation commercial, advertising or promotional
73+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74+
member of the public at large and to the detriment of Affirmer's heirs and
75+
successors, fully intending that such Waiver shall not be subject to
76+
revocation, rescission, cancellation, termination, or any other legal or
77+
equitable action to disrupt the quiet enjoyment of the Work by the public
78+
as contemplated by Affirmer's express Statement of Purpose.
79+
80+
3. Public License Fallback. Should any part of the Waiver for any reason
81+
be judged legally invalid or ineffective under applicable law, then the
82+
Waiver shall be preserved to the maximum extent permitted taking into
83+
account Affirmer's express Statement of Purpose. In addition, to the
84+
extent the Waiver is so judged Affirmer hereby grants to each affected
85+
person a royalty-free, non transferable, non sublicensable, non exclusive,
86+
irrevocable and unconditional license to exercise Affirmer's Copyright and
87+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
88+
maximum duration provided by applicable law or treaty (including future
89+
time extensions), (iii) in any current or future medium and for any number
90+
of copies, and (iv) for any purpose whatsoever, including without
91+
limitation commercial, advertising or promotional purposes (the
92+
"License"). The License shall be deemed effective as of the date CC0 was
93+
applied by Affirmer to the Work. Should any part of the License for any
94+
reason be judged legally invalid or ineffective under applicable law, such
95+
partial invalidity or ineffectiveness shall not invalidate the remainder
96+
of the License, and in such case Affirmer hereby affirms that he or she
97+
will not (i) exercise any of his or her remaining Copyright and Related
98+
Rights in the Work or (ii) assert any associated claims and causes of
99+
action with respect to the Work, in either case contrary to Affirmer's
100+
express Statement of Purpose.
101+
102+
4. Limitations and Disclaimers.
103+
104+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
105+
surrendered, licensed or otherwise affected by this document.
106+
b. Affirmer offers the Work as-is and makes no representations or
107+
warranties of any kind concerning the Work, express, implied,
108+
statutory or otherwise, including without limitation warranties of
109+
title, merchantability, fitness for a particular purpose, non
110+
infringement, or the absence of latent or other defects, accuracy, or
111+
the present or absence of errors, whether or not discoverable, all to
112+
the greatest extent permissible under applicable law.
113+
c. Affirmer disclaims responsibility for clearing rights of other persons
114+
that may apply to the Work or any use thereof, including without
115+
limitation any person's Copyright and Related Rights in the Work.
116+
Further, Affirmer disclaims responsibility for obtaining any necessary
117+
consents, permissions or other rights required for any use of the
118+
Work.
119+
d. Affirmer understands and acknowledges that Creative Commons is not a
120+
party to this document and has no duty or obligation with respect to
121+
this CC0 or use of the Work.

README.md

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,133 @@
1-
# vite-react-ts-powersync-supabase
1+
# Vite + React + TS + PowerSync + Supabase
2+
3+
A template Vite, TS, React, PowerSync and Supabase project to get you started quickly with building offline-first applications with PowerSync and Supabase.
4+
5+
## Getting Started
6+
7+
You have 4 options to get started with this template.
8+
We recommend using the first option for a quick start.
9+
10+
1. Generate a repository from this [template](https://github.com/powersync-community/vite-react-ts-powersync-supabase/generate)
11+
2. Use [degit](https://github.com/Rich-Harris/degit) to scaffold the project:
12+
13+
```bash
14+
npx degit powersync-community/vite-react-ts-powersync-supabase
15+
```
16+
17+
> **Note**: `degit` is a tool that downloads the latest version of a repository without the git history, giving you a clean starting point. Add a second argument to specify your project name (e.g., my-app).
18+
19+
3. Clone the repository directly and install dependencies:
20+
21+
```bash
22+
git clone https://github.com/powersync-community/vite-react-ts-powersync-supabase.git
23+
```
24+
25+
4. Start the project using [bolt.new](https://bolt.new):
26+
27+
- Open this [link](https://bolt.new/github.com/powersync-community/vite-react-ts-powersync-supabase/tree/main) to load the project.
28+
- You will see a configuration error in the preview window because the `.env` file has not yet been defined.
29+
- Create a new `.env` file and populate it with the appropriate Supabase and PowerSync credentials, as specified in the `.env.local.template` file included in this repository.
30+
- Save the file — the app should launch automatically.
31+
32+
## Usage
33+
34+
After cloning the repository, navigate to the project directory and install the dependencies:
35+
36+
```bash
37+
cd vite-react-ts-powersync-supabase
38+
npm install
39+
npm run dev
40+
```
41+
42+
## Setup Backend
43+
44+
### 1. Setup Supabase
45+
Follow these steps to set up your backend with Supabase and PowerSync (Or you can follow the [guide](https://docs.powersync.com/integration-guides/supabase-+-powersync)).
46+
47+
#### Setup using the Supabase Dashboard
48+
1. [Create a new project on the Supabase dashboard](https://supabase.com/dashboard/projects).
49+
2. Go to the Supabase SQL Editor for your new project and execute the SQL statements in [`database.pgsql`](database.pgsql) to create the database schema, database functions, and publication needed for PowerSync.
50+
3. Enable "anonymous sign-ins" for the project [here](https://supabase.com/dashboard/project/_/auth/providers) (demo specific)
51+
52+
#### Setup using the Supabase CLI (optional)
53+
If you prefer using the Supabase CLI, you can set up your project as follows:
54+
1. Login to your Supabase Account `npx supabase login`
55+
2. Initialize your project `npx supabase init`
56+
3. Enable "anonymous sign-ins" for the project [here](https://supabase.com/dashboard/project/_/auth/providers)
57+
4. Copy your project ID from the Supabase dashboard [here](https://supabase.com/dashboard/project/_/settings/general)
58+
5. Link your local project `npx supabase link --project-ref <project-id>`
59+
6. Create your first migration with `npx supabase migration new create_powersync_tables` and then copy the contents of [`database.pgsql`](database.pgsql) into the newly created migration file in the `supabase/migrations` directory.
60+
7. Push your tables to the cloud db
61+
```shell
62+
npx supabase db push
63+
```
64+
65+
### 2. Create PowerSync Instance and Connect to Supabase
66+
67+
You can set up your PowerSync instance using either the Dashboard or CLI approach:
68+
69+
#### Option 1: Using PowerSync [CLI](https://docs.powersync.com/usage/tools/cli)
70+
71+
> This PowerSync CLI only works with **PowerSync Cloud instances.**
72+
> The CLI currently does not support **self-hosted PowerSync instances.**
73+
74+
If you don't have a PowerSync account yet, [sign up here](https://accounts.journeyapps.com/portal/powersync-signup).
75+
76+
1. **Get your Personal Access Token:**
77+
- Go to the [PowerSync dashboard](https://powersync.journeyapps.com/)
78+
- Press `Ctrl + Shift + P` (or `Cmd + Shift + P` on Mac)
79+
- Search for "Create Personal Access Token"
80+
- Give it "owner" policy and a descriptive label
81+
- Copy the generated token
82+
83+
2. **Initialize the CLI and authenticate:**
84+
```bash
85+
npx powersync init
86+
```
87+
Paste your Personal Access Token when prompted.
88+
89+
3. **Create a new PowerSync instance:**
90+
```bash
91+
npx powersync instance create
92+
```
93+
Follow the prompts to configure:
94+
- Instance name (e.g., "supabase-staging")
95+
- Region (e.g., "EU")
96+
- Database connection details from your Supabase project (use the **direct connection**, not pooling)
97+
- When asked about Supabase auth, answer:
98+
- `? Are you using Supabase auth? Yes`
99+
- `? Do you want to add audiences? No`
100+
101+
4. **Deploy sync rules:**
102+
```bash
103+
npx powersync instance sync-rules deploy -f sync-rules.yaml
104+
```
105+
106+
> After deploying sync rules via CLI, the changes might not be reflected in the dashboard. If you want to see them in the dashboard, simply copy the contents of your `sync-rules.yaml` file and paste them into the dashboard's sync-rules editor, then redeploy.
107+
108+
#### Option 2: Using PowerSync Dashboard
109+
110+
If you prefer using the web interface:
111+
112+
1. In the [PowerSync dashboard](https://powersync.journeyapps.com/), create a new PowerSync instance:
113+
- Right-click on 'PowerSync Project' in the project tree on the left and click "Create new instance"
114+
- Pick a name for the instance e.g. "Yjs Demo Test" and proceed.
115+
116+
2. In the "Edit Instance" dialog that follows, click on the "Connections" tab:
117+
- Click on the "+" button to create a new database connection.
118+
- Input the credentials from the project you created in Supabase. In the Supabase dashboard, under your project you can go to "Project Settings" and then "Database" and choose "URI" under "Connection string", **untick the "Use connection pooling" option** to use the direct connection, and then copy & paste the connection string into the PowerSync dashboard "URI" field, and then enter your database password at the "Password" field.
119+
- Click the "Test connection" button and you should see "Connection success!"
120+
121+
3. Click on the "Credentials" tab of the "Edit Instance" dialog:
122+
- Tick the "Use Supabase Auth" checkbox and configure the JWT secret.
123+
- Click "Save" to save all the changes to your PowerSync instance. The instance will now be deployed — this may take a minute or two.
124+
125+
### 3. Deploy Sync Rules
126+
127+
#### Option 1: Using CLI (if you used CLI setup above)
128+
The sync rules are already deployed if you followed the CLI setup steps above.
129+
130+
#### Option 2: Using Dashboard
131+
1. Open the [`sync-rules.yaml`](sync-rules.yaml) in this repo and copy the contents.
132+
2. In the [PowerSync dashboard](https://powersync.journeyapps.com/), paste that into the 'sync-rules.yaml' editor panel.
133+
3. Click the "Deploy sync rules" button and select your PowerSync instance from the drop-down list.

database.pgsql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- See our guide for more information on how to set up your Supabase database:
2+
-- https://docs.powersync.com/integration-guides/supabase-+-powersync#supabase-powersync
3+
4+
CREATE TABLE counters
5+
(
6+
id TEXT PRIMARY KEY,
7+
count INTEGER NOT NULL DEFAULT 0,
8+
owner_id TEXT NOT NULL,
9+
created_at TIMESTAMP NOT NULL
10+
);
11+
12+
-- Create a role/user with replication privileges for PowerSync
13+
CREATE ROLE powersync_role WITH REPLICATION BYPASSRLS LOGIN PASSWORD 'myhighlyrandompassword';
14+
-- Set up permissions for the newly created role
15+
-- Read-only (SELECT) access is required
16+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO powersync_role;
17+
18+
-- Create a publication to replicate tables.
19+
-- Specify a subset of tables to replicate if required.
20+
-- NOTE: this must be named "powersync" at the moment
21+
CREATE PUBLICATION powersync FOR ALL TABLES;

0 commit comments

Comments
 (0)