The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
update and streamline all the docs readmes (#20201)
Charis3b781ab6bb9b
diff --git a/apps/docs/CONTRIBUTING.md b/apps/docs/CONTRIBUTING.mdindex f085a5f3be2..cc5845c1cec 100644--- a/apps/docs/CONTRIBUTING.md+++ b/apps/docs/CONTRIBUTING.md@@ -90,11 +90,13 @@ const docsDir = 'docs'const externalSite = 'https://supabase.github.io/pg_graphql'```-## File structure+Check the sections for [guide structure](#guide-structure) and [reference structure](#reference-structure) to learn more about the file structures.-The Supabase docs use [MDX](https://mdxjs.com/).+## Guide structure-Adding a new doc requires:+The Supabase docs use [MDX](https://mdxjs.com/). Guides are written in unstructured prose as MDX documents.++Adding a new guide requires:- A layout- Metadata@@ -139,6 +141,37 @@ The navigation is defined in [`NavigationMenu.constants.ts`](https://github.com/Add an entry with the `name`, `url`, and (optional) `icon` for your page.+## Reference structure++Reference docs are produced from the reference specs and library source code. A common spec file contains shared function and endpoint definitions, and library-specific spec files contain further details.++### Common spec file++Each type of library (for example, language SDK or CLI) has a common spec file. For example, see the [spec file for the language SDKs](https://github.com/supabase/supabase/blob/master/apps/docs/spec/common-client-libs-sections.json). This file contains definitions for the common SDK functions:++- **id** - Identifies the function+- **title** - Human-readable title+- **slug** - URL slug+- **product** - Supabase product that owns the function. For example, database operations are owned by `database`, and auth functions are owned by`auth`+- **type** - `function` for a structured function definition or `markdown` for a prose explainer section.++To add a new function, manually add an entry to this common file.++### Specific spec file++Each library also has its own spec file containing library-specific details. For example, see the [JavaScript SDK spec file](https://github.com/supabase/supabase/blob/master/apps/docs/spec/supabase_js_v2.yml).++The functions listed in this file match the ones defined in the common spec file.++Each function contains a description, code examples, and optional notes. The parameters are pulled from the source code via the `$ref` property, which references a function definition in the source code repo. These references are pulled down and transformed using commands in the spec [Makefile](https://github.com/supabase/supabase/blob/master/apps/docs/spec/Makefile). Unless you're a library maintainer, you don't need to worry about this.++If you're a library maintainer, follow these steps when updating function parameters or return values:++1. Get your changes merged to `master` in your library+2. This will kick off an action that automatically updates the spec file in the library's `gh-pages` branch+3. Run `make` in `/spec` of the `supabase/supabase` repo. This will regenerate all of the `tsdoc` files that the docs site uses+4. You should now see the changes you've made in the docs site locally+## Content reuseIf you copy the same content multiple times across different files, create a **partial** for content reuse instead. Partials are MDX files contained in [`apps/docs/components/MDX`](https://github.com/supabase/supabase/tree/master/apps/docs/components/MDX). They contain reusable snippets that can be inserted in multiple pages. For example, you can create a partial to define a common setup step for a group of tutorials.@@ -321,3 +354,9 @@ Here are some exceptions and Supabase-specific guidelines.- `Setup` is a noun. `Set up` is a verb.- `Supabase` is capitalized (not `supabase`), except in code.- `Supabase Platform` is in title case (not `Supabase platform`).++## Search++Search is handled using a Supabase instance. During CI, [a script](https://github.com/supabase/supabase/blob/master/apps/docs/scripts/search/generate-embeddings.ts) aggregates all content sources (eg. guides, reference docs, etc), indexes them using OpenAI embeddings, and stores them in a Supabase database.++Search uses a hybrid of native Postgres FTS and embedding similarity search based on [`pgvector`](https://github.com/pgvector/pgvector). At runtime, a PostgREST call triggers the RPC that runs the weighted FTS search, and an [Edge Function](https://github.com/supabase/blob/master/supabase/functions) is executed to perform the embedding search.diff --git a/apps/docs/DEVELOPERS.md b/apps/docs/DEVELOPERS.mdindex aa194c1a867..ed8fa91080d 100644--- a/apps/docs/DEVELOPERS.md+++ b/apps/docs/DEVELOPERS.md@@ -9,6 +9,9 @@ This document describes how to set up your development environment to contributeFor a complete run-down on how all of our tools work together, see the main DEVELOPERS.md. That readme describes how to get set up locally in lots of detail, including minimum requirements, our Turborepo setup, installing packages, sharing components across projects, and more. This readme deals specifically with the docs site.+> [!TIP]+> If you work at Supabase, branch this repo directly to make PRs. Don't use a fork. This lets the CI checks auto-run and speeds up review.+## Local setup[supabase.com/docs](https://supabase.com/docs) is a Next.JS site. You can get setup by following the same steps for all of our other Next.JS projects:@@ -19,83 +22,6 @@ For a complete run-down on how all of our tools work together, see the main DEVE4. Visit http://localhost:3001/docs in your browser - don't forget to append the `/docs` to the end5. Your local site should look exactly like [https://supabase.com/docs](https://supabase.com/docs)-## Types of documentation--[https://supabase.com/docs](https://supabase.com/docs) has several different kinds of documentation, all coming from different sources.--### Guides--The primary, instructional type of content. Basically anything that lives on the `https://supabase.com/docs/guides` route. This includes Guides for Auth, Database, Storage, Realtime, Edge Functions, as well as general resources, self-hosting instructions, and integrations. These are all [`.mdx`](https://mdxjs.com/) files — a combination of Markdown and Javascript.--#### Things to know--Here's a simple [example](https://supabase.com/docs/guides/functions) `.mdx` Guide, and here is [the source on Github](https://raw.githubusercontent.com/supabase/supabase/master/apps/docs/pages/guides/functions.mdx).--Some things to note:--1. The files need to import a Layout at the top-2. The files need to export a `Page` at the bottom with the `<Layout>` component-3. The files frontmatter is stored in `const meta = {}`. You should always include `title` and `description`.-4. You can write Markdown as you normally would, but you can also write regular Javascript and JSX. Note the `examples` array that we iterate over.-5. Any Javascript variables you use in these files need to be exported in order to be used (i.e., `export const examples = []`).--##### Using components--You can use any standard React components in these `.mdx` files without having to explicitly import them in each file. All components get imported in a [common components](https://github.com/supabase/supabase/blob/master/apps/docs/components/index.tsx) file and can be used in any `.mdx` file. Components can also be "intercepted" and modified via this file. Note how we're intercepting the `h2`, `h3` and `code` tags and modifying them before converting the `mdx` to `html`.--### Reference docs for client libraries--We maintain client libraries for [JavaScript](https://supabase.com/docs/reference/javascript) and [Flutter/Dart](https://supabase.com/docs/reference/dart) (with more to come). These reference docs document every object and method available for developers to use. They are assembled from different sources and work much differently than the `.mdx` Guides we just looked at.--The client libraries are essentially wrappers around the clients for the various tools we use — GoTrue, PostgREST, Storage, Functions, and Realtime. The easiest way to describe how the things fit together is to look at an example and trace where the various pieces of information are coming from.--#### Example--Let's look at the [`updateUser()`](https://supabase.com/docs/reference/javascript/auth-updateuser) function in the `supabase-js` library.--#### Common file--Several pieces of information for this function come from a [common file](https://github.com/supabase/supabase/blob/3d774b3b7bcdcb410e25726d832467584ebea686/spec/common-client-libs-sections.json#L548) where we store information shared by all libraries.--1. id — used to identify this function-2. title - the human-readable title-3. slug — the url slug-4. product - the Supabase tool or product that "owns" this function. Since `updateUser()` is an Auth function, its product is `auth`-5. type — `updateUser()` is a function and marked as such, but we can also have sections of markdown interspersed with these function definitions.--When a new function is added, this info would need to be manually added to the common file.--#### Function Parameters--The `updateUser()` function takes one parameter: `attributes`. The details for this parameter live in the GoTrue client library, referenced via a `$ref` property in the `supabase-js` [spec file](https://github.com/supabase/supabase/blob/cb04d85262db6a371539dda7df9b00ba5a901e87/spec/supabase_js_v2.yml#L357). Here, the `$ref` property is pointing to the [actual function definition](https://github.com/supabase/gotrue-js/blob/2d60e79073b96ae8c97a6ce18e2601ed1e2a2712/src/GoTrueClient.ts#L590) in the `gotrue-js` library. The accepted values for the `attributes` parameter come from the [type definition](https://github.com/supabase/gotrue-js/blob/16d3deb822097e8640a3a15b94a5690b3beaf11b/src/lib/types.ts#L233).--These individual library spec files are fetched via this [Makefile](https://github.com/supabase/supabase/blob/master/spec/Makefile), and get [transformed](https://github.com/supabase/supabase/blob/master/spec/enrichments/tsdoc_v2/supabase_dereferenced.json) to combine the information we need (params, types, etc). Unless you're a library maintainer, you shouldn't need to worry about this part of the process.--If you are a library maintainer, the last important note about these library files is that the [Makefile](https://github.com/supabase/supabase/blob/master/spec/Makefile) pulls from the `gh-pages` branch of the client library repo. Here's an example of the [`realtime-js` spec file](https://github.com/supabase/realtime-js/blob/gh-pages/v2/spec.json). Updating something like function params or returns, the process is:--1. Get your changes merged to `master` in your library-2. This will kick off an action that automatically updates the spec file in the library's `gh-pages` branch-3. Run `make` in `/spec` of the `supabase/supabase` repo. This will regenerate all of the `tsdoc` files that the docs site uses-4. You should now see the changes you've made in the docs site locally--#### Function Examples--The `updateUser()` function has three examples listed with it. The examples are stored along with the `$ref` property in the [supabase_js_v2 spec file](https://github.com/supabase/supabase/blob/master/spec/supabase_js_v2.yml).--#### Rendering in Next.JS--These reference docs are rendered by Next.JS via a dynamic route using a [`[...slug.tsx]`](https://github.com/supabase/supabase/blob/master/apps/docs/pages/reference/javascript/%5B...slug%5D.tsx). Here, we use the library [spec file](https://github.com/supabase/supabase/blob/bd0514553c627db8f1e8d0b3ae440ccb6759d228/apps/docs/pages/reference/javascript/%5B...slug%5D.tsx#L4) and the [common file](https://github.com/supabase/supabase/blob/bd0514553c627db8f1e8d0b3ae440ccb6759d228/apps/docs/pages/reference/javascript/%5B...slug%5D.tsx#L1) to output the info you see on the page.--### Other reference docs--The reference docs for the [Supabase Management API](https://supabase.com/docs/reference/api) and the [Supabase CLI](https://supabase.com/docs/reference/cli) are a little more straightforward than the client libraries. Both files also have a [common file](https://github.com/supabase/supabase/blob/master/spec/common-cli-sections.json) which handles things like `title`, `id` and `slug`. Both also have a spec file detailing things like parameters, descriptions, and responses ([Management API](https://github.com/supabase/supabase/blob/master/spec/api_v0_openapi.json) / [CLI](https://github.com/supabase/supabase/blob/master/spec/cli_v1_commands.yaml))--On the Next.JS side of things, these work almost exactly the same as the client libraries with a dynamic [`[...slug.tsx]`](https://github.com/supabase/supabase/blob/master/apps/docs/pages/reference/cli/%5B...slug%5D.tsx).--### Misc--#### Search--Search is handled using a Supabase instance. During CI, [a script](https://github.com/supabase/supabase/blob/master/apps/docs/scripts/search/generate-embeddings.ts) aggregates all content sources (eg. guides, reference docs, etc), indexes them using OpenAI embeddings, and stores them in a Supabase database.+## Contributing-At runtime, an [Edge Function](https://github.com/supabase/supabase/blob/master/supabase/functions) is executed that performs a similarity search between the user's query and the above content sources using [`pgvector`](https://github.com/pgvector/pgvector) embeddings.+For repo organization and style guide, see the [contributing guide](https://github.com/supabase/supabase/blob/master/apps/docs/CONTRIBUTING.md).diff --git a/apps/docs/README.md b/apps/docs/README.mdindex 8068648d98f..c8a0cd91609 100644--- a/apps/docs/README.md+++ b/apps/docs/README.md@@ -6,17 +6,6 @@ Supabase Reference DocsIf you are a maintainer of any tools in the Supabase ecosystem, you can use this site to provide documentation for the tools & libraries that you maintain.-## Types of docs--There are many types of docs:--1. Guides: teach developers how to use a product. "I have XX problem, how do I solve it?"-2. Tutorials: walk-throughs, have a large outcome. "Build a React application with Supabase".-3. Explanations: teach developers about a broad topic. "What is a database?"-4. Reference: technical descriptions of tools and how to use them. "What errors does the API return?"--In these docs, you should focus only on the fourth type: "Reference Docs".-## VersioningAll tools have versioned docs, which are kept in separate folders. For example, the CLI has the following folders and files:@@ -43,3 +32,7 @@ We use documentation specifications which can be used to generate human-readableThe benefit of using custom specifications is that we can generate many other types from a strict schema (eg, HTML and manpages).It also means that we can switch to any documentation system we want. On this site we use Next.JS, but on Supabase's official website, we use a custom React site and expose only a subset of the available API for each tool.++## Contributing++To contribute to docs, see the [developers' guide](https://github.com/supabase/supabase/blob/master/apps/docs/DEVELOPERS.md) and [contributing guide](https://github.com/supabase/supabase/blob/master/apps/docs/CONTRIBUTING.md).