9 ms·
Ask HN: How come there is no example code for B2B-SaaS apps?
I'm truly baffled! There are probably 1000s of consumer (B2C) SaaaS example and OSS apps in virtually all languages. But there is virtually ZERO examples or OSS projects that talk about B2B multi-tenant apps! The worst part is that even companies like Google Cloud don't provide an example.
What I'm looking for is: A SaaS app that allows people to create tenants (companies), and allows admin of the tenant to login and manage group of users, keep track of billing for each tenant, have super-admin who can access any tenant. But the rest of the app code is shared across the tenants.
I'm looking for code that's either in Java or JavaScript(NodeJS). Are you in the same boat as me? If not, could you please point me to something? I really appreciate that!
- hackerm0nkey 6y agoI have built many over the years in Java but nothing is public, I was thinking of abstracting away a Microservice template as a starting point for my projects. What you are mentioning is a very specific example of that, happy to have a chat and perhaps we can build that together and open source it ?
- dawie 6y agoIf you find any, please let us know. We are looking for a Laravel example.
- lbutler 6y agoHave you considered Laravel Spark? https://spark.laravel.com/ https://spark.laravel.com/
- smileysteve 6y agohttps://github.com/sadnub/laravel-tenancy-passport-demo https://github.com/sadnub/laravel-tenancy-passport-demo https://github.com/tenancy/tenancy https://github.com/tenancy/tenancy
- mikeburrelljr 6y agoCheck out Tenancy for Laravel: https://tenancyforlaravel.com/ https://tenancyforlaravel.com/
- deleted 6y ago[deleted]
- hayksaakian 6y agoI'm not sure you'll find something with such a specific requirement. The first thing that came to mind is server management tools like free alternatives to cpanel/webhostmanager https://froxlor.org/ https://froxlor.org/ You'll have better luck searching online if you look for "free / open source" + specific problem/solution rather than "b2b saas app" in this example i searched for "free alternative to cpanel"
- tasssko 6y agoTry this https://saasstartupkit.com/ https://saasstartupkit.com/ built in Golang. My company has used it for a proof of concept as it definitely is built around b2b multi-tenancy. Good starting point for us at the time.
- node-bayarea 6y agothanks!
- phiggins 6y agoWhy? It’s difficult and knowledge of how to do single and multi-tenant applications for B2B keep a ton of people employed. However it’s not that far off from consumer projects. Most established players moved fast to build custom code to match their use cases. It’s not OSS material. For B2B, “super-admin” should only be done with logged permission. Usually an email request. Here’s two projects to help point you in the right direction. https://github.com/terraform-google-modules/terraform-google-project-factory https://github.com/terraform-google-modules/terraform-google... WorkOS is attempting to simplify this. https://m.youtube.com/watch?v=IR2QZQrzoiA&t=1433s https://m.youtube.com/watch?v=IR2QZQrzoiA&t=1433s
- grinich 6y agoThanks for the shout-out! :)
- x3haloed 6y agoDoes this help? https://docs.microsoft.com/en-us/azure/sql-database/saas-dbpertenant-wingtip-app-overview https://docs.microsoft.com/en-us/azure/sql-database/saas-dbp...
- mweatherill 6y agoI was going to post this same link. Great docs from Microsoft
- node-bayarea 6y agothanks!
- hbcondo714 6y agoFor .NET, we used the web starter kit AspDotNetZero which has multi-tenancy and billing: https://www.aspnetzero.com/Features https://www.aspnetzero.com/Features It's a bit pricey but if you don't need the UI or billing then you can use their open source boilerplate code which gives you multi-tenancy: https://github.com/aspnetboilerplate/aspnetboilerplate https://github.com/aspnetboilerplate/aspnetboilerplate
- sneeuwpopsneeuw 6y agoWhat is the problem just build it your self. A simple template that has a login with a todo list can be extended to have a companies table. When you have added this, you can add a n to n relation between companies and users and poof you have a B2B saas app template.
- x3haloed 6y agoI think the request is more for guidance about how to do it right.
- JoeSloth 6y agoI’ve been trying to find some guidance too, specifically for authentication with B2B and how to be adaptable to work with different IAM/SSO platforms
- eloff 6y agoHaving built a number of these, it's not that simple. For example do you put a tenant column on every table, have a separate table per tenant, or have a separate schema or database? There are tradeoffs for each approach and lots of gotchas you wouldn't expect. Like if you use a separate table or database, migrations take forever, you can run into file descriptor limits in your database, etc.
- balfirevic 6y agoThat's true, but just looking at the code of some example application you've found online won't shed any light on what those trade-offs are.
- eloff 6y agoProbably not, but there are articles on the subject that are helpful. I've found them before.
- wolco 6y agoSeparate table per tenant? Not unless you have/expect 2 to 5 tenants otherwise you run into the issues you describe above. Having a database per tenant has always interested me. It make sense if the databases will be different (contain other tables) Adding a tenant id to the tables that require them makes sense. The best approach is to create a pivot table between users and tenants that holds user_id and tenant_id. Use the primary id of that table to represent the user at that tenant.
- excid3 6y agoI've been working on something like this for Ruby on Rails in case anyone is interested. It has multitenancy, billing separate for each tenant, automatic query filtering for the current tenant, etc. https://jumpstartrails.com https://jumpstartrails.com
- schappim 6y agoI 2nd https://jumpstartrails.com https://jumpstartrails.com . I purchased the "Unlimited Site License", and it is well worth it.
- node-bayarea 6y agoI wish there was something like this ready in Noode.js world (happy to pay)
- mattmanser 6y agohttps://github.com/async-labs/saas/blob/master/README.md https://github.com/async-labs/saas/blob/master/README.md From: https://www.indiehackers.com/post/17-saas-starter-kits-boilerplates-based-on-your-favourite-programming-language-framework-35387161e0 https://www.indiehackers.com/post/17-saas-starter-kits-boile... Probably more than that one.
- bnt 6y agoFor the unfamiliar, OP makes awesome Rails tutorial videos and is really knowledgeable on the subject.
- petargyurov 6y agoIntereting. I've been thinking about doing something like this with Python (Flask/Django), albeit a bit more general.
- czue 6y agoI work on https://www.saaspegasus.com/ https://www.saaspegasus.com/ as a similar project for Django. Let me know if you have any questions!
- swiley 6y agoDoesn't open stack do this?
- benologist 6y agoI have been working on this: https://github.com/userdashboard/dashboard https://github.com/userdashboard/dashboard Dashboard powers the basic 'web app with registrations' and then using modules it can be supplemented with organizations, Stripe Subscriptions and Stripe Connect to standardize / reuse the "SaaS boilerplate". It runs parallel to your application server so you can use whatever stack you like. Users browse your Dashboard server URL and it proxies your application server for content. The software is complete but it needs niceties like useful charts and information added to the UI and I'll be prioritizing that in the coming weeks. It's got a really nice documentation site being generated with Github Actions but it's not publishing correctly unfortunately, probably tomorrow that will be resolved.
- mikst 6y agoI think because it's much easier to do deploy templates than multitennancy.
- deleted 6y ago[deleted]
- ComputerGuru 6y agoIn my experience, a lot of projects start off with shared tenancy (using a tenant id discriminator in the database) and eventually migrate to completely separate schema for each tenant (i.e. a separate “installation” of a single-tenancy app for each tenant) to avoid security and architectural pitfalls. Once you’ve done that, you don’t have to worry about forgetting a `WHERE tenantId = foo` somewhere and leaking data. The actual code is shared (i.e. not installed separately or in separate processes) and you would simply use your dependency injection or equivalent to resolve the DB connection contingent on $user’s validated claims. “Networking” or sharing entities across tenants becomes harder this way.. but purer/cleaner. You essentially create a federation layer and communicate across instances via a hard code wall (via network requests to yourself and an API) rather than “in memory” which is less efficient and requires a lot of boiler plate, but it’s going to be what you’re going to end up doing anyway.
- smileysteve 6y ago> you don’t have to worry about forgetting a `WHERE tenantId = foo I found a few tools early on that work for this in Rails. You can guarantee all of your sql includes the tenant. - Apartment - Tenancy There's also several for the PHP ecosystem.
- gfodor 6y agoInterestingly, I've only seen the opposite, going back to the 90s. Eventually managing N schemas ends up being difficult, and you're also fighting against the database.
- awinder 6y agoYeah 100%. Multi-tenant as implemented this way with separate infrastructure works ok for very small values on N. Once you’re into N > 100s or 1000s then you’re absolutely not reducing complication.
- TekMol 6y agoWHERE tenantId = foo You only need to do that if you keep multiple tennants in one table. But who does this? Usually in a multi tennant application you have only one line which connects to the tennants DB and thats it. The rest of the code does not have to think about tennants.
- kamyarg 6y agoThis may not match your description but definitely matches the title - OSS B2B SaaS app: https://github.com/getsentry/sentry https://github.com/getsentry/sentry They also have a separate repo to help you run it: https://github.com/getsentry/onpremise https://github.com/getsentry/onpremise
- hijp 6y agoI’m using Jumpstart Pro (paid) for a rail’s app i’m working on, I know you requested node, but you may find it very useful to see how they implemented multitenancy and ruby/rails code is very readable. https://youtu.be/6wuaVWKVclo https://youtu.be/6wuaVWKVclo https://jumpstartrails.com/ https://jumpstartrails.com/
- villgax 6y agoThat's kind of their daily bread & butter.
- masonhensley 6y agoI know it's a little early and it will be in Ruby on Rails. However, I'm working on open sourcing a clone of Stripe's Home [1] as part of a series of open source B2B applications & they should check all those boxes (besides the Java/Node) I'm also happy to walk you (or others in the thread if time permits) though the source code of a closed source app I have over a video call if you need to grok the mechanics/db structure. (email in profile.) It's got: - multi-tenancy - roles with-in each tenant - sub-tenants (think engineering team vs accounting team vs hr team) - accounts can be members of multiple tenants - billing for each tenant (even sub tenants or inherit from root tenant) - Super Admin & "Staff" roles - Auditing If anyone's interested in the open source app, follow here - https://twitter.com/tools_hub https://twitter.com/tools_hub [1] - https://stripe.com/blog/stripe-home https://stripe.com/blog/stripe-home
- dchuk 6y agoI’m super interested in this, but not sure what I’m looking at at the twitter account. Is there something on github or similar to look at?
- masonhensley 6y agoYa, sorry. The twitter account is a placeholder while we work. Just spun up a repo you can follow. https://github.com/Internal-Tools-Hub/CorpHome/blob/master/README.md https://github.com/Internal-Tools-Hub/CorpHome/blob/master/R...
- hackerm0nkey 6y agoInterested to see how you guys approached that for a Java B2B service. Thanks for the offer.
- gfodor 6y agoI'm starting a SaaS that adds multitenancy to an app as a service.
- mmaha 6y agoCheck this [SaaS Deployment Guide](https://github.com/aws-quickstart/saas-identity-cognito https://github.com/aws-quickstart/saas-identity-cognito) out from AWS.
- yodon 6y agoAnd then add in a user authentication system like Auth0 or Cognito with a way to pass authentication tokens among microservices within the app. All stuff that should be boilerplate samples but in practice burns an enormous amount of time getting in place.
- james_s_tayler 6y agohttp://abp.io/ http://abp.io/ is probably the best open source one I've seen. They also offer a paid product which is fairly comprehensive. I don't quite like their frontend stuff but the backend side of things is definitely what you're looking for. There are plenty of paid products in every language which are basically B2B SaaS templates. ABP, bullettrain, Laravel etc.
- node-bayarea 6y agolooks great, I wish there was something like this in the Node.js world
- hbcondo714 6y agoAn engineer from Nodewood posted on here at the same time as this post about their SaaS starter kit, built in Node.js and includes billing but no mention of multi-tenancy: https://news.ycombinator.com/item?id=23054417 https://news.ycombinator.com/item?id=23054417
- bjacobt 6y agoYou should look into Feathers JS [0]. You've the option to write in Javascript or Typescript and its built on top of nodejs/express. Feathers JS has got builtin authentication and it is easy to add tenants. I've created a quick example and published it here [1], there maybe some rough edges, please mail me if you have any questions. As others have mentioned with multi tenancy you must have good test cases that verify you've appropriate filters in place to avoid leaking data. [0] https://feathersjs.com/ https://feathersjs.com/ [1] https://github.com/bjacobt/feathers-multi-tenant-example https://github.com/bjacobt/feathers-multi-tenant-example
- node-bayarea 6y agoThanks, will look into it
- abraae 6y agoThere's little sample code because some parts of the problem are disproportionately harder than others. For example, in saas, if you have a serious product then you'll soon find that some of your tenants want to use SSO. So you need not only the stuff you mentioned already but also admin screens for setting up e.g saml for individual tenants. Add that to your points and you don't need sample code, you need a whole product (we use keycloak, there are plenty of other options). As to billing, that's a whole gigantic separate area and again something where you don't want sample code, you want a complete product (I have heard jbilling talked of favorably). In short, the problem space is too big to be addressed with some sample code.
- harshamv22 6y agoMultitenancy with Rails - 2nd edition If you are doing Rails by any chance this is just what you need. https://leanpub.com/multi-tenancy-rails-2 https://leanpub.com/multi-tenancy-rails-2
- abhishektwr 6y agoWill you consider a SaaS option? We are finishing up a identity management platform which does exactly that (at least access management part with 3-tiers of multi-tenancy). Our dedicated option allows you to host up to 1000-5000 tenants in a completely isolated infrastructure. Happy to have a chat.
- abhishektwr 6y agoJust to add details on this topic, Multi-tenancy is quite complicated subject and there are many ways to implement it. (1) One database per tenant. Each tenant gets their own set of tables. Dedicated virtual infrastructure with strong data isolation. (2) One database but one schema per tenant using Postgres. Each tenant gets their own set of tables. Shared virtual infrastructure with strong data isolation. (3) One database one schema one set of tables but tenant data is segmented using tenant key in the tables. Shared virtual infrastructure logical data isolation. On top you can create tenant specific views. Before you choose one, you need to analyse best possible approach according to your needs factoring performance, cost, maintenance and scalability. You can also mix some of these approaches in you solution. So for instance we use all 3 on top of single codebase. Happy to respond any specific questions anyone may have.
- cultofmetatron 6y agoyou could get pretty far with laravel spark if you don't mind picking up some php. https://spark.laravel.com/ https://spark.laravel.com/
- guptaneil 6y agoOne of the largest open-source Rails apps has all of those features: Canvas LMS[1]. It uses Switchman[2] for abstracting the multi-tenancy logic. Their approach has scaled to millions of concurrent users, but admittedly not helpful if you’re looking for a guide since the code is buried in a legacy monolith. Part of the reason there isn’t a generic guide to this is that multi-tenancy is probably a premature optimization if a generic guide would be helpful. Just use nested user accounts to accomplish your business logic. By the time you really need true multi-tenancy, generic sample code won’t be much more helpful than the docs of the various plugins like Switchman. 1: https://github.com/instructure/canvas-lms https://github.com/instructure/canvas-lms 2: https://github.com/instructure/switchman https://github.com/instructure/switchman
- node-bayarea 6y agoNice. It's amazing so many Rails multi-tenant projects but almost nothing in the Node.js world
- yodon 6y agoThat said, Canvas is also AGPL 3 which might be a concern for some people looking for code to base their new SaaS startup on.
- langbot 6y agohttps://github.com/async-labs/saas https://github.com/async-labs/saas "Build your own SaaS business with SaaS boilerplate. Productive stack: React, Material-UI, Next, MobX, WebSockets, Express, Node, Mongoose, MongoDB. Written with TypeScript"
- mbzi 6y agoI like this, I see what they're doing and it looks promising. However It lacks a data request/GDPR takedown section which for me makes the project commercially useless. Most teams/products always look at compliance as the last big rock to implement and it becomes a massive headache. If this project is focused to B2B learning it should have been tackled first (and not missing from the demo).
- yread 6y agoIs it really such a big problem in b2b? Can't you be only the Processor sign a DPA with your customers and let them handle the biggest part of the headache?
- mbzi 6y agoyes. I am a data processor not a controller. If you store data tied to the user you still need a mechanism to retrieve / delete it. This is something I encountered. Even if it is in reality not an issue and by itself the data is meaningless. Perhaps I need better legal advice :)
- hackerm0nkey 6y agoIt's a template, GDPR is EU-specific and not everyone in the world has to worry about that, it's just too specific a subject to consider in a generic template. If an EU-based (or storing EU data) team need to jump start from this, one can implement that section on top and not have to wait until the end as you say. The aim of the template is to give you a head start in the right direction.
- mbzi 6y ago
- mister_hn 6y agoIsn't Gitlab a B2B SaaS app?
- stedaniels 6y agoThey're are literally dozens of these startup frameworks for most of the web languages out there.
- charrondev 6y agohttps://github.com/vanilla/vanilla https://github.com/vanilla/vanilla can be run in a “multi-tenant” setup. It is always done with separate databases and configs though. Localhost setups are always multi-tenant, even if our infrastructure is more strongly isolated. In the end, if you can load different configurations for your app at runtime, and that configuration includes info about how to connect to your DB, cache, etc, then it’s pretty easy to do. https://github.com/vanilla/vanilla-docker/blob/master/docs/vanilla-localhost-dirs.md https://github.com/vanilla/vanilla-docker/blob/master/docs/v... this is an example of how we do the localhost setups, although I’d using separate DB credentials for any production site.
- mariushn 6y agohttps://nodex.wensia.com/ https://nodex.wensia.com/ (it's not OSS, but $99)
- ersaurav 6y agoBagisto does have Multi-Tenant SaaS eCommerce solution. Furthermore, it has got B2C, PWA, POS and Subscription add-on for the same. https://bit.ly/3by9VFH https://bit.ly/3by9VFH