insforge 0.3.2 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (507) hide show
  1. package/.claude-plugin/marketplace.json +20 -0
  2. package/.cursor/rules/cursor-rules.mdc +94 -0
  3. package/.dockerignore +3 -0
  4. package/.env.example +33 -4
  5. package/.github/ISSUE_TEMPLATE/bug_report.yml +13 -60
  6. package/.github/ISSUE_TEMPLATE/config.yml +2 -2
  7. package/.github/ISSUE_TEMPLATE/feature_request.yml +10 -63
  8. package/.github/PULL_REQUEST_TEMPLATE.md +7 -0
  9. package/.github/workflows/build-image.yml +2 -1
  10. package/.github/workflows/e2e.yml +63 -0
  11. package/CHANGELOG.md +41 -0
  12. package/CLAUDE_PLUGIN.md +104 -0
  13. package/CODE_OF_CONDUCT.md +128 -0
  14. package/CONTRIBUTING.md +1 -1
  15. package/Dockerfile +4 -1
  16. package/README.md +66 -18
  17. package/assets/mcpInstallv2.png +0 -0
  18. package/assets/sampleResponse.png +0 -0
  19. package/auth/index.html +13 -0
  20. package/auth/package.json +28 -0
  21. package/auth/public/favicon.ico +0 -0
  22. package/auth/src/App.tsx +33 -0
  23. package/auth/src/components/ErrorCard.tsx +37 -0
  24. package/auth/src/components/Layout.tsx +13 -0
  25. package/auth/src/index.css +19 -0
  26. package/auth/src/lib/broadcastService.ts +115 -0
  27. package/auth/src/lib/utils.ts +11 -0
  28. package/auth/src/main.tsx +22 -0
  29. package/auth/src/pages/ForgotPasswordPage.tsx +11 -0
  30. package/auth/src/pages/ResetPasswordPage.tsx +11 -0
  31. package/auth/src/pages/SignInPage.tsx +57 -0
  32. package/auth/src/pages/SignUpPage.tsx +57 -0
  33. package/auth/src/pages/VerifyEmailPage.tsx +20 -0
  34. package/auth/src/vite-env.d.ts +10 -0
  35. package/auth/tsconfig.json +32 -0
  36. package/auth/tsconfig.node.json +11 -0
  37. package/auth/vite.config.ts +25 -0
  38. package/backend/package.json +9 -9
  39. package/backend/src/api/{middleware → middlewares}/auth.ts +8 -9
  40. package/backend/src/api/middlewares/rate-limiters.ts +127 -0
  41. package/backend/src/api/routes/{ai.ts → ai/index.routes.ts} +20 -24
  42. package/backend/src/api/routes/auth/index.routes.ts +570 -0
  43. package/backend/src/api/routes/auth/oauth.routes.ts +448 -0
  44. package/backend/src/api/routes/{database.advance.ts → database/advance.routes.ts} +107 -65
  45. package/backend/src/api/routes/database/index.routes.ts +13 -0
  46. package/backend/src/api/routes/{database.records.ts → database/records.routes.ts} +22 -8
  47. package/backend/src/api/routes/{database.tables.ts → database/tables.routes.ts} +20 -23
  48. package/backend/src/api/routes/docs/index.routes.ts +76 -0
  49. package/backend/src/api/routes/functions/index.routes.ts +188 -0
  50. package/backend/src/api/routes/{logs.ts → logs/index.routes.ts} +25 -30
  51. package/backend/src/api/routes/{metadata.ts → metadata/index.routes.ts} +21 -31
  52. package/backend/src/api/routes/{secrets.ts → secrets/index.routes.ts} +27 -22
  53. package/backend/src/api/routes/{storage.ts → storage/index.routes.ts} +34 -53
  54. package/backend/src/api/routes/usage/index.routes.ts +89 -0
  55. package/backend/src/infra/config/app.config.ts +51 -0
  56. package/backend/src/{core/database/manager.ts → infra/database/database.manager.ts} +76 -85
  57. package/backend/src/infra/database/migrations/013_create-auth-schema-functions.sql +44 -0
  58. package/backend/src/infra/database/migrations/014_add-updated-at-trigger-user-table.sql +8 -0
  59. package/backend/src/infra/database/migrations/015_create-auth-config-and-email-otp-tables.sql +60 -0
  60. package/backend/src/infra/database/migrations/016_update-auth-config-and-email-otp.sql +24 -0
  61. package/backend/src/{core/secrets/encryption.ts → infra/security/encryption.manager.ts} +3 -2
  62. package/backend/src/infra/security/token.manager.ts +125 -0
  63. package/backend/src/{core/socket/socket.ts → infra/socket/socket.manager.ts} +15 -15
  64. package/backend/src/providers/ai/openrouter.provider.ts +377 -0
  65. package/backend/src/providers/email/base.provider.ts +41 -0
  66. package/backend/src/providers/email/cloud.provider.ts +187 -0
  67. package/backend/src/{core/logs/providers → providers/logs}/base.provider.ts +11 -11
  68. package/backend/src/{core/logs/providers → providers/logs}/cloudwatch.provider.ts +61 -38
  69. package/backend/src/providers/logs/local.provider.ts +185 -0
  70. package/backend/src/providers/oauth/base.provider.ts +29 -0
  71. package/backend/src/providers/oauth/discord.provider.ts +195 -0
  72. package/backend/src/providers/oauth/facebook.provider.ts +194 -0
  73. package/backend/src/providers/oauth/github.provider.ts +208 -0
  74. package/backend/src/providers/oauth/google.provider.ts +249 -0
  75. package/backend/src/providers/oauth/index.ts +7 -0
  76. package/backend/src/providers/oauth/linkedin.provider.ts +240 -0
  77. package/backend/src/providers/oauth/microsoft.provider.ts +169 -0
  78. package/backend/src/providers/oauth/x.provider.ts +202 -0
  79. package/backend/src/providers/storage/base.provider.ts +29 -0
  80. package/backend/src/providers/storage/local.provider.ts +103 -0
  81. package/backend/src/providers/storage/s3.provider.ts +313 -0
  82. package/backend/src/server.ts +70 -74
  83. package/backend/src/{core/ai/config.ts → services/ai/ai-config.service.ts} +19 -24
  84. package/backend/src/services/ai/ai-model.service.ts +60 -0
  85. package/backend/src/{core/ai/usage.ts → services/ai/ai-usage.service.ts} +28 -35
  86. package/backend/src/{core/ai/chat.ts → services/ai/chat-completion.service.ts} +37 -24
  87. package/backend/src/services/ai/helpers.ts +64 -0
  88. package/backend/src/{core/ai/image.ts → services/ai/image-generation.service.ts} +17 -19
  89. package/backend/src/services/ai/index.ts +13 -0
  90. package/backend/src/services/auth/auth-config.service.ts +250 -0
  91. package/backend/src/services/auth/auth-otp.service.ts +424 -0
  92. package/backend/src/services/auth/auth.service.ts +1136 -0
  93. package/backend/src/services/auth/index.ts +4 -0
  94. package/backend/src/{core/auth/oauth.ts → services/auth/oauth-config.service.ts} +106 -52
  95. package/backend/src/{core/database/advance.ts → services/database/database-advance.service.ts} +97 -131
  96. package/backend/src/services/database/database-table.service.ts +811 -0
  97. package/backend/src/services/email/email.service.ts +75 -0
  98. package/backend/src/{core/functions/functions.ts → services/functions/function.service.ts} +95 -88
  99. package/backend/src/{core/logs/audit.ts → services/logs/audit.service.ts} +92 -75
  100. package/backend/src/services/logs/log.service.ts +73 -0
  101. package/backend/src/{core/secrets/secrets.ts → services/secrets/secret.service.ts} +48 -66
  102. package/backend/src/services/storage/storage.service.ts +617 -0
  103. package/backend/src/services/usage/usage.service.ts +149 -0
  104. package/backend/src/types/auth.ts +66 -2
  105. package/backend/src/types/email.ts +8 -0
  106. package/backend/src/types/error-constants.ts +4 -0
  107. package/backend/src/types/logs.ts +0 -29
  108. package/backend/src/{core/socket/types.ts → types/socket.ts} +5 -6
  109. package/backend/src/utils/environment.ts +9 -3
  110. package/backend/src/utils/logger.ts +20 -2
  111. package/backend/src/utils/seed.ts +150 -57
  112. package/backend/src/utils/sql-parser.ts +1 -1
  113. package/backend/src/utils/utils.ts +114 -0
  114. package/backend/src/utils/validations.ts +40 -4
  115. package/backend/tests/local/test-ai-config.sh +129 -0
  116. package/backend/tests/local/test-ai-usage.sh +80 -0
  117. package/backend/tests/local/test-auth-router.sh +1 -1
  118. package/backend/tests/local/test-e2e.sh +1 -1
  119. package/backend/tests/local/test-functions.sh +123 -0
  120. package/backend/tests/local/test-logs.sh +132 -0
  121. package/backend/tests/local/test-public-bucket.sh +3 -3
  122. package/backend/tests/local/test-secrets.sh +14 -12
  123. package/backend/tests/local/test-traditional-rest.sh +2 -2
  124. package/backend/tests/manual/test-rawsql-modes.sh +244 -0
  125. package/backend/tests/test-config.sh +37 -1
  126. package/backend/tests/unit/cloud-token.test.ts +48 -0
  127. package/backend/tests/unit/constant.test.ts +8 -0
  128. package/backend/tests/unit/email.test.ts +372 -0
  129. package/backend/tests/unit/environment.test.ts +59 -0
  130. package/backend/tests/unit/helpers.test.ts +63 -0
  131. package/backend/tests/unit/logger.test.ts +22 -0
  132. package/backend/tests/unit/rate-limit.test.ts +154 -0
  133. package/backend/tests/unit/response.test.ts +58 -0
  134. package/backend/tests/unit/sql-parser.test.ts +74 -0
  135. package/backend/tests/unit/uuid.test.ts +21 -0
  136. package/backend/tests/unit/validations.test.ts +80 -0
  137. package/backend/tsconfig.json +1 -1
  138. package/backend/vitest.config.ts +11 -0
  139. package/claude-plugin/.claude-plugin/plugin.json +24 -0
  140. package/claude-plugin/README.md +133 -0
  141. package/claude-plugin/skills/insforge-schema-patterns/SKILL.md +270 -0
  142. package/docker-compose.prod.yml +60 -4
  143. package/docker-compose.yml +65 -4
  144. package/docker-init/db/db-init.sql +6 -34
  145. package/docker-init/logs/vector.yml +236 -0
  146. package/docs/README.md +44 -0
  147. package/docs/changelog.mdx +67 -0
  148. package/docs/core-concepts/ai/architecture.mdx +373 -0
  149. package/docs/core-concepts/ai/sdk.mdx +213 -0
  150. package/docs/core-concepts/authentication/architecture.mdx +278 -0
  151. package/docs/core-concepts/authentication/sdk.mdx +414 -0
  152. package/docs/core-concepts/authentication/ui-components/customization.mdx +529 -0
  153. package/docs/core-concepts/authentication/ui-components/nextjs.mdx +221 -0
  154. package/docs/core-concepts/authentication/ui-components/react-router.mdx +184 -0
  155. package/docs/core-concepts/authentication/ui-components/react.mdx +129 -0
  156. package/docs/core-concepts/database/architecture.mdx +256 -0
  157. package/docs/core-concepts/database/sdk.mdx +382 -0
  158. package/docs/core-concepts/functions/architecture.mdx +105 -0
  159. package/docs/core-concepts/functions/sdk.mdx +184 -0
  160. package/docs/core-concepts/storage/architecture.mdx +243 -0
  161. package/docs/core-concepts/storage/sdk.mdx +253 -0
  162. package/docs/deployment/README.md +94 -0
  163. package/docs/deployment/deploy-to-aws-ec2.md +565 -0
  164. package/docs/deployment/deploy-to-azure-virtual-machines.md +313 -0
  165. package/docs/deployment/deploy-to-google-cloud-compute-engine.md +613 -0
  166. package/docs/deployment/deploy-to-render.md +441 -0
  167. package/docs/docs.json +210 -0
  168. package/docs/examples/framework-guides/nextjs.mdx +131 -0
  169. package/docs/examples/framework-guides/nuxt.mdx +165 -0
  170. package/docs/examples/framework-guides/react.mdx +165 -0
  171. package/docs/examples/framework-guides/svelte.mdx +153 -0
  172. package/docs/examples/framework-guides/vue.mdx +159 -0
  173. package/docs/examples/overview.mdx +67 -0
  174. package/docs/favicon.svg +19 -0
  175. package/docs/images/changelog/nov-2025/auth-components.webp +0 -0
  176. package/docs/images/changelog/nov-2025/database-metadata.webp +0 -0
  177. package/docs/images/changelog/nov-2025/quickstart-prompts.webp +0 -0
  178. package/docs/images/changelog/nov-2025/sql-editor.webp +0 -0
  179. package/docs/images/changelog/nov-2025/usage-page.webp +0 -0
  180. package/docs/images/changelog/october-2025/csv-upload.webp +0 -0
  181. package/docs/images/changelog/october-2025/logs-feature.webp +0 -0
  182. package/docs/images/changelog/october-2025/oauth-providers.webp +0 -0
  183. package/docs/images/checks-passed.png +0 -0
  184. package/docs/images/dashboard-connect-expanded.png +0 -0
  185. package/docs/images/dashboard-connect.png +0 -0
  186. package/docs/images/hero-dark.png +0 -0
  187. package/docs/images/hero-light.png +0 -0
  188. package/docs/images/icons/ai.svg +4 -0
  189. package/docs/images/icons/auth.svg +1 -0
  190. package/docs/images/icons/database.svg +1 -0
  191. package/docs/images/icons/function.svg +1 -0
  192. package/docs/images/icons/storage.svg +1 -0
  193. package/docs/images/logos/nextjs.svg +4 -0
  194. package/docs/images/logos/nuxt.svg +4 -0
  195. package/docs/images/logos/react.svg +5 -0
  196. package/docs/images/logos/svelte.svg +4 -0
  197. package/docs/images/logos/vue.svg +5 -0
  198. package/docs/images/mcp-install.png +0 -0
  199. package/docs/images/onboarding-mcp.png +0 -0
  200. package/docs/insforge-instructions-sdk.md +55 -374
  201. package/docs/introduction.mdx +45 -0
  202. package/docs/logo/dark.svg +22 -0
  203. package/docs/logo/light.svg +20 -0
  204. package/docs/partnership.mdx +647 -0
  205. package/docs/quickstart.mdx +83 -0
  206. package/docs/showcase/2048-arena.png +0 -0
  207. package/docs/showcase/framegen-cloud.png +0 -0
  208. package/docs/showcase/line-connect-race.png +0 -0
  209. package/docs/showcase/moment-vibe.png +0 -0
  210. package/docs/showcase/national-flags.png +0 -0
  211. package/docs/showcase/pokemon-vibe.png +0 -0
  212. package/docs/showcase/pure-browse-buy.png +0 -0
  213. package/docs/showcase.mdx +52 -0
  214. package/docs/snippets/sdk-installation.mdx +22 -0
  215. package/docs/snippets/service-icons.mdx +27 -0
  216. package/eslint.config.js +10 -3
  217. package/frontend/package.json +10 -4
  218. package/frontend/src/App.tsx +13 -82
  219. package/frontend/src/assets/icons/connected.svg +3 -0
  220. package/frontend/src/assets/icons/loader.svg +9 -0
  221. package/frontend/src/assets/logos/apple.svg +4 -0
  222. package/frontend/src/assets/logos/discord.svg +1 -1
  223. package/frontend/src/assets/logos/facebook.svg +3 -0
  224. package/frontend/src/assets/logos/instagram.svg +2 -0
  225. package/frontend/src/assets/logos/linkedin.svg +3 -0
  226. package/frontend/src/assets/logos/microsoft.svg +1 -0
  227. package/frontend/src/assets/logos/spotify.svg +17 -0
  228. package/frontend/src/assets/logos/tiktok.svg +6 -0
  229. package/frontend/src/assets/logos/x.svg +3 -0
  230. package/frontend/src/components/Checkbox.tsx +27 -29
  231. package/frontend/src/components/CodeBlock.tsx +55 -2
  232. package/frontend/src/components/CodeEditor.tsx +92 -0
  233. package/frontend/src/components/ConfirmDialog.tsx +1 -1
  234. package/frontend/src/components/ConnectCTA.tsx +38 -0
  235. package/frontend/src/components/CopyButton.tsx +52 -15
  236. package/frontend/src/components/ErrorState.tsx +1 -2
  237. package/frontend/src/components/FeatureSidebar.tsx +6 -6
  238. package/frontend/src/components/FeatureSidebarItem.tsx +2 -2
  239. package/frontend/src/components/JsonHighlight.tsx +21 -9
  240. package/frontend/src/components/ProjectInfoModal.tsx +128 -0
  241. package/frontend/src/components/PromptDialog.tsx +1 -4
  242. package/frontend/src/components/SearchInput.tsx +1 -2
  243. package/frontend/src/components/Stepper.tsx +53 -0
  244. package/frontend/src/components/ThemeToggle.tsx +3 -3
  245. package/frontend/src/components/datagrid/DataGrid.tsx +25 -32
  246. package/frontend/src/components/datagrid/cell-editors/DateCellEditor.tsx +1 -2
  247. package/frontend/src/components/datagrid/cell-editors/JsonCellEditor.tsx +2 -4
  248. package/frontend/src/components/datagrid/index.ts +23 -0
  249. package/frontend/src/components/index.ts +23 -30
  250. package/frontend/src/components/layout/AppHeader.tsx +133 -92
  251. package/frontend/src/components/layout/AppSidebar.tsx +80 -170
  252. package/frontend/src/components/layout/Layout.tsx +12 -23
  253. package/frontend/src/components/layout/PrimaryMenu.tsx +187 -0
  254. package/frontend/src/components/layout/SecondaryMenu.tsx +70 -0
  255. package/frontend/src/components/layout/index.ts +5 -0
  256. package/frontend/src/components/radix/Tooltip.tsx +24 -13
  257. package/frontend/src/components/radix/index.ts +22 -0
  258. package/frontend/src/features/ai/components/AIConfigCard.tsx +129 -83
  259. package/frontend/src/features/ai/components/AIEmptyState.tsx +12 -7
  260. package/frontend/src/features/ai/components/ModalityFilterSidebar.tsx +101 -0
  261. package/frontend/src/features/ai/components/ModelSelectionDialog.tsx +135 -0
  262. package/frontend/src/features/ai/components/ModelSelectionGrid.tsx +51 -0
  263. package/frontend/src/features/ai/components/SystemPromptDialog.tsx +118 -0
  264. package/frontend/src/features/ai/components/index.ts +6 -0
  265. package/frontend/src/features/ai/helpers.ts +57 -71
  266. package/frontend/src/features/ai/hooks/useAIConfigs.ts +39 -113
  267. package/frontend/src/features/ai/hooks/useAIUsage.ts +0 -2
  268. package/frontend/src/features/ai/page/AIPage.tsx +67 -79
  269. package/frontend/src/features/ai/services/ai.service.ts +5 -5
  270. package/frontend/src/features/auth/components/AuthPreview.tsx +96 -0
  271. package/frontend/src/features/auth/components/OAuthConfigDialog.tsx +53 -30
  272. package/frontend/src/features/auth/components/UserFormDialog.tsx +13 -6
  273. package/frontend/src/features/auth/components/UsersDataGrid.tsx +44 -14
  274. package/frontend/src/features/auth/components/index.ts +5 -0
  275. package/frontend/src/features/auth/helpers.tsx +200 -0
  276. package/frontend/src/features/auth/hooks/useAnonToken.ts +30 -0
  277. package/frontend/src/features/auth/hooks/useAuthConfig.ts +48 -0
  278. package/frontend/src/features/auth/hooks/useOAuthConfig.ts +14 -10
  279. package/frontend/src/features/auth/hooks/useUsers.ts +43 -5
  280. package/frontend/src/features/auth/index.ts +3 -2
  281. package/frontend/src/features/auth/page/AuthMethodsPage.tsx +275 -0
  282. package/frontend/src/features/auth/page/ConfigurationPage.tsx +395 -0
  283. package/frontend/src/features/auth/page/UsersPage.tsx +285 -0
  284. package/frontend/src/features/auth/services/anonToken.service.ts +11 -0
  285. package/frontend/src/features/auth/services/config.service.ts +19 -0
  286. package/frontend/src/features/auth/services/{oauth.service.ts → oauth-config.service.ts} +4 -4
  287. package/frontend/src/features/auth/services/{auth.service.ts → user.service.ts} +7 -53
  288. package/frontend/src/features/dashboard/components/ConnectionSuccessBanner.tsx +35 -0
  289. package/frontend/src/features/dashboard/components/PromptCard.tsx +21 -0
  290. package/frontend/src/features/dashboard/components/PromptDialog.tsx +103 -0
  291. package/frontend/src/features/dashboard/components/StatsCard.tsx +50 -0
  292. package/frontend/src/features/dashboard/components/index.ts +4 -0
  293. package/frontend/src/features/dashboard/page/DashboardPage.tsx +187 -169
  294. package/frontend/src/features/dashboard/prompts/ai-chatbot.ts +13 -0
  295. package/frontend/src/features/dashboard/prompts/crm-system.ts +13 -0
  296. package/frontend/src/features/dashboard/prompts/ecommerce-platform.ts +12 -0
  297. package/frontend/src/features/dashboard/prompts/index.ts +31 -0
  298. package/frontend/src/features/dashboard/prompts/instagram-clone.ts +11 -0
  299. package/frontend/src/features/dashboard/prompts/notion-clone.ts +14 -0
  300. package/frontend/src/features/dashboard/prompts/reddit-clone.ts +12 -0
  301. package/frontend/src/features/database/components/DatabaseDataGrid.tsx +48 -17
  302. package/frontend/src/features/database/components/ForeignKeyCell.tsx +15 -34
  303. package/frontend/src/features/database/components/ForeignKeyPopover.tsx +19 -20
  304. package/frontend/src/features/database/components/LinkRecordModal.tsx +120 -125
  305. package/frontend/src/features/database/components/RecordFormDialog.tsx +22 -33
  306. package/frontend/src/features/database/components/RecordFormField.tsx +45 -47
  307. package/frontend/src/features/database/components/TableEmptyState.tsx +6 -5
  308. package/frontend/src/features/database/components/TableForm.tsx +28 -15
  309. package/frontend/src/features/database/components/TableFormColumn.tsx +2 -3
  310. package/frontend/src/features/database/components/TableSidebar.tsx +1 -1
  311. package/frontend/src/features/database/components/TablesEmptyState.tsx +48 -0
  312. package/frontend/src/features/database/components/TemplateCard.tsx +37 -0
  313. package/frontend/src/features/database/components/TemplatePreview.tsx +92 -0
  314. package/frontend/src/features/database/components/index.ts +19 -0
  315. package/frontend/src/features/database/constants.ts +28 -2
  316. package/frontend/src/features/database/contexts/SQLEditorContext.tsx +188 -0
  317. package/frontend/src/features/database/helpers.ts +2 -2
  318. package/frontend/src/features/database/hooks/useCSVImport.ts +29 -0
  319. package/frontend/src/features/database/hooks/useFullMetadata.ts +18 -0
  320. package/frontend/src/features/database/hooks/useRawSQL.ts +55 -0
  321. package/frontend/src/features/database/hooks/useRecords.ts +139 -0
  322. package/frontend/src/features/database/hooks/useTables.ts +131 -0
  323. package/frontend/src/features/database/index.ts +6 -1
  324. package/frontend/src/features/database/page/FunctionsPage.tsx +211 -0
  325. package/frontend/src/features/database/page/IndexesPage.tsx +240 -0
  326. package/frontend/src/features/database/page/PoliciesPage.tsx +248 -0
  327. package/frontend/src/features/database/page/SQLEditorPage.tsx +382 -0
  328. package/frontend/src/features/database/page/{DatabasePage.tsx → TablesPage.tsx} +186 -185
  329. package/frontend/src/features/database/page/TemplatesPage.tsx +39 -0
  330. package/frontend/src/features/database/page/TriggersPage.tsx +242 -0
  331. package/frontend/src/features/database/services/advance.service.ts +66 -0
  332. package/frontend/src/features/database/services/{database.service.ts → record.service.ts} +67 -64
  333. package/frontend/src/features/database/services/table.service.ts +64 -0
  334. package/frontend/src/features/database/templates/ai-chatbot.ts +402 -0
  335. package/frontend/src/features/database/templates/crm-system.ts +528 -0
  336. package/frontend/src/features/database/templates/ecommerce-platform.ts +553 -0
  337. package/frontend/src/features/database/templates/index.ts +34 -0
  338. package/frontend/src/features/database/templates/instagram-clone.ts +222 -0
  339. package/frontend/src/features/database/templates/notion-clone.ts +483 -0
  340. package/frontend/src/features/database/templates/reddit-clone.ts +526 -0
  341. package/frontend/src/features/functions/components/FunctionRow.tsx +2 -1
  342. package/frontend/src/features/functions/components/FunctionsSidebar.tsx +1 -1
  343. package/frontend/src/features/functions/components/SecretRow.tsx +1 -1
  344. package/frontend/src/features/functions/components/index.ts +5 -0
  345. package/frontend/src/features/functions/hooks/useFunctions.ts +4 -4
  346. package/frontend/src/features/{secrets → functions}/hooks/useSecrets.ts +5 -5
  347. package/frontend/src/features/functions/page/FunctionsPage.tsx +160 -17
  348. package/frontend/src/features/functions/{components/SecretsContent.tsx → page/SecretsPage.tsx} +8 -12
  349. package/frontend/src/features/functions/services/{functions.service.ts → function.service.ts} +2 -2
  350. package/frontend/src/features/{secrets/services/secrets.service.ts → functions/services/secret.service.ts} +2 -2
  351. package/frontend/src/features/login/hooks/usePartnerOrigin.ts +27 -0
  352. package/frontend/src/features/login/page/CloudLoginPage.tsx +79 -54
  353. package/frontend/src/features/login/page/LoginPage.tsx +16 -23
  354. package/frontend/src/features/login/services/partnership.service.ts +65 -0
  355. package/frontend/src/features/logs/components/LogsDataGrid.tsx +89 -0
  356. package/frontend/src/features/logs/components/SeverityBadge.tsx +18 -0
  357. package/frontend/src/features/logs/components/index.ts +2 -0
  358. package/frontend/src/features/logs/helpers.ts +24 -0
  359. package/frontend/src/features/logs/hooks/useAuditLogs.ts +4 -4
  360. package/frontend/src/features/logs/hooks/useLogSources.ts +137 -0
  361. package/frontend/src/features/logs/hooks/useLogs.ts +163 -0
  362. package/frontend/src/features/logs/hooks/useMcpUsage.ts +181 -0
  363. package/frontend/src/features/logs/index.ts +8 -2
  364. package/frontend/src/features/logs/page/AuditsPage.tsx +91 -38
  365. package/frontend/src/features/logs/page/LogsPage.tsx +152 -0
  366. package/frontend/src/features/logs/page/MCPLogsPage.tsx +84 -0
  367. package/frontend/src/features/logs/services/audit.service.ts +63 -0
  368. package/frontend/src/features/logs/services/log.service.ts +15 -110
  369. package/frontend/src/features/logs/services/usage.service.ts +31 -0
  370. package/frontend/src/features/onboard/components/McpConnectionStatus.tsx +68 -0
  371. package/frontend/src/features/onboard/components/OnboardingModal.tsx +267 -0
  372. package/frontend/src/features/onboard/components/VideoDemoModal.tsx +38 -0
  373. package/frontend/src/features/onboard/components/index.ts +4 -0
  374. package/frontend/src/features/onboard/components/mcp/CursorDeeplinkGenerator.tsx +2 -2
  375. package/frontend/src/features/onboard/components/mcp/{mcp-helper.tsx → helpers.tsx} +8 -8
  376. package/frontend/src/features/onboard/components/mcp/index.ts +2 -3
  377. package/frontend/src/features/onboard/index.ts +13 -3
  378. package/frontend/src/features/storage/components/BucketEmptyState.tsx +9 -6
  379. package/frontend/src/features/storage/components/BucketFormDialog.tsx +25 -41
  380. package/frontend/src/features/storage/components/FilePreviewDialog.tsx +20 -8
  381. package/frontend/src/features/storage/components/StorageDataGrid.tsx +4 -3
  382. package/frontend/src/features/storage/components/StorageManager.tsx +23 -34
  383. package/frontend/src/features/storage/components/index.ts +12 -0
  384. package/frontend/src/features/storage/hooks/useStorage.ts +208 -0
  385. package/frontend/src/features/storage/page/StoragePage.tsx +41 -115
  386. package/frontend/src/features/storage/services/storage.service.ts +22 -1
  387. package/frontend/src/features/visualizer/components/AuthNode.tsx +72 -56
  388. package/frontend/src/features/visualizer/components/BucketNode.tsx +4 -4
  389. package/frontend/src/features/visualizer/components/SchemaVisualizer.tsx +108 -80
  390. package/frontend/src/features/visualizer/components/TableNode.tsx +34 -41
  391. package/frontend/src/features/visualizer/components/VisualizerSkeleton.tsx +12 -4
  392. package/frontend/src/features/visualizer/page/VisualizerPage.tsx +33 -29
  393. package/frontend/src/index.css +1 -0
  394. package/frontend/src/lib/analytics/posthog.tsx +27 -0
  395. package/frontend/src/lib/contexts/AuthContext.tsx +38 -31
  396. package/frontend/src/lib/contexts/SocketContext.tsx +5 -6
  397. package/frontend/src/{features/metadata → lib}/hooks/useMetadata.ts +1 -1
  398. package/frontend/src/lib/hooks/useToast.tsx +6 -2
  399. package/frontend/src/lib/routing/AppRoutes.tsx +84 -0
  400. package/frontend/src/lib/routing/RequireAuth.tsx +27 -0
  401. package/frontend/src/lib/utils/cloudMessaging.ts +20 -0
  402. package/frontend/src/lib/utils/menuItems.ts +183 -0
  403. package/frontend/src/lib/utils/{validation-schemas.ts → schemaValidations.ts} +10 -5
  404. package/frontend/src/lib/utils/utils.ts +19 -1
  405. package/frontend/src/vite-env.d.ts +1 -0
  406. package/frontend/vite.config.ts +5 -3
  407. package/functions/server.ts +28 -3
  408. package/functions/worker-template.js +15 -4
  409. package/i18n/README.ar.md +130 -0
  410. package/i18n/README.de.md +130 -0
  411. package/i18n/README.es.md +154 -0
  412. package/i18n/README.fr.md +134 -0
  413. package/i18n/README.hi.md +129 -0
  414. package/i18n/README.ja.md +174 -0
  415. package/i18n/README.ko.md +137 -0
  416. package/i18n/README.pt-BR.md +131 -0
  417. package/i18n/README.ru.md +129 -0
  418. package/i18n/README.zh-CN.md +133 -0
  419. package/openapi/ai.yaml +31 -4
  420. package/openapi/auth.yaml +827 -146
  421. package/package.json +16 -7
  422. package/shared-schemas/package.json +1 -1
  423. package/shared-schemas/src/ai-api.schema.ts +34 -58
  424. package/shared-schemas/src/ai.schema.ts +5 -0
  425. package/shared-schemas/src/auth-api.schema.ts +154 -8
  426. package/shared-schemas/src/auth.schema.ts +42 -6
  427. package/shared-schemas/src/cloud-events.schema.ts +57 -0
  428. package/shared-schemas/src/database-api.schema.ts +3 -3
  429. package/shared-schemas/src/database.schema.ts +1 -1
  430. package/shared-schemas/src/index.ts +1 -0
  431. package/shared-schemas/src/logs-api.schema.ts +7 -1
  432. package/shared-schemas/src/logs.schema.ts +26 -0
  433. package/shared-schemas/src/metadata.schema.ts +9 -4
  434. package/test-gemini.sh +35 -0
  435. package/test-usage-admin.sh +57 -0
  436. package/test-usage.sh +50 -0
  437. package/zeabur/README.md +13 -0
  438. package/zeabur/template.yml +1032 -0
  439. package/.github/workflows/deploy-aws.yml +0 -130
  440. package/backend/src/api/routes/agent.ts +0 -29
  441. package/backend/src/api/routes/auth.oauth.ts +0 -482
  442. package/backend/src/api/routes/auth.ts +0 -386
  443. package/backend/src/api/routes/docs.ts +0 -66
  444. package/backend/src/api/routes/functions.ts +0 -183
  445. package/backend/src/api/routes/openapi.ts +0 -82
  446. package/backend/src/api/routes/usage.ts +0 -96
  447. package/backend/src/core/ai/client.ts +0 -242
  448. package/backend/src/core/ai/model.ts +0 -117
  449. package/backend/src/core/auth/auth.ts +0 -781
  450. package/backend/src/core/database/table.ts +0 -772
  451. package/backend/src/core/documentation/agent.ts +0 -689
  452. package/backend/src/core/documentation/openapi.ts +0 -856
  453. package/backend/src/core/logs/analytics.ts +0 -76
  454. package/backend/src/core/logs/providers/localdb.provider.ts +0 -246
  455. package/backend/src/core/storage/storage.ts +0 -923
  456. package/backend/src/utils/cloud-token.ts +0 -39
  457. package/backend/src/utils/helpers.ts +0 -49
  458. package/backend/src/utils/uuid.ts +0 -9
  459. package/backend/tests/manual/test-better-auth.sh +0 -303
  460. package/docker-init/db/logs.sql +0 -9
  461. package/frontend/README.md +0 -112
  462. package/frontend/src/components/datagrid/index.tsx +0 -20
  463. package/frontend/src/components/layout/CloudLayout.tsx +0 -95
  464. package/frontend/src/features/ai/components/AIConfigDialog.tsx +0 -76
  465. package/frontend/src/features/ai/components/AIConfigForm.tsx +0 -222
  466. package/frontend/src/features/ai/components/fields/ModalityField.tsx +0 -87
  467. package/frontend/src/features/ai/components/fields/ModelSelectionField.tsx +0 -134
  468. package/frontend/src/features/ai/components/fields/SystemPromptField.tsx +0 -33
  469. package/frontend/src/features/auth/components/AddOAuthDialog.tsx +0 -106
  470. package/frontend/src/features/auth/components/AuthMethodTab.tsx +0 -238
  471. package/frontend/src/features/auth/components/UsersTab.tsx +0 -114
  472. package/frontend/src/features/auth/page/AuthenticationPage.tsx +0 -169
  473. package/frontend/src/features/database/hooks/UseLinkModal.tsx +0 -78
  474. package/frontend/src/features/functions/components/FunctionViewer.tsx +0 -46
  475. package/frontend/src/features/functions/components/FunctionsContent.tsx +0 -88
  476. package/frontend/src/features/login/components/AuthErrorBoundary.tsx +0 -87
  477. package/frontend/src/features/login/components/PrivateRoute.tsx +0 -24
  478. package/frontend/src/features/logs/components/AnalyticsLogsTable.tsx +0 -313
  479. package/frontend/src/features/logs/components/LogsTable.tsx +0 -199
  480. package/frontend/src/features/logs/page/AnalyticsLogsPage.tsx +0 -530
  481. package/frontend/src/features/metadata/index.ts +0 -0
  482. package/frontend/src/features/metadata/page/MetadataPage.tsx +0 -136
  483. package/frontend/src/features/onboard/components/CompletionCard.tsx +0 -41
  484. package/frontend/src/features/onboard/components/OnboardButton.tsx +0 -84
  485. package/frontend/src/features/onboard/components/StepContent.tsx +0 -91
  486. package/frontend/src/features/onboard/components/TestConnectionStep.tsx +0 -53
  487. package/frontend/src/features/onboard/components/mcp/McpInstallation.tsx +0 -144
  488. package/frontend/src/features/onboard/page/OnBoardPage.tsx +0 -104
  489. package/frontend/src/features/onboard/types.ts +0 -8
  490. package/frontend/src/lib/contexts/OnboardStepContext.tsx +0 -68
  491. package/frontend/src/lib/hooks/useOnboardingCompletion.ts +0 -29
  492. /package/backend/src/api/{middleware → middlewares}/error.ts +0 -0
  493. /package/backend/src/api/{middleware → middlewares}/upload.ts +0 -0
  494. /package/backend/{migrations → src/infra/database/migrations}/000_create-base-tables.sql +0 -0
  495. /package/backend/{migrations → src/infra/database/migrations}/001_create-helper-functions.sql +0 -0
  496. /package/backend/{migrations → src/infra/database/migrations}/002_rename-auth-tables.sql +0 -0
  497. /package/backend/{migrations → src/infra/database/migrations}/003_create-users-table.sql +0 -0
  498. /package/backend/{migrations → src/infra/database/migrations}/004_add-reload-postgrest-func.sql +0 -0
  499. /package/backend/{migrations → src/infra/database/migrations}/005_enable-project-admin-modify-users.sql +0 -0
  500. /package/backend/{migrations → src/infra/database/migrations}/006_modify-ai-usage-table.sql +0 -0
  501. /package/backend/{migrations → src/infra/database/migrations}/007_drop-metadata-table.sql +0 -0
  502. /package/backend/{migrations → src/infra/database/migrations}/008_add-system-tables.sql +0 -0
  503. /package/backend/{migrations → src/infra/database/migrations}/009_add-function-secrets.sql +0 -0
  504. /package/backend/{migrations → src/infra/database/migrations}/010_modify-ai-config-modalities.sql +0 -0
  505. /package/backend/{migrations → src/infra/database/migrations}/011_refactor-secrets-table.sql +0 -0
  506. /package/backend/{migrations → src/infra/database/migrations}/012_add-storage-uploaded-by.sql +0 -0
  507. /package/frontend/src/{features/metadata → lib}/services/metadata.service.ts +0 -0
