go-saas-kit

repository·main·Indexed 43 days ago

https://github.com/go-saas/kit

A starter kit for building Golang-based SaaS projects featuring a modular architecture compatible with monolithic and microservice patterns. It includes built-in support for multi-tenancy, payments, distributed systems, and embedded services like OpenID Connect (OIDC) and DTM. The kit provides specialized protoc plugins, such as protoc-gen-go-errors-i18n for localized error messages and protoc-gen-go-grpc-proxy for unifying gRPC server and client interfaces.

Tokens
30K
Snippets
119
Records
167
Agent score
55%

What's inside go-saas-kit

  1. Overview of GO-SAAS-KIT

    main

    GO-SAAS-KIT is a Go-based project designed to help developers quickly build and sell Software as a Service (SaaS) solutions. Rather than being a monolithic web framework, it acts as an inspirational template and a starting point built on top of popular frameworks and middleware. It provides essential SaaS features that developers can extend, such as:

    • User management
    • Permission control
    • Data storage
    • RESTful API design

    It is optimized for distributed/microservice scenarios and focuses on solving common SaaS challenges like data isolation and multi-tenancy.

  2. Overview of the Sys service module

    main
    The Sys module is a service module within the project designed to handle menu-related logic. It is categorized as a service module and is not currently part of the saas specific implementation (marked with :x:).
  3. What is a Virtual File System (VFS)

    main
    A Virtual File System (VFS) is an abstraction layer that provides a consistent and unified interface for accessing and managing different types of file systems. It allows applications to interact with files and directories regardless of their underlying physical storage or format. In this project, the VFS is based on the afero library.
  4. Understand the Unit of Work pattern for local transactions

    main

    The Unit of Work (UOW) pattern is used to manage database transactions and ensure data consistency without passing transaction objects through every layer of your application. It provides a unified mental model where multiple operations are grouped together: they are 'committed together' when the unit of work is submitted and 'rolled back together' if an error occurs.

    Important Limitation: This implementation manages multiple transactions within a single unit of work. While it attempts to commit or roll back them as a group, it does not provide absolute atomicity across different resources. If your application requires strict, strong consistency across distributed systems, use distributed transactions instead.

  5. Understand the authentication mechanisms in go-saas/kit

    main

    The kit supports three primary authentication patterns:

    1. Session-based Authentication: Uses a forked version of gorilla/sessions (via go-saas/sessions) to enable cookie reading and writing across both the gateway and downstream services.
    2. JWT (JSON Web Tokens): Uses golang-jwt/jwt for generating and extracting claims. The following claims are supported:
      • standard: Standard JWT claims as defined by Auth0.
      • uid: A custom claim equivalent to the standard sub (subject) claim.
      • clientId: A custom claim used to verify server-to-server communication.
    3. OpenID Connect (OIDC): Implemented via integration with ory/hydra for standardized identity verification and Single Sign-On (SSO).
  6. Define permissions using Access Control Lists (ACL)

    main

    Authorization in kit is managed via Access Control Lists (ACL) that define what a subject can do to an object within a specific namespace and tenant.

    An ACL entry follows this schema:

    subjectnamespaceobjectactiontenanteffect

    Example Entry: To grant a specific role permission to read all users in a tenant: role/<role_id> | user.user | * | read | <tenant_id> | grant

    Note: * acts as a wildcard for 'any'.

    Detailed subject definitions can be found in the pkg/authz/authz/subjects.go source file.