RFC 001: API Template for SaaS with User Authentication, Workspaces, and Stripe Integration
- Authors: Lucas Jahier lucas.jahier@stratorys.com
- Status: Draft
- Created: Sat Aug 24 09:09:29 CEST 2024
Summary
This RFC proposes the creation of a Rust-based API template using Axum and SQLx (PostgreSQL) for SaaS applications. The template will include features such as user authentication, workspace management (with the ability to enable/disable workspaces), and simple payment integration using Stripe. The goal is to streamline the development process for new SaaS ideas, allowing developers to focus on domain-specific logic by providing a reusable foundation for common SaaS functionalities.
Motivation
Building a SaaS application often requires implementing the same foundational features such as user authentication, workspace management, and payment processing. These features can be time-consuming and distract from developing the unique aspects of the application. By creating a robust API template that includes these common features, we can reduce development time, avoid repetitive tasks, and ensure a consistent, secure, and scalable foundation for future projects. This template will be especially useful for rapidly prototyping new ideas or spinning up new SaaS products.
Detailed Design
The API template will be built using the following components:
1. User Authentication
- Framework: Axum will be used to handle HTTP requests and responses.
- Database: SQLx with PostgreSQL will store user credentials and profile information.
- Features:
- User registration and login with hashed passwords.
- Token-based authentication for securing API endpoints.
- Email verification and password reset functionality.
- User settings management
2. Workspace Management
- Concept: Users can create and manage workspaces, which can be enabled or disabled.
- Database Schema: A
workspacestable will be linked to theuserstable with a many-to-one relationship. - Features:
- Create, update, and delete workspaces.
- Enable or disable workspaces, affecting access and functionality for users associated with the workspace.
3. Payment Integration with Stripe
- Features:
- Subscription management: Users can subscribe to a plan, with billing occurring monthly.
- Payment validation: When a user creates a new account, the system checks if the user has already paid and links the payment to the correct account.
- Payment entry creation: Automatically creates an entry in the database when a payment is processed.
- Subscription update: Automatic updating of subscription status each month.
- Billing page link: Users can access their Stripe billing page for managing their subscription.
4. API Structure
- Routes:
/auth: Handles user authentication-related actions./workspaces: Manages CRUD operations and toggling of workspaces./webhook/stripe: Handle stripe webhook call/payment: Integrates Stripe functionality, including payment processing and subscription management.
Implementation Plan
- Phase 1: Set up the project structure with Axum, SQLx, and basic user authentication.
- Phase 2: Implement workspace management with enable/disable functionality.
- Phase 3: Integrate Stripe for payment processing and subscription management.
- Phase 4: Test and document the template for easy adoption in future projects.