Coder Social home page Coder Social logo

petrpavlik / vapor-saas-backend-template Goto Github PK

View Code? Open in Web Editor NEW
43.0 1.0 3.0 80 KB

A starter template for your SAAS backend using Swift and Vapor

License: MIT License

Dockerfile 5.53% Swift 94.47%
firebase-auth saas saas-api saas-boilerplate server-side-swift swift vapor vapor-swift

vapor-saas-backend-template's Introduction

SAAS Backend Starter Template

You can check out my project IndiePitcher for an example of a SAAS with a backend written in Swift, using this template.

This is an extension of Vapor's starter template to get the backend for your next SAAS off the ground. Or if you're jsut curious about server-side Swift and Vapor, and would like to see some real code.

It takes care of the tedious tasks for you, user management, sending emails, analytics, error logging...

Every SAAS needs to handle user sign up, and if your service takes off, you'll start being asked by customers how they can invite their colleagues. This ends up being a huge pain if everything is tied to a user profile instead of an organization unit. That's why this template includes a complete organization management with 3 levels of user permission. You can create a default org with a user profile during sign up that's hidden from the user, that's fine, and you are ready for to future.

  • This repo will be expanded and kept up to date with the latest Swift and Vapor releases, feel free to give it a star and/or subscribe for updates.
  • I'm working on a course explaining everything in in a very detailed way. Scroll down to learn more and join the waitlist.

Overview

  • JWT-based user authentication using Firebase
    • Firebase provides a very generous offering of 50,000 monthly active users for free
    • You can swap firebase for a different provider with little effort
  • Grouping users into organisations with user roles
    • Think GitHub or Figma organization you have for your company
  • Using PostgreSQL as database
    • Swappable for a different database supported by Vapor’s ORM framework Fluent, I’d recommend sticking with PostgreSQL though
  • Sending emails using SMTP
    • Send automated emails such as "You've been added to RockerAI organization as an admin."
    • Can be swapped for Sendgrid or another solution
  • Tracking of server events to Mixpanel
    • Tracking important events, such as new user sign up, is more reliable to track from the backend than
    • Mixpanel offers a generous free tier and is realtime.
  • Logging of errors to Sentry
    • Automatic logging of erros and warning
    • Sentry offers a generous free plan to get you started
  • All dockerized and deployable pretty much anywhere
    • AWS, DigitalOcean, ...
  • Tests for everything
    • Don’t worry about breaking the production, we have unit tests.

How to Use

  • Clone this repo to use it as a building block for your project
  • You'll need a postgre database. You can
  • When cloned, create .env file and fill in following info to be able to run the app against a local database.
    • FIREBASE_PROJECT_ID=your-firebase-project-id
      
      • This is enough to run the project locally. When deploying to production, you'll want to add the database connection keys, as well as optionally your mixpanel and sentry credentials
      • You can copy the FIREBASE_PROJECT_ID from .env.testing to try things out, but please do create your own firebase project.
  • Set up your local dev environment, you need to spin up a database. An easy way is by downloading Docker and typing in following commands
    • docker-compose build
    • docker-compose up db starts a local database to develop against
    • docker-compose up db-test starts a local database to run init tests against (this is a separate database so you don't wipe your data when running unit tests)
    • docker-compose down to shut the databases down, or just kill the docker app
  • Running the project locally and running the unit tests should now work

Deployment

You can deploy your backend anywhere that supports Docker. An obvious choice for many people would be AWS, I'm personally a fan of Digital Ocean's App Platform. You can also check out fly.io since they offer a free tier, or good old Heroku using the swift buildpack.

Want to Learn More?

I'm hard at work working on a video course providing a detailed walk through of this template and Vapor framework in general. If you're interested, or would just like to support further development, you can join the waitlist.

I'd also encourage you to join the vapor discord. Feel free to DM me there.

vapor-saas-backend-template's People

Contributors

ladiesman218 avatar petrpavlik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vapor-saas-backend-template's Issues

from where to extract the bearer jwt token

2024-01-19T23:04:30+0300 info codes.vapor.application : request-id=A228F382-41E1-4811-B117-4C9FEC68CA7D [Vapor] POST /profile
2024-01-19T23:04:30+0300 error codes.vapor.application : request-id=A228F382-41E1-4811-B117-4C9FEC68CA7D [FirebaseJWTMiddleware] Request is missing JWT bearer header.
2024-01-19T23:04:30+0300 warning codes.vapor.application : request-id=A228F382-41E1-4811-B117-4C9FEC68CA7D [FirebaseJWTMiddleware] Abort.401: Unauthorized

sslUnsupported

When trying to start the app, it errored out saying:

error codes.vapor.application : database-id=psql [AsyncKit] Opening new connection for pool failed: PSQLError(code: sslUnsupported)

This should be an tlsConfiguration error, right?

I didn't change anything other than set up a postgres db myself

User registration

I have no experience nor knowledge for firebase at this moment. But do get one question, about the registration logic:
do I have to get an firebase JWT token before I can register an account for a SaaS service?
I sense this could be a stupid question, but could really use some help here..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.