Skip to main content

Django SAAS Framework

Project description

🚀 django_resaas

django_resaas é um framework modular para construção de aplicações SaaS multi-tenant em Django, com:

  • 🔐 Controle de permissões (RBAC)
  • 🏢 Multi-tenant (Entity / Branch)
  • 🧩 Módulos ativáveis por cliente
  • 💰 Billing por plano (SaaS ready)
  • ♻️ Soft delete + restore
  • 🔎 Busca dinâmica automática
  • ⚡ BaseAPIView inteligente (DRF)

🧠 Arquitetura

User
 ↓
Person
 ↓
Employee (RH)
 ↓
Entity (tenant)
 ↓
Branch
 ↓
Groups + Permissões

🧩 Conceitos principais

🏢 Entity (Tenant)

Representa o cliente (empresa)

🏬 Branch

Unidade da entity

👤 Person

Dados humanos (name, email, etc.)

🔐 User

Autenticação

👥 BranchUserGroup

Relaciona:

  • User
  • Branch
  • Group (Django)

👉 Permite múltiplos groups por branch


🔐 Sistema de Permissões (RBAC)

Baseado em:

User + Group + Permission (Django)
+ contexto (Entity + Branch)

Headers obrigatórios:

ET → entity_type
E  → entity
S  → branch
G  → group
L  → language

🧱 BaseModel

Todos os models herdam:

from django_resaas import BaseModel

Inclui:

  • entity
  • branch
  • created_at / updated_at
  • soft delete
  • created_by / updated_by

🔁 Soft Delete

obj.delete()        # soft delete
obj.restore()       # restore
obj.hard_delete()   # delete real

Managers disponíveis:

Model.objects          # ativos
Model.deleted_objects  # apagados
Model.all_objects      # todos

⚡ BaseAPIView

CRUD automático com:

  • multi-tenant automático
  • permissões automáticas
  • search dinâmica
  • soft delete
  • restore
  • hard delete

Uso:

from django_resaas import BaseAPIView, register_view

@register_view(module="hr")
class EmployeeView(BaseAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmployeeSerializer

🔍 Busca dinâmica

GET /api/employees/?search=joao

Busca automaticamente em:

  • name
  • email
  • código
  • relações (FK)

🧩 Sistema de Módulos

Permite ativar/desativar funcionalidades por cliente.

Models:

  • App
  • EntityApp

Exemplo:

Entity Módulo Estado
Empresa A RH
Empresa A CRM

🔐 Proteção automática por módulo

@register_view(module="hr")
class EmployeeView(BaseAPIView):
    ...

👉 Se módulo não estiver ativo → acesso bloqueado


💰 Billing (SaaS)

Models:

  • Plano
  • PlanoApp
  • EntityPlano

Fluxo:

Plano → módulos → EntityPlano → ativa módulos automaticamente

🔄 Sync automático de módulos

Ao mudar plano:

sync_apps_entity(entity)

📦 BaseSerializer

Proteção automática de arquivos:

{
  "file": {
    "url": "...",
    "name": "...",
    "ext": "pdf",
    "size": 12345
  }
}

🌐 Middleware

TenantContextMiddleware

Captura headers:

request.entity_id
request.branch_id
request.group_id

FrontEndMiddleware

Protege acesso por:

  • chave frontend (FEK/FEP)
  • permissões por URL
  • permissões por método HTTP

🧪 Exemplo completo

Model

from django_resaas import BaseModel

class Employee(BaseModel):
    person = models.ForeignKey('django_resaas.Person', on_delete=models.CASCADE)
    cargo = models.CharField(max_length=100)

Serializer

from django_resaas import BaseSerializer

class EmployeeSerializer(BaseSerializer):
    class Meta:
        model = Employee
        fields = "__all__"

View

from django_resaas import BaseAPIView, register_view

@register_view(module="hr")
class EmployeeView(BaseAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmployeeSerializer

⚙️ Instalação

pip install django_resaas

ou local:

pip install -e .

🔧 Configuração

INSTALLED_APPS

INSTALLED_APPS = [
    "django_resaas",
    "hr",
]

Middleware

MIDDLEWARE = [
    "django_resaas.core.middleware.tenant.TenantContextMiddleware",
    "django_resaas.core.middleware.frontend.FrontEndMiddleware",
]

🚀 Roadmap

  • Integração com Stripe
  • Dashboard de billing
  • Auto-router
  • Auditoria de ações
  • Logs multi-tenant
  • Cache de permissões (Redis)

🧠 Filosofia

"Construir SaaS não deve ser repetitivo."

django_resaas resolve:

  • multi-tenant
  • permissões
  • módulos
  • billing

👉 para você focar no negócio


🤝 Contribuição

PRs são bem-vindos 🚀


📄 Licença

MIT License


👨‍💻 Autor

Metano Chavana

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_resaas-0.0.247.tar.gz (102.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_resaas-0.0.247-py3-none-any.whl (157.5 kB view details)

Uploaded Python 3

File details

Details for the file django_resaas-0.0.247.tar.gz.

File metadata

  • Download URL: django_resaas-0.0.247.tar.gz
  • Upload date:
  • Size: 102.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_resaas-0.0.247.tar.gz
Algorithm Hash digest
SHA256 43623444a728bcbff29db281081b19d934ac312b5fe915f036ae41eaca87d796
MD5 0361c03647ed750a2d1b89e3efe9dc88
BLAKE2b-256 567f819b5c10795ddc4710f5ea5b0ae4f4b837204c10bc68162c556b5e1827c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_resaas-0.0.247.tar.gz:

Publisher: publish_pypi.yml on metanochava/django_resaas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_resaas-0.0.247-py3-none-any.whl.

File metadata

  • Download URL: django_resaas-0.0.247-py3-none-any.whl
  • Upload date:
  • Size: 157.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_resaas-0.0.247-py3-none-any.whl
Algorithm Hash digest
SHA256 c51eb4b002c4e26b820abdd82faf17b4694b4a4d42ea79d96a6c624311465b98
MD5 ac0675fbae3de1cdbcb70f562b286654
BLAKE2b-256 350ea6d21f206fd4105d123919d1935bfaa46045f58b3169b11d2fe65471ba49

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_resaas-0.0.247-py3-none-any.whl:

Publisher: publish_pypi.yml on metanochava/django_resaas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page