This project is a template for building Software as a Service (SaaS) applications using Vapor, a server-side Swift web framework. It provides a solid foundation for creating scalable and maintainable web applications with features commonly found in SaaS products.
- User authentication (sign up, sign in, password recovery)
- JWT-based authentication for protected routes
- PostgreSQL database integration
- Environment-based configuration
- Basic user profile management
- Multi-Tenant architecture with Organizations and Projects
- Role-based access control
This project is currently under active development. Here's a list of features and their current status:
- User Authentication (Sign Up, Sign In)
- JWT-based Authentication
- Password Recovery Flow
- Basic User Profile Management
- Multi-Tenant Organization Structure
- Project Creation within Organizations
- Role-Based Access Control (In Progress)
- Unit Tests (In Progress)
- Frontend with Leaf and Tailwind CSS (Planned)
- Email Integration with Resend (Planned)
- Image and File Upload (Planned)
- Billing Integration (Planned)
- API Rate Limiting (Planned)
- Webhooks (Planned)
- Audit Logs (Planned)
- Swift 5.2 or later
- Vapor 4
- PostgreSQL
-
Clone the repository:
git clone https://github.com/yourusername/saas-vapor-template.git cd saas-vapor-template
-
Install dependencies:
swift package resolve
-
Set up your environment variables by creating a
.env
file in the project root:DB_HOSTNAME=localhost DB_PORT=5432 DB_USERNAME=your_username DB_PASSWORD=your_password DB_DATABASE=your_database_name
-
Run database migrations:
swift run Run migrate
To run the project in development mode:
swift run Run serve --env development
The server will start on http://localhost:8080
.
To run the unit tests:
swift test
POST /auth/sign-up
: Create a new user accountPOST /auth/sign-in
: Authenticate and receive a JWT tokenGET /auth/profile
: Get the authenticated user's profile (protected route)POST /auth/password/recover
: Request a password recoveryPOST /auth/password/reset
: Reset password using a recovery tokenPOST /organizations
: Create a new organizationGET /organizations
: List user's organizationsPOST /organizations/:id/projects
: Create a new project within an organizationGET /organizations/:id/projects
: List projects within an organization
For detailed API documentation, please refer to the API Documentation.
.
├── Sources
│ └── App
│ ├── Controllers
│ ├── Models
│ ├── Migrations
│ ├── Middleware
│ ├── Services
│ ├── configure.swift
│ └── routes.swift
├── Tests
├── Resources
│ └── Views
├── Public
├── Package.swift
└── README.md
This template provides a starting point for your SaaS application. You can customize and extend it by:
- Adding new models and controllers
- Implementing additional features specific to your SaaS product
- Customizing the authentication flow
- Adding more complex database relationships
- Implementing custom business logic for multi-tenancy
- Creating Leaf templates for the frontend
- Styling your frontend with Tailwind CSS
For deployment instructions, please refer to the Vapor documentation on deploying to production.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Vapor - The web framework used
- Swift - The programming language
- Leaf - Templating language for Vapor
- Tailwind CSS - A utility-first CSS framework
- Resend - Email API service
If you have any questions or need help with the template, please open an issue in the GitHub repository.