• Stars
    star
    4,033
  • Rank 10,787 (Top 0.3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build your own SaaS business with SaaS boilerplate. Productive stack: React, Material-UI, Next, MobX, WebSockets, Express, Node, Mongoose, MongoDB. Written with TypeScript.

image

Support Ukraine: link

SaaS Boilerplate

Open source web app that saves you many days of work when building your own SaaS product. The boilerplate comes with many basic SaaS features (see Features below) so that you can focus on features that differentiate your product.

If you want to learn how to build this project from scratch, check out our book: https://builderbook.org/book

The open source project is located in the saas folder. If you purchased our book, codebases for each of the book's chapters are located in the book folder.

Live demo:

Sponsors

aws-activate-logo

1password-logo

Showcase

Check out projects built with the help of this open source app. Feel free to add your own project by creating a pull request.

  • Async: Open source web app for team communication, separate urgent vs. non-urgent conversations.
  • workinbiotech.com: Work in biotech, job board for small and young biotech companies
  • Retaino by Earl Lee: Save, annotate, review, and share great web content. Receive smart email digests to retain key information.
  • Builder Book: Open source web app to publish documentation or books.

Contents

Features

  • Server-side rendering for fast initial load and SEO.
  • User authentication with Google OAuth API and Passwordless, cookie, and session.
  • Production-ready Express server with compression, parser, and helmet.
  • Transactional emails (AWS SES): welcome, team invitation, and payment.
  • Adding email addresses to newsletter lists (Mailchimp): new users, paying users.
  • File upload, load, and deletion (AWS S3) with pre-signed request for: Posts, Team Profile, and User Profile.
  • Websockets with socket.io v3.
  • Team creation, Team Member invitation, and settings for Team and User.
  • Opinionated architecture:
    • keeping babel and webpack configurations under the hood,
    • striving to minimize number of configurations,
    • withAuth HOC to pass user prop and control user access to pages,
    • HOC extensions MyApp and MyDocument
    • server-side rendering with Material-UI,
    • model-specific components in addition to common components.
  • Universally-available environmental variables at runtime.
  • Custom logger (configure what not to print in production).
  • Useful components for any web app: ActiveLink, Confirm, Notifier, MenuWithLinks, and more.
  • Analytics with Google Analytics.
  • Production-ready, scalable architecture:
    • app - user-facing web app with Next/Express server, responsible for rendering pages (either client-side or server-side rendered). app sends requests via API methods to api Express server.
    • api - server-only code, Express server, responsible for processing requests for internal and external API infrastructures.
  • Subscriptions with Stripe:
    • subscribe/unsubscribe Team to plan,
    • update card information,
    • verified Stripe webhook for failed payment for subscription.

Running api locally:

  • Before running, create a .env file inside the api folder with the environmental variables as shown below. These variables are also listed in .env.example, which you can use as a template to create your own .env file inside the api foler.

api/.env:

# Used in api/server/server.ts
MONGO_URL_TEST=
MONGO_URL=
SESSION_NAME=
SESSION_SECRET=
COOKIE_DOMAIN=

# Used in api/server/google.ts
GOOGLE_CLIENTID=
GOOGLE_CLIENTSECRET=

# Used in api/server/aws-s3.ts and api/server/aws-ses.ts
AWS_REGION=
AWS_ACCESSKEYID=
AWS_SECRETACCESSKEY=

# Used in api/server/models/Invitation.ts and api/server/models/User.ts
EMAIL_SUPPORT_FROM_ADDRESS=

# Used in api/server/mailchimp.ts
MAILCHIMP_API_KEY=
MAILCHIMP_REGION=
MAILCHIMP_SAAS_ALL_LIST_ID=

----------
# All env variables above this line are needed for successful user signup

# Used in api/server/stripe.ts
STRIPE_TEST_SECRETKEY=sk_test_xxxxxx
STRIPE_LIVE_SECRETKEY=sk_live_xxxxxx

STRIPE_TEST_PLANID=plan_xxxxxx
STRIPE_LIVE_PLANID=plan_xxxxxx

STRIPE_LIVE_ENDPOINTSECRET=whsec_xxxxxx

# Optionally determine the URL
URL_APP="http://localhost:3000"
URL_API="http://localhost:8000"
PRODUCTION_URL_APP="https://saas-app.async-await.com"
PRODUCTION_URL_API="https://saas-api.async-await.com"
  • Your .env file file must have values for the required variables. To use all features and third-party integrations, also add the optional variables.

  • IMPORTANT: do not publish your actual values for environmentable variables in .env.example; this file is public and only meant to show you how your .env should look.

  • IMPORTANT: use your values for PRODUCTION_URL_APP and PRODUCTION_URL_API. These are values for domain name that you own.

  • IMPORTANT: The above environmental variables are available on the server only. You should add your .env file to .gitignore inside the api folder so that your secret keys are not stored on a remote Github repo.

  • To get value for MONGO_URL_TEST, we recommend you use a free MongoDB at MongoDB Atlas or $15/month MongoDB at Digital Ocean

  • Specify your own name and secret keys for Express session: SESSION_NAME and SESSION_SECRET

  • Get GOOGLE_CLIENTID and GOOGLE_CLIENTSECRET by following the official OAuth tutorial.
    Important: For Google OAuth app, callback URL is: http://localhost:8000/oauth2callback
    Important: You have to enable Google+ API in your Google Cloud Platform account.

  • Once .env is created, you can run the api app. Navigate to the api folder, run yarn install to add all packages, then run the command below:

    yarn dev
    

Running app locally:

  • Navigate to the app folder, run yarn to add all packages, then run yarn dev and navigate to http://localhost:3000:

    • A .env file in the app folder is not required to run, but you can create one to override the default variables. The environmental variables for .env in the app folder are shown below. You can also refer .env.example for creating your own .env file in the app folder.
      NEXT_PUBLIC_STRIPE_TEST_PUBLISHABLEKEY="pk_test_xxxxxxxxxxxxxxx"
      NEXT_PUBLIC_STRIPE_LIVE_PUBLISHABLEKEY="pk_live_xxxxxxxxxxxxxxx"
      
      NEXT_PUBLIC_BUCKET_FOR_POSTS=
      NEXT_PUBLIC_BUCKET_FOR_TEAM_AVATARS=
      NEXT_PUBLIC_BUCKET_FOR_TEAM_LOGOS=
      
      NEXT_PUBLIC_URL_APP="http://localhost:3000"
      NEXT_PUBLIC_URL_API="http://localhost:8000"
      NEXT_PUBLIC_PRODUCTION_URL_APP=
      NEXT_PUBLIC_PRODUCTION_URL_API=
      
      NEXT_PUBLIC_API_GATEWAY_ENDPOINT=
      NEXT_PUBLIC_GA_MEASUREMENT_ID=
    
    • IMPORTANT: do not publish your actual values for environmentable variables in .env.example; this file is public and only meant to show you how your .env should look.

    • IMPORTANT: use your values for PRODUCTION_URL_APP and PRODUCTION_URL_API. These are values for domain name that you own.

    • To get NEXT_PUBLIC_GA_MEASUREMENT_ID, set up Google Analytics and follow these instructions to find your tracking ID.

    • To get NEXT_PUBLIC_STRIPE_TEST_PUBLISHABLEKEY, go to your Stripe dashboard, click Developers, then click API keys.

  • For successful file uploading, make sure your buckets have proper CORS configuration. Go to your AWS account, find your bucket, go to Permissions > CORS configuration, add:

[
  {
    "AllowedHeaders":[
      "*"
    ],
    "AllowedMethods":[
      "PUT",
      "POST",
      "GET",
      "HEAD",
      "DELETE"
    ],
    "AllowedOrigins":[
      "http://localhost:3000",
      "https://saas-app.async-await.com"
    ],
    "ExposeHeaders":[
      "ETag",
      "x-amz-meta-custom-header"
    ]
  }
]
  • Make sure to update allowed origin with your actual values for NEXT_PUBLIC_URL_APP and NEXT_PUBLIC_PRODUCTION_URL_APP.

  • Once .env is created, you can run the app app. Navigate to the app folder, run yarn install to add all packages, then run the command below:

    yarn dev
    

Symlink api in lambda:

In lambda directory we are symlinking api directory. You can run symlink command in lambda folder as mentioned below:

bash symlink ../api

Deploy to Heroku, AWS Elastic Beanstalk, API Gateway and AWS Lambda

We give detailed instructions inside Chapter 9 and 10 of our SaaS Boilerplate book: https://builderbook.org/book

Built with

For more detail, check package.json files in both app and api folders and project's root.

To customize styles, check this guide.

Screenshots

Google or passwordless login: 1_SaaS_login

Dropdown menu for settings: 2_SaaS_DropdownMenu

Personal settings: 3_SaaS_PersonalSettings

Team settings: 4_SaaS_TeamSettings

Creating a Discussion: 5_SaaS_Discussion_Creation

Writing a Post, Markdown vs. HTML view: 6_SaaS_Discussion_Markdown

7_SaaS_Discussion_HTML

Discussion between team members: 8_SaaS_Discussion_Dark

Billing settings: 9_SaaS_Billing

Purchasing a subscription: 10_SaaS_BuySubscription

Payment history: 12_SaaS_PaymentHistory

Contributing

Want to support this project? Consider buying our books.

Team

You can contact us at [email protected].

If you are interested in working with us, check out Async Labs.

License

All code in this repository is provided under the MIT License.

Project structure

β”œβ”€β”€ .elasticbeanstalk
β”‚   └── config.yml
β”œβ”€β”€ .github
β”‚   └── FUNDING.yml
β”œβ”€β”€ .vscode
β”‚   β”œβ”€β”€ extensions.json
β”‚   β”œβ”€β”€ launch.json
β”‚   └── settings.json
β”œβ”€β”€ api
β”‚   β”œβ”€β”€ .elasticbeanstalk
β”‚   β”‚   └── config.yml
β”‚   β”œβ”€β”€ server
β”‚   β”‚   β”œβ”€β”€ api
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ public.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ team-leader.ts
β”‚   β”‚   β”‚   └── team-member.ts
β”‚   β”‚   β”œβ”€β”€ models
β”‚   β”‚   β”‚   β”œβ”€β”€ Discussion.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ EmailTemplate.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ Invitation.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ Post.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ Team.ts
β”‚   β”‚   β”‚   └── User.ts
β”‚   β”‚   β”œβ”€β”€ utils
β”‚   β”‚   β”‚   β”œβ”€β”€ slugify.ts
β”‚   β”‚   β”‚   └── sum.ts
β”‚   β”‚   β”œβ”€β”€ aws-s3.ts
β”‚   β”‚   β”œβ”€β”€ aws-ses.ts
β”‚   β”‚   β”œβ”€β”€ google-auth.ts
β”‚   β”‚   β”œβ”€β”€ logger.ts
β”‚   β”‚   β”œβ”€β”€ mailchimp.ts
β”‚   β”‚   β”œβ”€β”€ passwordless-auth.ts
β”‚   β”‚   β”œβ”€β”€ passwordless-token-mongostore.ts
β”‚   β”‚   β”œβ”€β”€ server.ts
β”‚   β”‚   β”œβ”€β”€ sockets.ts
β”‚   β”‚   └── stripe.ts
β”‚   β”œβ”€β”€ static
β”‚   β”‚   └── robots.txt
β”‚   β”œβ”€β”€ test/server/utils
β”‚   β”‚   β”œβ”€β”€ slugify.test.ts
β”‚   β”‚   └── sum.test.ts
β”‚   β”œβ”€β”€ .eslintignore
β”‚   β”œβ”€β”€ .eslintrc.js
β”‚   β”œβ”€β”€ .gitignore
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”œβ”€β”€ tsconfig.server.json
β”‚   └── yarn.lock
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ .elasticbeanstalk
β”‚   β”‚   └── config.yml
β”‚   β”œβ”€β”€ components
β”‚   β”‚   β”œβ”€β”€ common
β”‚   β”‚   β”‚   β”œβ”€β”€ Confirmer.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginButton.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MemberChooser.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MenuWithLinks.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MenuWithMenuItems.tsx
β”‚   β”‚   β”‚   └── Notifier.tsx
β”‚   β”‚   β”œβ”€β”€ discussions
β”‚   β”‚   β”‚   β”œβ”€β”€ CreateDiscussionForm.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DiscussionActionMenu.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DiscussionList.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DiscussionListItem.tsx
β”‚   β”‚   β”‚   └── EditDiscussionForm.tsx
β”‚   β”‚   β”œβ”€β”€ layout
β”‚   β”‚   β”‚   β”œβ”€β”€ index.tsx
β”‚   β”‚   β”œβ”€β”€ posts
β”‚   β”‚   β”‚   β”œβ”€β”€ PostContent.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ PostDetail.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ PostEditor.tsx
β”‚   β”‚   β”‚   └── PostForm.tsx
β”‚   β”‚   β”œβ”€β”€ teams
β”‚   β”‚   β”‚   └── InviteMember.tsx
β”‚   β”œβ”€β”€ lib
β”‚   β”‚   β”œβ”€β”€ api
β”‚   β”‚   β”‚   β”œβ”€β”€ makeQueryString.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ public.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ sendRequestAndGetResponse.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ team-leader.ts
β”‚   β”‚   β”‚   └── team-member.ts
β”‚   β”‚   β”œβ”€β”€ store
β”‚   β”‚   β”‚   β”œβ”€β”€ discussion.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ invitation.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ post.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ team.ts
β”‚   β”‚   β”‚   └── user.ts
β”‚   β”‚   β”œβ”€β”€ confirm.ts
β”‚   β”‚   β”œβ”€β”€ isMobile.ts
β”‚   β”‚   β”œβ”€β”€ notify.ts
β”‚   β”‚   β”œβ”€β”€ resizeImage.ts
β”‚   β”‚   β”œβ”€β”€ sharedStyles.ts
β”‚   β”‚   β”œβ”€β”€ theme.ts
β”‚   β”‚   └── withAuth.tsx
β”‚   β”œβ”€β”€ pages
β”‚   β”‚   β”œβ”€β”€ _app.tsx
β”‚   β”‚   β”œβ”€β”€ _document.tsx
β”‚   β”‚   β”œβ”€β”€ billing.tsx
β”‚   β”‚   β”œβ”€β”€ create-team.tsx
β”‚   β”‚   β”œβ”€β”€ discussion.tsx
β”‚   β”‚   β”œβ”€β”€ invitation.tsx
β”‚   β”‚   β”œβ”€β”€ login-cached.tsx
β”‚   β”‚   β”œβ”€β”€ login.tsx
β”‚   β”‚   β”œβ”€β”€ team-settings.tsx
β”‚   β”‚   └── your-settings.tsx
β”‚   β”œβ”€β”€ public
β”‚   β”‚   └── pepe.jpg
β”‚   β”œβ”€β”€ server
β”‚   β”‚   β”œβ”€β”€ robots.txt
β”‚   β”‚   β”œβ”€β”€ routesWithCache.ts
β”‚   β”‚   β”œβ”€β”€ server.ts
β”‚   β”‚   └── setupSitemapAndRobots.ts
β”‚   β”œβ”€β”€ .babelrc
β”‚   β”œβ”€β”€ .eslintignore
β”‚   β”œβ”€β”€ .eslintrc.js
β”‚   β”œβ”€β”€ .gitignore
β”‚   β”œβ”€β”€ next.env.d.ts
β”‚   β”œβ”€β”€ next.config.js
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”œβ”€β”€ tsconfig.server.json
β”‚   └── yarn.lock
β”œβ”€β”€ book
β”œβ”€β”€ lambda
β”‚   β”œβ”€β”€ .estlintignore
β”‚   β”œβ”€β”€ .eslintrc.js
β”‚   β”œβ”€β”€ .gitignore
β”‚   β”œβ”€β”€ api
β”‚   β”œβ”€β”€ handler.ts
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ serverless.yml
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   └── yarn.lock
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE.md
β”œβ”€β”€ README.md
β”œβ”€β”€ package.json
β”œβ”€β”€ yarn.lock