Skip to content

Commit 1e79ac9

Browse files
authored
feat: Add tRPC application server and Firestore database (#2063)
1 parent b34bced commit 1e79ac9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2877
-177
lines changed

.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ APP_NAME=Acme Co.
1111
APP_HOSTNAME=localhost
1212
APP_ORIGIN=http://localhost:5173
1313
API_ORIGIN=https://api-mcfytwakla-uc.a.run.app
14+
APP_STORAGE_BUCKET=example.com
1415

1516
# Google Cloud
1617
# https://console.cloud.google.com/
1718
GOOGLE_CLOUD_PROJECT=kriasoft
1819
GOOGLE_CLOUD_REGION=us-central1
20+
GOOGLE_CLOUD_DATABASE="(default)"
1921
GOOGLE_CLOUD_CREDENTIALS={"type":"service_account","project_id":"example","private_key_id":"xxx","private_key":"-----BEGIN PRIVATE KEY-----\nxxxxx\n-----END PRIVATE KEY-----\n","client_email":"application@exmaple.iam.gserviceaccount.com","client_id":"xxxxx","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/application%40example.iam.gserviceaccount.com"}
2022

2123
# Firebase
@@ -24,6 +26,11 @@ FIREBASE_APP_ID=1:736557952746:web:b5ee23841e24c0b883b193
2426
FIREBASE_API_KEY=AIzaSyAZDmdeRWvlYgZpwm6LBCkYJM6ySIMF2Hw
2527
FIREBASE_AUTH_DOMAIN=kriasoft.web.app
2628

29+
# OpenAI
30+
# https://platform.openai.com/
31+
OPENAI_ORGANIZATION=xxxxx
32+
OPENAI_API_KEY=xxxxx
33+
2734
# Cloudflare
2835
# https://dash.cloudflare.com/
2936
# https://developers.cloudflare.com/api/tokens/create

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,28 @@
6161
"firestore",
6262
"globby",
6363
"hono",
64+
"identitytoolkit",
6465
"jamstack",
6566
"kriasoft",
6667
"localforage",
6768
"miniflare",
6869
"nodenext",
6970
"notistack",
7071
"oidc",
72+
"openai",
7173
"pathinfo",
74+
"pino",
7275
"pnpify",
7376
"reactstarter",
7477
"refetch",
7578
"refetchable",
79+
"relyingparty",
7680
"sendgrid",
7781
"signup",
7882
"sourcemap",
7983
"spdx",
8084
"swapi",
85+
"trpc",
8186
"tslib",
8287
"typechecking",
8388
"vite",

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ Be sure to join our [Discord channel](https://discord.com/invite/2nKEnKq) for as
3131
`├──`[`.github`](.github) — GitHub configuration including CI/CD workflows<br>
3232
`├──`[`.vscode`](.vscode) — VSCode settings including code snippets, recommended extensions etc.<br>
3333
`├──`[`app`](./app) — Web application front-end built with [React](https://react.dev/) and [Joy UI](https://mui.com/joy-ui/getting-started/)<br>
34+
`├──`[`db`](./db) — Firestore database schema, seed data, and admin tools<br>
3435
`├──`[`edge`](./edge) — Cloudflare Workers (CDN) edge endpoint<br>
3536
`├──`[`env`](./env) — Application settings, API keys, etc.<br>
3637
`├──`[`scripts`](./scripts) — Automation scripts such as `yarn deploy`<br>
38+
`├──`[`server`](./server) — Node.js application server built with [tRPC](https://trpc.io/)<br>
3739
`├──`[`tsconfig.base.json`](./tsconfig.base.json) — The common/shared TypeScript configuration<br>
3840
`└──`[`tsconfig.json`](./tsconfig.json) — The root TypeScript configuration<br>
3941

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"devDependencies": {
3737
"@babel/core": "^7.23.7",
3838
"@emotion/babel-plugin": "^11.11.0",
39-
"@types/node": "^20.10.6",
39+
"@types/node": "^20.10.7",
4040
"@types/react": "^18.2.47",
4141
"@types/react-dom": "^18.2.18",
4242
"@vitejs/plugin-react": "^4.2.1",

db/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Firestore Database
2+
3+
Database schema, security rules, indexes, and seed data for the [Firestore](https://cloud.google.com/firestore) database.
4+
5+
## Directory Structure
6+
7+
- [`/models`](./models/) — Database schema definitions using [Zod](https://zod.dev/).
8+
- [`/seeds`](./seeds/) — Sample / reference data for the database.
9+
- [`/scripts`](./scripts/) — Scripts for managing the database.
10+
- [`/firestore.indexes.json`](./firestore.indexes.json) — Firestore indexes.
11+
- [`/firestore.rules`](./firestore.rules) — Firestore security rules.
12+
13+
## Scripts
14+
15+
- `yarn workspace db seed` - Seed the database with data from [`/seeds`](./seeds/).
16+
17+
## References
18+
19+
- https://zod.dev/
20+
- https://cloud.google.com/firestore

db/firestore.indexes.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"indexes": [
3+
{
4+
"collectionGroup": "workspace",
5+
"queryScope": "COLLECTION",
6+
"fields": [
7+
{ "fieldPath": "ownerId", "order": "ASCENDING" },
8+
{ "fieldPath": "archived", "order": "DESCENDING" }
9+
]
10+
}
11+
],
12+
"fieldOverrides": []
13+
}

db/firestore.rules

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Firestore security rules.
2+
// https://cloud.google.com/firestore/docs/security/get-started
3+
4+
rules_version = '2';
5+
6+
service cloud.firestore {
7+
match /databases/{database}/documents {
8+
match /workspace/{id} {
9+
allow read: if request.auth != null && (
10+
resource.data.ownerId = request.auth.uid ||
11+
request.auth.token.admin == true
12+
);
13+
}
14+
15+
match /{document=**} {
16+
allow read, write: if false;
17+
}
18+
}
19+
}

db/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
2+
/* SPDX-License-Identifier: MIT */
3+
4+
export * from "./models";
5+
export { testUsers } from "./seeds/01-users";
6+
export { testWorkspaces } from "./seeds/02-workspaces";

db/models/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
2+
/* SPDX-License-Identifier: MIT */
3+
4+
export * from "./workspace";

db/models/workspace.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-FileCopyrightText: 2014-present Kriasoft */
2+
/* SPDX-License-Identifier: MIT */
3+
4+
import { Timestamp } from "@google-cloud/firestore";
5+
import { z } from "zod";
6+
7+
export const WorkspaceSchema = z.object({
8+
name: z.string().max(100),
9+
ownerId: z.string().max(50),
10+
created: z.instanceof(Timestamp),
11+
updated: z.instanceof(Timestamp),
12+
archived: z.instanceof(Timestamp).nullable(),
13+
});
14+
15+
export type Workspace = z.output<typeof WorkspaceSchema>;
16+
export type WorkspaceInput = z.input<typeof WorkspaceSchema>;

0 commit comments

Comments
 (0)