summaryrefslogtreecommitdiff
path: root/Documentation/source/architecture/data-and-auth.rst
diff options
context:
space:
mode:
authorBertrand Yuan <189593334+bertyuan@users.noreply.github.com>2026-04-27 20:54:16 +0800
committerGitHub <noreply@github.com>2026-04-27 20:54:16 +0800
commit85b6fb59db5fe1112c58eff9d02ae4f9c9b6456d (patch)
tree8c83fc84bd9547630e6733929dec77e102e055a8 /Documentation/source/architecture/data-and-auth.rst
parent658798b3a2378bb6df16cfbb16d707c6fb719e1e (diff)
parentdbb5e791f0c228369605d126dd590962ebe1eddc (diff)
Merge pull request #21 from bertyuan/Documentationv1.2
docs: add comprehensive documentation for operations
Diffstat (limited to 'Documentation/source/architecture/data-and-auth.rst')
-rw-r--r--Documentation/source/architecture/data-and-auth.rst72
1 files changed, 72 insertions, 0 deletions
diff --git a/Documentation/source/architecture/data-and-auth.rst b/Documentation/source/architecture/data-and-auth.rst
new file mode 100644
index 0000000..44736bd
--- /dev/null
+++ b/Documentation/source/architecture/data-and-auth.rst
@@ -0,0 +1,72 @@
+Data, Auth, and Comments
+========================
+
+Database Ownership
+------------------
+
+The repository uses PostgreSQL for both CMS data and application-owned data.
+The separation is logical:
+
+* Payload stores CMS data in the ``payload`` schema.
+* Application auth and comments use Drizzle schema objects and ``blog_*``
+ tables.
+
+This keeps CMS-managed structures separate from reader interaction data and
+allows application migrations to evolve without coupling every change to
+Payload internals.
+
+Authentication
+--------------
+
+Authentication is configured in ``src/server/auth/index.ts`` with better-auth
+and the Drizzle adapter. Current providers:
+
+* Google OAuth;
+* GitHub OAuth.
+
+The user model includes an additional ``role`` field with a default value of
+``user``. Session lookup is wrapped by ``getSession`` so route and component
+code does not need to call the better-auth API directly.
+
+Comments
+--------
+
+Comments are configured in ``src/server/comments/config.ts``. The Fuma Comments
+storage adapter receives the Drizzle database connection and these schemas:
+
+* ``comments``;
+* ``rates``;
+* ``roles``;
+* ``users``.
+
+The comment API route is mounted under ``/api/comments/[...comment]``. Frontend
+comment rendering belongs on post detail pages, while moderation and role
+policy should remain server-controlled.
+
+Migration Commands
+------------------
+
+.. list-table::
+ :header-rows: 1
+ :widths: 26 50
+
+ * - Command
+ - Use
+ * - ``pnpm db:generate``
+ - Generate Drizzle migration files after schema changes.
+ * - ``pnpm db:migrate``
+ - Apply Drizzle migrations.
+ * - ``pnpm db:push``
+ - Push schema changes directly during local development.
+ * - ``pnpm payload:migrate``
+ - Run Payload migrations.
+ * - ``pnpm payload:migrate:create``
+ - Create a new Payload migration.
+
+Implementation Rule
+-------------------
+
+When adding data-backed features, decide first whether the data is editorial or
+application-owned. Editorial content should be modeled in Payload collections.
+Account, interaction, moderation, and operational records should be modeled in
+Drizzle.