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 (Entidade / Sucursal)
  • 🧩 Módulos ativáveis por cliente
  • 💰 Billing por plano (SaaS ready)
  • ♻️ Soft delete + restore
  • 🔎 Busca dinâmica automática
  • ⚡ BaseAPIView inteligente (DRF)

🧠 Arquitetura

User
 ↓
Pessoa
 ↓
Funcionario (RH)
 ↓
Entidade (tenant)
 ↓
Sucursal
 ↓
Groups + Permissões

🧩 Conceitos principais

🏢 Entidade (Tenant)

Representa o cliente (empresa)

🏬 Sucursal

Unidade da entidade

👤 Pessoa

Dados humanos (nome, email, etc.)

🔐 User

Autenticação

👥 SucursalUserGroup

Relaciona:

  • User
  • Sucursal
  • Group (Django)

👉 Permite múltiplos groups por sucursal


🔐 Sistema de Permissões (RBAC)

Baseado em:

User + Group + Permission (Django)
+ contexto (Entidade + Sucursal)

Headers obrigatórios:

ET → tipo_entidade
E  → entidade
S  → sucursal
G  → group
L  → idioma

🧱 BaseModel

Todos os models herdam:

from django_resaas import BaseModel

Inclui:

  • entidade
  • sucursal
  • 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="rh")
class FuncionarioView(BaseAPIView):
    queryset = Funcionario.objects.all()
    serializer_class = FuncionarioSerializer

🔍 Busca dinâmica

GET /api/funcionarios/?search=joao

Busca automaticamente em:

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

🧩 Sistema de Módulos

Permite ativar/desativar funcionalidades por cliente.

Modelos:

  • Modulo
  • EntidadeModulo

Exemplo:

Entidade Módulo Estado
Empresa A RH
Empresa A CRM

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

@register_view(module="rh")
class FuncionarioView(BaseAPIView):
    ...

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


💰 Billing (SaaS)

Modelos:

  • Plano
  • PlanoModulo
  • EntidadePlano

Fluxo:

Plano → módulos → EntidadePlano → ativa módulos automaticamente

🔄 Sync automático de módulos

Ao mudar plano:

sync_modulos_entidade(entidade)

📦 BaseSerializer

Proteção automática de arquivos:

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

🌐 Middleware

TenantContextMiddleware

Captura headers:

request.entidade_id
request.sucursal_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 Funcionario(BaseModel):
    pessoa = models.ForeignKey('django_resaas.Pessoa', on_delete=models.CASCADE)
    cargo = models.CharField(max_length=100)

Serializer

from django_resaas import BaseSerializer

class FuncionarioSerializer(BaseSerializer):
    class Meta:
        model = Funcionario
        fields = "__all__"

View

from django_resaas import BaseAPIView, register_view

@register_view(module="rh")
class FuncionarioView(BaseAPIView):
    queryset = Funcionario.objects.all()
    serializer_class = FuncionarioSerializer

⚙️ Instalação

pip install django_resaas

ou local:

pip install -e .

🔧 Configuração

INSTALLED_APPS

INSTALLED_APPS = [
    "django_resaas",
    "rh",
]

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.188.tar.gz (98.1 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.188-py3-none-any.whl (150.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_resaas-0.0.188.tar.gz
  • Upload date:
  • Size: 98.1 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.188.tar.gz
Algorithm Hash digest
SHA256 7a02f07258004087c248df590c22023bcb95881050db087c48800530529a44d1
MD5 4668e299ddafba90d4c38364b33a6870
BLAKE2b-256 d6edbe5f03817c570bbacd5261c6d777ae62fce4377ea4e370ec7486b8aae807

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_resaas-0.0.188.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.188-py3-none-any.whl.

File metadata

  • Download URL: django_resaas-0.0.188-py3-none-any.whl
  • Upload date:
  • Size: 150.6 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.188-py3-none-any.whl
Algorithm Hash digest
SHA256 298bce8ab3890ff4c1b98822b7763933f01eec793a3aff513513569ac0859227
MD5 42be2d5bc55ce1093c84637d5e1a0e97
BLAKE2b-256 28d01011cc98d264ad2597c7bb8e572cee7c29d218721ab854d8e8cf0f2a7a4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_resaas-0.0.188-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