8.2 KiB
Nuxt 3 (SAAS) Boilerplate
Not Production Ready
Please don't hitch your wagon to this star just yet... I'm coding this in the open and the TODO list is verrrrrry long.
Tech Stack
- Nuxt 3 (I like it, shut up)
- Supabase (Auth including OAuth + Postgresql instance)
- Prisma (Schema management + Strongly typed client)
- TRPC (Server/Client communication with Strong types, SSR compatible)
- Pinia (State Store. I liked vuex a lot, in particular explicit mutations but gotta go with the cool crowd)
- Stripe (Payments including Webhook integration)
Features
User Management
- User authentication via Supabase including Social Signon (e.g. google) Email/Password (TODO) and Magic Link
- Full list of available providers
- User roles and permissions (admin, regular user, etc. roles defined in the Prisma Schema)
- User Email captured on initial login
- Initial plan and plan period controled via config to allow either a trial plan or a 'No Plan' for initial users
- Edit Account Name from Account Page
Schema and DB Management
- Prisma based Schema Management
- Supabase integration for DB
- Smart DB initialisation script including Plan and Stripe Product information, maybe templated
Config Management and Env integration
- Config for Stripe Keys
- Env keys for Supabase and Stripe
- Config Switches for free trial - If you want a 'free trial period' set initialPlanName to an appropriate plan name in the DB and initialPlanActiveMonths to a positive value. If you don't want a free trial, set initialPlanName to an appropriate 'No Plan' plan in the DB and set the initialPlanActiveMonths to -1.
Multi-Modal State Management
- SPA type pages (e.g. Dashboard) - postgresql(supabase) -> Prisma -> Service Layer for Business Logic -> TRPC -> Pinia -> UI
- SSR type pages (e.g. Note) - postgresql(supabase) -> Prisma -> Service Layer for Business Logic -> TRPC -> UI
Multi User Accounts (Teams)
- Allow users to upgrade their accounts fron individual accounts to multi-user accounts (Teams).
- Allow users to switch between Teams and view/edit data from the selected Team.
- All features, billing and limits is controlled at the Account (Team) level (not the user level)
- Team administrators and owners can administer the permissions (roles) of other team members on the Accounts page
- Gen/Regen an invite link to allow users to join a team
Plans and Pricing
- Manage multiple Plans each with specific Feature flags and Plan limits
- Plan features copied to Accounts upon successfull subscription
- Loose coupling between Plan and Account Features to allow ad-hoc account tweaks without creating custom plans
- Pricing page appropriately reacts to users with/without account and current plan.
- Plan features and Limits available in an object structure in Server methods and with method annotations or similar
Stripe (Payments) Integration
- Each plan is configured with Stripe Product ID so that multiple Stripe Prices can be created for each plan but subscriptions (via Webhook) will still activate the correct plan.
- Support basic (customer.subscription) flows for Subscription payments via Webhook
- Support additional Stripe flows for things like failed payments, imminent subscription expiry (send email?) etc.....
Support
- Help desk support (ticketing system, live chat, etc.)
- Knowledge base with FAQs and tutorials
Look and Feel, Design System and Customisation
- Very Crap default UI
- Not Crap UI
- Integrated Design system (Bootstrap? Tailwind?)
- Branding options (logo, color scheme, etc.)
Demo Software (Notes)
- Simple Text based Notes functionality
- Read only Notes Dashboard
- SSR Rendered (SEO Optimised) Note Display
- Max Notes limit property on Plan
- Max Notes enforced
- Optional public SSR Rendered public notes index page
- Add, Delete, edit notes on Dashboard
Mobile App
- Flutter App Demo integrating with API endpoints, Auth etc
- Mobile-friendly web interface.
Testing
- Unit tests for server functions
- Integration tests around subscription scenarios
Special Mention
This https://blog.checklyhq.com/building-a-multi-tenant-saas-data-model/ Article by https://twitter.com/tim_nolet was my inspiration for the user/account/subscription schema. Tim was also generous with his time and answered some of my stoopid questions on the https://www.reddit.com/r/SaaS/ Subreddit.
Externals Setup
Things you gotta do that aren't code (and are therefore not very interesting)
Env
Copy the .env_example file to create .env Note) This file is for development convenience, is .gitignored by default and should not be added to source control
Supabase
This solution uses Supabase for Auth and to provide a DB. In addition to Magic Link and email/password login via Supabase, it also supports Google OAuth via Supabase.
- Go to Supabase and 'Start your Project'
- Setup your org and project (Free tier is fine to start)
- Update the project's email template
- Choose an OAuth provider. I have chosen Google using these Instructions for the purposes of demonstration but they all should work.
- Go to Project Settings -> API and copy Project URL and Project API Key to SUPABASE_URL and SUPABASE_KEY settings respectively in your .env file
- Go to Project Settings -> Database -> Connection String -> URI and copy the uri value into the DATABASE_URL setting in your .env file, remembering to replace
[YOUR-PASSWORD]with the password you provided when you setup the project.
Setup Database (Prisma)
This solution uses Prisma to both manage changes and connect to the Postgresql database provided by Supabase. Your Supabase DB will be empty by default so you need to hydrate the schema and re-generate the local prisma client.
npx prisma db push
npx prisma generate
npm install @prisma/client --save-dev
...you should now have a bunch of empty tables in your Supabase DB
Stripe
This solution uses Stripe for Subscription payments.
- Go to Stripe and setup your business (Free Tier is fine to start)
- Create 2 products ('Team Plan' and 'Individual Plan') each with a single price and note the Product ID's and Price ID's
- Manually edit the Plan table in Supabase and add 3 rows as shown below making sure to replace the
stripe_product_idfields with the appropriate values
| id | name | features | max_notes | stripe_product_id | max_members |
|---|---|---|---|---|---|
| 1 | Free Trial | ADD_NOTES,EDIT_NOTES,VIEW_NOTES | 10 | 1 | |
| 2 | Individual Plan | ADD_NOTES,EDIT_NOTES,VIEW_NOTES,SPECIAL_FEATURE | 100 | [your product id] | 1 |
| 3 | Team Plan | ADD_NOTES,EDIT_NOTES,VIEW_NOTES,SPECIAL_FEATURE,SPECIAL_TEAM_FEATURE | 200 | [your other product id] | 10 |
- Edit the Pricing pricing page and put your Price ID's into the appropriate hidden
price_idform fields...
<input type="hidden" name="price_id" value="[Your Price ID from Stripe]" />
Developement Setup
Dependencies
# yarn
yarn install
# npm
npm install
# pnpm
pnpm install --shamefully-hoist
Webhook Forwarding
This makes sure that you can debug subscription workflows locally
stripe listen --forward-to localhost:3000/webhook
Start the development server on http://localhost:3000
npm run dev
Production
Build the application for production:
npm run build
Locally preview production build:
npm run preview
Check out the deployment documentation for more information.