Context
I need a quick way to setup businesses, particularly software-as-a-service (SaaS).
My last speed build took 57 hours to build. A lot of that are stock-standard components that should be reusable (e.g. 11 hours spent on authentication, 4 hours spent on payment integration).
I have tried a few frameworks (Firebase, Amplify), but they eventually let me down when I want to implement a feature they do not support. I am not a fan of many frameworks. They add a level of abstraction that:
- Require learning something new
- Impose restrictions, eventually
- Add complexity in maintenance
Instead, I like templates. So the aim here is to create a simple SaaS repository that I can clone anytime I start a new speed build.
Requirements:
A basic app that allows users to create an account and increment their counter. The counter will only be allowed to exceed 5 if the user pays a monthly subscription fee.
The app will have:
- Multiple environments
- Local development environment
- Production environment
- Web UI
- Simple landing page
- Basic app
- Basic database
- Authentication and authorisation
- Payment
- Version control
- Testing
Out-of-scope:
- Real-time updates (e.g. websockets)
Summary
Stack:
- Backend
- Compute
- AWS: Lambda (written in Go v1.17)
- AWS: API Gateway (v2/HTTP)
- Database
- AWS: DynamoDB
- User identity
- AWS: Cognito
- Payments
- Stripe (checkout)
- Tooling
- Serverless v2.57
- Compute
- Frontend
- Landing page
- Vanilla HTML/CSS/JS
- App
- Vue v3.2, Vue-router v4.0, Vuex v4.0
- Tailwind v2.2, DaisyUI v1.16
- Tooling
- Vite v2.1
- TypeScript v4.4
- Landing page
- Tooling
- GitHub
Guide
-
Buy a domain, e.g. from Namecheap
-
Create a free email account on Gmail
-
Create a new AWS root account
-
Create a new AWS IAM user
-
Then create a profile in .aws/credentials
-
Update .env to include profile name
-
Setup a Hosted Zone in AWS’ Route53
-
Set domain’s nameservers to AWS on Namecheap
-
(Optional) Set up a mail server with Zoho
-
Create an S3 bucket and configure as a website (see script)
-
Create a Stripe account and a subscription product
-
Jump through hoops to deploy:
- Deploy to production
make deploy STAGE=${STAGE}
- Create a Stripe webhook with
customer.subscription.created
andcustomer.subscription.deleted
events sent to the appropriate API address (e.g. https://{api-id}.execute-api.{region}.amazonaws.com/subscription/webhook) - Update .env.production with the output from the previous command and the
Signing secret
from the Stripe webhook (e.g. whsec_abc123) - Reploy backend to production, build frontend, and then deploy frontend to bucket created above
make deploy STAGE=production make buildfront make deployfront AWS_PROFILE={profile} BUCKETNAME={bucketname}
The site should be available at http://{bucketname}.s3-website.{region}.amazonaws.com
-
Create a cloudfront distribution to direct requests to the domain to the S3 bucket