Web-development – How to structure a SaaS application

apiprogramming practicessoftware-as-a-serviceweb servicesweb-development

The Problem

I need to develop a Software-as-a-Service application, that will be used from our clients. The application contains a lot of forms (Company Application) using a step-by-step forms. They users will fill these forms, and see some progress.

The Company (our client), can have a view of they dashboard, showing they users, products and other informations, including company information and some customizations.

One thing that I'm trying to solve, it's: I need a subdomain for each of my client, and each User in Company, need to have a subdomain in Company.

For example, using the first approach (above), for example, what I'll have:
API: .myapp.com/api/v1
Client Base Page (rendered by my application): .com (CNAME to somewhere)
User Base Page (rendered by my application): ..com (CNAME to somewhere)

The things I can't figure how to do are:

  1. It's better to develop a REST API, use the standards for that, and create a separate Front-end application (using Angular, Ember or other frameworks). Then I deploy the API, get the link, and setup it on my Angular application. This is a good approach?
  2. Develop a Standard Application, where the same application connects to database and render the views, where the logic will be on Models and Controllers.
  3. Other approach? (I think using microservices in this stage, will be cumbersome.

Based on that approaches, I've some questions.

In 1st case:

  1. I think the best way for the API is to use a subdomain based on my startup domain, like: .mycompany.com/api/. This way, I can buy a wildcard SSL and secure the endpoint of each client. But what I see in applications like Stripe, it's using single endpoint, like: api.stripe.com with an EV SSL. So, both approaches are good and secure?
  2. What it's a good approach to render the Front-end? Based on fact that on the front-end will be wildcard subdomains for each user.

So, what it's a good way to develop that?

Background

I'm using Rails 4, and Postgres (for multi-tenancy database), and if needed, I can develop using Angular.js or "static views".

Best Answer

For my current project I had similar requirements like you. I have decided to use a backend server exposing a REST API. And for the cleints I am using a nginx server, which handles the subdomains and hosting the AngularJS Application.

The server side checks which subdomain the client is using and sends the correct data to the client.

In my opinion the advantage of this approach is, that the communication could be easily encrypted with SSL (see Stripe).

Microsoft gives good information about SAAS architecture in following article: https://msdn.microsoft.com/en-us/library/aa479069.aspx