@@ -0,0 +1,256 @@
1
+ ---
2
+ title: Architecture
3
+ description: PostgreSQL database with automatic REST APIs via PostgREST
4
+ ---
5
+
6
+ ## Overview
7
+
8
+ InsForge uses a powerful database stack that automatically generates REST APIs from your PostgreSQL schema, eliminating the need to write backend CRUD code.
9
+
10
+ ## Technology Stack
11
+
12
+ ```mermaid
13
+ graph TB
14
+ Client[Client Application] --> SDK[InsForge SDK]
15
+ SDK --> API[InsForge API]
16
+ API --> PostgREST[PostgREST v12.2]
17
+ PostgREST --> PG[(PostgreSQL 15)]
18
+ API --> PG
19
+
20
+ PG --> RLS[Row Level Security]
21
+ PG --> Triggers[Database Triggers]
22
+ PG --> Functions[Stored Functions]
23
+ PG --> Schemas[Multiple Schemas]
24
+
25
+ style Client fill:#1e293b,stroke:#475569,color:#e2e8f0
26
+ style SDK fill:#1e40af,stroke:#3b82f6,color:#dbeafe
27
+ style API fill:#166534,stroke:#22c55e,color:#dcfce7
28
+ style PostgREST fill:#c2410c,stroke:#fb923c,color:#fed7aa
29
+ style PG fill:#0e7490,stroke:#06b6d4,color:#cffafe
30
+ style RLS fill:#4c1d95,stroke:#8b5cf6,color:#ede9fe
31
+ style Triggers fill:#4c1d95,stroke:#8b5cf6,color:#ede9fe
32
+ style Functions fill:#4c1d95,stroke:#8b5cf6,color:#ede9fe
33
+ style Schemas fill:#4c1d95,stroke:#8b5cf6,color:#ede9fe
34
+ ```
35
+
36
+ ## Core Components
37
+
38
+ | Component | Technology | Version | Purpose |
39
+ |-----------|------------|---------|---------|
40
+ | **Database** | PostgreSQL | 15.13 | ACID-compliant relational database |
41
+ | **REST API** | PostgREST | 12.2.12 | Auto-generates RESTful APIs from public schema only |
42
+ | **Query Engine** | PostgREST DSL | - | Powerful filtering with operators and functions |
43
+ | **Security** | Row Level Security | - | Fine-grained access control at the row level |
44
+ | **Roles** | PostgreSQL Roles | - | anon (read-only), authenticated (CRUD), project_admin (full) |
45
+ | **SDK** | @insforge/sdk | Latest | Type-safe JavaScript/TypeScript client |
46
+
47
+ ## How It Works
48
+
49
+ ### 1. Schema Definition
50
+ When you create a table through the InsForge API or migrations:
51
+ - Table structure is stored in PostgreSQL
52
+ - PostgREST discovers the schema via database introspection
53
+ - REST endpoints are instantly available
54
+
55
+ ### 2. API Generation
56
+ PostgREST automatically creates endpoints:
57
+ - `GET /api/database/records/{table}` - Query records
58
+ - `POST /api/database/records/{table}` - Insert records
59
+ - `PATCH /api/database/records/{table}` - Update records
60
+ - `DELETE /api/database/records/{table}` - Delete records
61
+
62
+ ### 3. Query Translation
63
+ HTTP requests are converted to optimized SQL:
64
+ ```
65
+ GET /api/database/records/products?price=gte.100&category=eq.electronics
66
+
67
+ SELECT * FROM products
68
+ WHERE price >= 100
69
+ AND category = 'electronics'
70
+ ```
71
+
72
+ ### 4. Security Layer
73
+ - JWT tokens are validated on each request
74
+ - User ID extracted from token
75
+ - RLS policies applied based on user context
76
+ - Only authorized rows are returned
77
+
78
+ ### 5. Response Format
79
+ - Results returned as JSON arrays
80
+ - HTTP status codes indicate success/failure
81
+ - Headers include pagination info
82
+
83
+ ## PostgREST Features
84
+
85
+ <CardGroup cols={2}>
86
+ <Card title="Instant APIs" icon="bolt">
87
+ Every table gets full CRUD endpoints automatically without writing any backend code
88
+ </Card>
89
+
90
+ <Card title="Advanced Filtering" icon="filter">
91
+ Complex queries with operators like `eq`, `gt`, `like`, `in`, `is`, `or`
92
+ </Card>
93
+
94
+ <Card title="Relationship Embedding" icon="link">
95
+ Join related tables in single requests using foreign key relationships
96
+ </Card>
97
+
98
+ <Card title="Bulk Operations" icon="layer-group">
99
+ Insert, update, or delete multiple records in a single atomic transaction
100
+ </Card>
101
+
102
+ <Card title="Computed Fields" icon="calculator">
103
+ Expose database functions and views as API endpoints
104
+ </Card>
105
+
106
+ <Card title="Real-time Updates" icon="sync">
107
+ NOTIFY/LISTEN for schema changes without restart
108
+ </Card>
109
+ </CardGroup>
110
+
111
+ ## Database Structure
112
+
113
+ InsForge uses two PostgreSQL databases:
114
+
115
+ ### Main Database (`insforge`)
116
+ All application and system tables reside in the `public` schema:
117
+
118
+ | Table Type | Purpose | Examples |
119
+ |------------|---------|----------|
120
+ | **User Tables** | Created by developers | Any table you create |
121
+ | **System Tables** | Internal InsForge tables | Prefixed with `_` |
122
+
123
+ ### Analytics Database (`_insforge`)
124
+ Separate database for analytics with `_analytics` schema for Logflare integration.
125
+
126
+ ### System Tables (in `public` schema)
127
+
128
+ | Table | Purpose |
129
+ |-------|---------|
130
+ | `_accounts` | Core user authentication records |
131
+ | `users` | User profile data (references _accounts) |
132
+ | `_account_providers` | OAuth provider connections |
133
+ | `_storage_buckets` | Storage bucket configuration |
134
+ | `_storage` | File metadata and references |
135
+ | `_ai_configs` | AI model configurations per project |
136
+ | `_ai_usage` | AI token usage tracking |
137
+ | `_config` | System configuration key-value store |
138
+ | `_metadata` | Application metadata |
139
+ | `_mcp_usage` | MCP tool usage tracking |
140
+ | `_edge_functions` | Serverless function definitions |
141
+ | `logs` | Activity and audit logs |
142
+
143
+ ## Query Syntax
144
+
145
+ PostgREST provides a powerful query syntax that maps to SQL:
146
+
147
+ ### Operators
148
+
149
+ | Operator | SQL Equivalent | Example |
150
+ |----------|---------------|---------|
151
+ | `eq` | `=` | `?id=eq.123` |
152
+ | `neq` | `!=` | `?status=neq.deleted` |
153
+ | `gt` | `>` | `?age=gt.18` |
154
+ | `gte` | `>=` | `?price=gte.100` |
155
+ | `lt` | `<` | `?created=lt.2024-01-01` |
156
+ | `lte` | `<=` | `?quantity=lte.10` |
157
+ | `like` | `LIKE` | `?name=like.*john*` |
158
+ | `ilike` | `ILIKE` | `?email=ilike.*gmail*` |
159
+ | `in` | `IN` | `?status=in.(active,pending)` |
160
+ | `is` | `IS` | `?deleted_at=is.null` |
161
+
162
+ ### Complex Queries
163
+
164
+ ```javascript
165
+ // Combine conditions with AND
166
+ GET /api/database/records/products?price=gte.100&category=eq.electronics
167
+
168
+ // OR conditions
169
+ GET /api/database/records/products?or=(price.lt.50,on_sale.is.true)
170
+
171
+ // Nested conditions
172
+ GET /api/database/records/orders?and=(status.eq.pending,or=(priority.eq.high,created_at.lt.2024-01-01))
173
+ ```
174
+
175
+ ## Performance Optimizations
176
+
177
+ ### Connection Pooling
178
+ - PgBouncer manages database connections
179
+ - Reduces connection overhead
180
+ - Handles concurrent requests efficiently
181
+
182
+ ### Query Optimization
183
+ - PostgREST generates optimized SQL
184
+ - Uses prepared statements
185
+ - Leverages PostgreSQL query planner
186
+
187
+ ### Indexing Strategy
188
+ - Automatic indexes on primary keys
189
+ - Foreign key indexes for joins
190
+ - Custom indexes via migrations
191
+
192
+ ### Caching
193
+ - ETags for conditional requests
194
+ - Client-side caching support
195
+ - Response compression
196
+
197
+ ## Data Types
198
+
199
+ PostgreSQL types are automatically mapped to JSON:
200
+
201
+ | InsForge Type | PostgreSQL Type | JSON Type | Notes |
202
+ |---------------|----------------|-----------|-------|
203
+ | `string` | `TEXT` | string | Text of any length |
204
+ | `integer` | `INTEGER` | number | 32-bit integers |
205
+ | `float` | `DOUBLE PRECISION` | number | Decimal numbers |
206
+ | `boolean` | `BOOLEAN` | boolean | true/false |
207
+ | `date` | `DATE` | string | ISO 8601 date format |
208
+ | `datetime` | `TIMESTAMPTZ` | string | ISO 8601 with timezone |
209
+ | `uuid` | `UUID` | string | Auto-generated unique identifier |
210
+ | `json` | `JSONB` | object/array | Structured JSON data with indexing |
211
+
212
+ ## Best Practices
213
+
214
+ <CardGroup cols={2}>
215
+ <Card title="Use Indexes" icon="gauge">
216
+ Create indexes on frequently queried columns
217
+ </Card>
218
+
219
+ <Card title="Leverage RLS" icon="shield">
220
+ Implement Row Level Security for data isolation
221
+ </Card>
222
+
223
+ <Card title="Batch Operations" icon="boxes">
224
+ Use bulk inserts/updates for better performance
225
+ </Card>
226
+
227
+ <Card title="Select Columns" icon="table-columns">
228
+ Query only needed columns to reduce payload
229
+ </Card>
230
+
231
+ <Card title="Use Views" icon="eye">
232
+ Create views for complex queries
233
+ </Card>
234
+
235
+ <Card title="Monitor Performance" icon="chart-line">
236
+ Use EXPLAIN ANALYZE for slow queries
237
+ </Card>
238
+ </CardGroup>
239
+
240
+ ## Limitations
241
+
242
+ - **No Custom Business Logic**: PostgREST handles CRUD only
243
+ - **SQL Knowledge Helpful**: Complex queries benefit from SQL understanding
244
+ - **Schema Changes**: Require PostgREST reload (automatic via NOTIFY)
245
+ - **File Handling**: Use storage API for files, not database
246
+
247
+ ## Comparison with Traditional APIs
248
+
249
+ | Aspect | Traditional REST API | InsForge + PostgREST |
250
+ |--------|---------------------|----------------------|
251
+ | **Development Time** | Write CRUD for each table | Instant APIs from schema |
252
+ | **Maintenance** | Update code for schema changes | Automatic updates |
253
+ | **Performance** | Depends on implementation | Optimized SQL generation |
254
+ | **Consistency** | Varies by developer | Uniform API patterns |
255
+ | **Documentation** | Manual updates needed | Auto-generated OpenAPI |
256
+ | **Security** | Custom implementation | Built-in RLS + JWT |
@@ -0,0 +1,382 @@
1
+ ---
2
+ title: Database SDK Reference
3
+ description: Type-safe database operations using the InsForge SDK
4
+ ---
5
+
6
+ import Installation from '/snippets/sdk-installation.mdx';
7
+
8
+ <Installation />
9
+
10
+ ## insert()
11
+
12
+ Insert new records into a table.
13
+
14
+ ### Parameters
15
+
16
+ - `values` (object | Array, required) - Data to insert. Single object or array for bulk insert
17
+ - `options.count` ('exact' | 'planned' | 'estimated', optional) - Include count of inserted rows
18
+
19
+ ### Returns
20
+
21
+ ```typescript
22
+ {
23
+ data: Array<object> | null,
24
+ error: Error | null,
25
+ count?: number
26
+ }
27
+ ```
28
+
29
+ <Note>
30
+ Chain `.select()` after `.insert()` to return the inserted data
31
+ </Note>
32
+
33
+ ### Examples
34
+
35
+ <CodeGroup>
36
+ ```javascript Single insert
37
+ const { data, error } = await insforge.database
38
+ .from('users')
39
+ .insert({ name: 'John', email: 'john@example.com' })
40
+ .select()
41
+ ```
42
+
43
+ ```javascript Bulk insert
44
+ const { data, error } = await insforge.database
45
+ .from('users')
46
+ .insert([
47
+ { name: 'Alice', email: 'alice@example.com' },
48
+ { name: 'Bob', email: 'bob@example.com' }
49
+ ])
50
+ .select()
51
+ ```
52
+ </CodeGroup>
53
+
54
+ ### Output Example
55
+
56
+ ```json
57
+ {
58
+ "data": [
59
+ { "id": "789", "name": "John", "email": "john@example.com", "created_at": "2024-01-15T10:30:00Z" }
60
+ ],
61
+ "error": null
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ ## update()
68
+
69
+ Update existing records in a table. Must use filters to target specific rows.
70
+
71
+ ### Parameters
72
+
73
+ - `values` (object, required) - Fields to update
74
+ - `options.count` ('exact' | 'planned' | 'estimated', optional) - Include count of updated rows
75
+
76
+ ### Returns
77
+
78
+ ```typescript
79
+ {
80
+ data: Array<object> | null,
81
+ error: Error | null,
82
+ count?: number
83
+ }
84
+ ```
85
+
86
+ <Warning>
87
+ Always use filters like `.eq()` or `.in()` to specify which rows to update
88
+ </Warning>
89
+
90
+ ### Examples
91
+
92
+ <CodeGroup>
93
+ ```javascript Update by ID
94
+ const { data, error } = await insforge.database
95
+ .from('users')
96
+ .update({ name: 'Jane Doe' })
97
+ .eq('id', userId)
98
+ .select()
99
+ ```
100
+
101
+ ```javascript Update multiple
102
+ const { data, error } = await insforge.database
103
+ .from('tasks')
104
+ .update({ status: 'completed' })
105
+ .in('id', ['task-1', 'task-2'])
106
+ .select()
107
+ ```
108
+ </CodeGroup>
109
+
110
+ ### Output Example
111
+
112
+ ```json
113
+ {
114
+ "data": [
115
+ { "id": "123", "name": "Jane Doe", "email": "john@example.com", "updated_at": "2024-01-15T11:00:00Z" }
116
+ ],
117
+ "error": null
118
+ }
119
+ ```
120
+
121
+ ---
122
+
123
+ ## delete()
124
+
125
+ Delete records from a table. Must use filters to target specific rows.
126
+
127
+ ### Parameters
128
+
129
+ - `options.count` ('exact' | 'planned' | 'estimated', optional) - Include count of deleted rows
130
+
131
+ ### Returns
132
+
133
+ ```typescript
134
+ {
135
+ data: Array<object> | null,
136
+ error: Error | null,
137
+ count?: number
138
+ }
139
+ ```
140
+
141
+ <Warning>
142
+ Always use filters to specify which rows to delete
143
+ </Warning>
144
+
145
+ ### Examples
146
+
147
+ <CodeGroup>
148
+ ```javascript Delete by ID
149
+ const { error } = await insforge.database
150
+ .from('posts')
151
+ .delete()
152
+ .eq('id', postId)
153
+ ```
154
+
155
+ ```javascript Delete with filter
156
+ const { error } = await insforge.database
157
+ .from('sessions')
158
+ .delete()
159
+ .lt('expires_at', new Date())
160
+ ```
161
+ </CodeGroup>
162
+
163
+ ### Output Example
164
+
165
+ ```json
166
+ {
167
+ "data": null,
168
+ "error": null
169
+ }
170
+ ```
171
+
172
+ ---
173
+
174
+ ## select()
175
+
176
+ Query records from a table or view.
177
+
178
+ ### Parameters
179
+
180
+ - `columns` (string, optional) - Comma-separated column names. Use `*` for all columns
181
+ - `options.count` ('exact' | 'planned' | 'estimated', optional) - Include total row count
182
+ - `options.head` (boolean, optional) - Return only count, no data
183
+
184
+ ### Returns
185
+
186
+ ```typescript
187
+ {
188
+ data: Array<object> | null,
189
+ error: Error | null,
190
+ count?: number
191
+ }
192
+ ```
193
+
194
+ ### Examples
195
+
196
+ <CodeGroup>
197
+ ```javascript Get all
198
+ const { data, error } = await insforge.database
199
+ .from('users')
200
+ .select()
201
+ ```
202
+
203
+ ```javascript Specific columns
204
+ const { data, error } = await insforge.database
205
+ .from('users')
206
+ .select('id, name, email')
207
+ ```
208
+
209
+ ```javascript With relationships
210
+ const { data, error } = await insforge.database
211
+ .from('posts')
212
+ .select('*, users(nickname, avatar_url)')
213
+ ```
214
+ </CodeGroup>
215
+
216
+ ### Output Example
217
+
218
+ ```json
219
+ {
220
+ "data": [
221
+ { "id": "123", "name": "John", "email": "john@example.com" },
222
+ { "id": "456", "name": "Jane", "email": "jane@example.com" }
223
+ ],
224
+ "error": null
225
+ }
226
+ ```
227
+
228
+ ---
229
+
230
+ ## Filters
231
+
232
+ Chain filters to narrow down query results. All filters take `(column, value)` as parameters.
233
+
234
+ | Filter | Description | Example |
235
+ |--------|-------------|---------|
236
+ | `.eq(column, value)` | Equals | `.eq('status', 'active')` |
237
+ | `.neq(column, value)` | Not equals | `.neq('status', 'banned')` |
238
+ | `.gt(column, value)` | Greater than | `.gt('age', 18)` |
239
+ | `.gte(column, value)` | Greater than or equal | `.gte('price', 100)` |
240
+ | `.lt(column, value)` | Less than | `.lt('stock', 10)` |
241
+ | `.lte(column, value)` | Less than or equal | `.lte('priority', 3)` |
242
+ | `.like(column, pattern)` | Case-sensitive pattern (use `%` wildcard) | `.like('name', '%Widget%')` |
243
+ | `.ilike(column, pattern)` | Case-insensitive pattern (use `%` wildcard) | `.ilike('email', '%@gmail.com')` |
244
+ | `.in(column, array)` | Value in array | `.in('status', ['pending', 'active'])` |
245
+ | `.is(column, value)` | Exactly equals (for null checks) | `.is('deleted_at', null)` |
246
+
247
+ ```javascript
248
+ // Example: Chain multiple filters
249
+ const { data } = await insforge.database
250
+ .from('products')
251
+ .select()
252
+ .eq('category', 'electronics')
253
+ .gte('price', 50)
254
+ .lte('price', 500)
255
+ .is('in_stock', true)
256
+ ```
257
+
258
+ ---
259
+
260
+ ## Modifiers
261
+
262
+ Control how query results are returned.
263
+
264
+ | Modifier | Description | Example |
265
+ |----------|-------------|---------|
266
+ | `.order(column, options)` | Sort results. Options: `{ ascending: true/false, nullsFirst: true/false }` | `.order('created_at', { ascending: false })` |
267
+ | `.limit(count)` | Limit number of rows | `.limit(10)` |
268
+ | `.range(from, to)` | Get rows between indices (pagination) | `.range(0, 9)` |
269
+ | `.single()` | Return object instead of array (throws if multiple) | `.single()` |
270
+ | `.maybeSingle()` | Return object or null (no error) | `.maybeSingle()` |
271
+
272
+ ```javascript
273
+ // Example: Pagination with sorting
274
+ const { data } = await insforge.database
275
+ .from('posts')
276
+ .select()
277
+ .order('created_at', { ascending: false })
278
+ .range(0, 9)
279
+ .limit(10)
280
+ ```
281
+
282
+ ---
283
+
284
+ ## Common Patterns
285
+
286
+ ### Pagination with Count
287
+
288
+ ```javascript
289
+ const page = 1;
290
+ const pageSize = 10;
291
+ const from = (page - 1) * pageSize;
292
+ const to = from + pageSize - 1;
293
+
294
+ const { data, count } = await insforge.database
295
+ .from('posts')
296
+ .select('*', { count: 'exact' })
297
+ .range(from, to)
298
+ .order('created_at', { ascending: false })
299
+
300
+ console.log(`Page ${page}: ${data.length} of ${count} total`)
301
+ ```
302
+
303
+ **Output:**
304
+ ```json
305
+ {
306
+ "data": [
307
+ { "id": "1", "title": "Post 1", "created_at": "2024-01-15T10:00:00Z" },
308
+ { "id": "2", "title": "Post 2", "created_at": "2024-01-14T10:00:00Z" }
309
+ ],
310
+ "count": 50,
311
+ "error": null
312
+ }
313
+ ```
314
+
315
+ ### Filtered Search
316
+
317
+ ```javascript
318
+ const { data } = await insforge.database
319
+ .from('products')
320
+ .select('id, name, price, category')
321
+ .eq('category', 'electronics')
322
+ .gte('price', 50)
323
+ .lte('price', 500)
324
+ .order('price', { ascending: true })
325
+ .limit(20)
326
+ ```
327
+
328
+ **Output:**
329
+ ```json
330
+ {
331
+ "data": [
332
+ { "id": "101", "name": "USB Cable", "price": 59.99, "category": "electronics" },
333
+ { "id": "102", "name": "Keyboard", "price": 89.99, "category": "electronics" }
334
+ ],
335
+ "error": null
336
+ }
337
+ ```
338
+
339
+ ### Using with Authentication Hooks
340
+
341
+ Combine database queries with `useUser()` or `useAuth()` hooks to fetch user-specific data:
342
+
343
+ ```tsx
344
+ import { useUser } from '@insforge/react'; // or '@insforge/react-router'
345
+ import { insforge } from './lib/insforge';
346
+ import { useEffect, useState } from 'react';
347
+
348
+ function MyProfile() {
349
+ const { user, isLoaded } = useUser();
350
+ const [posts, setPosts] = useState([]);
351
+
352
+ useEffect(() => {
353
+ if (user) {
354
+ // Fetch user's posts from database
355
+ insforge.database
356
+ .from('posts')
357
+ .select('*')
358
+ .eq('user_id', user.id)
359
+ .then(({ data }) => setPosts(data));
360
+ }
361
+ }, [user]);
362
+
363
+ if (!isLoaded) return <div>Loading...</div>;
364
+ if (!user) return <div>Not signed in</div>;
365
+
366
+ return (
367
+ <div>
368
+ <h1>{user.name}</h1>
369
+ <p>{user.email}</p>
370
+ <h2>My Posts: {posts.length}</h2>
371
+ {posts.map(post => (
372
+ <div key={post.id}>{post.title}</div>
373
+ ))}
374
+ </div>
375
+ );
376
+ }
377
+ ```
378
+
379
+ **Key points:**
380
+ - Use `user.id` to filter data for the authenticated user
381
+ - Check `isLoaded` before accessing `user` to avoid race conditions
382
+ - Check `!user` to handle unauthenticated state