The official Nx plugin for Supabase
Automated migrations, type generation, and local dev setup for Nx monorepos.
Building modern applications with Supabase in an Nx monorepo? This plugin streamlines your entire workflow:
- Zero Configuration - Auto-detect Supabase projects via
config.toml - Smart Port Management - Run multiple Supabase instances without conflicts
- Nx Caching - Generated types are cached and only regenerated when needed
- Full Lifecycle Support - From local dev to production deployment
| Feature | Description |
|---|---|
| Generators | Scaffold Supabase projects, migrations, Edge Functions, and seed files |
| Executors | Start/stop local instances, run migrations, generate types, deploy |
| Type Safety | Auto-generate TypeScript types from your database schema |
| Multi-Project | Support multiple Supabase instances with automatic port allocation |
| Project Inference | Auto-detect and configure targets via createNodesV2 |
| Docker Orchestration | Full local Supabase stack management |
Before you begin, ensure you have:
- Node.js 18+ installed
- Docker Desktop installed and running
- Supabase CLI installed:
# Via npm
npm install -g supabase
# Or via Homebrew (macOS)
brew install supabase/tap/supabasenpm install @nxsupabase/supabase --save-devnx g @nxsupabase/supabase:initThis registers the plugin in your nx.json and configures target defaults.
Run the generator and follow the interactive prompts:
nx g @nxsupabase/supabase:projectAll generators support interactive prompts - just run the command without flags and you'll be guided through the options.
This creates the Supabase directory structure:
apps/my-app/
└── supabase/
├── config.toml # Supabase configuration
├── migrations/ # Database migrations
├── functions/ # Edge Functions
└── seed.sql # Seed data
nx run my-app:supabase-startThis spins up the full Supabase stack locally (PostgreSQL, Auth, Storage, Realtime, etc.)
nx g @nxsupabase/supabase:migration --project=my-app --name=create_users_tablenx run my-app:supabase-gen-typesTypes are automatically cached by Nx and regenerated only when migrations change.
| Generator | Description | Command |
|---|---|---|
init |
Initialize plugin in workspace | nx g @nxsupabase/supabase:init |
project |
Add Supabase to a project | nx g @nxsupabase/supabase:project --project=<name> |
migration |
Create a database migration | nx g @nxsupabase/supabase:migration --project=<name> --name=<migration> |
function |
Create an Edge Function | nx g @nxsupabase/supabase:function --project=<name> --name=<function> --template=<basic|crud|webhook|x402> |
seed |
Create a seed file | nx g @nxsupabase/supabase:seed --project=<name> |
| Executor | Description | Command |
|---|---|---|
supabase-start |
Start local Supabase | nx run <project>:supabase-start |
supabase-stop |
Stop local Supabase | nx run <project>:supabase-stop |
supabase-status |
Show status and URLs | nx run <project>:supabase-status |
supabase-db-reset |
Reset database | nx run <project>:supabase-db-reset |
supabase-gen-types |
Generate TS types | nx run <project>:supabase-gen-types |
supabase-migrate |
Run migrations | nx run <project>:supabase-migrate |
supabase-db-push |
Push to remote | nx run <project>:supabase-db-push |
supabase-deploy |
Deploy to cloud | nx run <project>:supabase-deploy |
supabase-functions-serve |
Serve functions locally | nx run <project>:supabase-functions-serve |
Run multiple Supabase instances in your monorepo:
# Start all Supabase instances
nx run-many -t supabase-start
# Generate types for all projects
nx run-many -t supabase-gen-types
# Only affected projects
nx affected -t supabase-db-resetConfigure the plugin in nx.json:
{
"plugins": [
{
"plugin": "@nxsupabase/supabase",
"options": {
"startTargetName": "supabase-start",
"stopTargetName": "supabase-stop",
"genTypesTargetName": "supabase-gen-types"
}
}
]
}The plugin loads environment variables from (in order):
- Workspace root
.env - Workspace root
.env.local - Project
.env - Project
.env.local
Common variables:
| Variable | Description |
|---|---|
SUPABASE_ACCESS_TOKEN |
Authentication for deployment |
SUPABASE_DB_PASSWORD |
Remote database password |
SUPABASE_PROJECT_REF |
Remote project reference |
import { createClient } from '@supabase/supabase-js';
import type { Database } from './types/supabase';
const supabase = createClient<Database>(
process.env.SUPABASE_URL!,
process.env.SUPABASE_ANON_KEY!
);
// Fully typed queries
const { data: users } = await supabase
.from('users')
.select('id, email, created_at')
.eq('active', true);
// TypeScript knows the shape of `users`nx g @nxsupabase/supabase:function --project=my-app --name=send-email --template=basic// supabase/functions/send-email/index.ts
import { serve } from 'https://deno.land/[email protected]/http/server.ts';
serve(async (req) => {
const { to, subject, body } = await req.json();
// Your email logic here
return new Response(JSON.stringify({ success: true }), {
headers: { 'Content-Type': 'application/json' },
});
});# Link to your Supabase project
npx supabase link --project-ref your-project-ref
# Deploy everything
nx run my-app:supabase-deployContributions are welcome! Please read our contributing guidelines before submitting a PR.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with love for the Nx and Supabase communities