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
↓
Grupos + 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
- Grupo (Django)
👉 Permite múltiplos grupos 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 → grupo
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
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_resaas-0.0.81.tar.gz.
File metadata
- Download URL: django_resaas-0.0.81.tar.gz
- Upload date:
- Size: 95.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e21d0560fa22a265ba902a86420469d4439194eac49295015d0546b4083308c3
|
|
| MD5 |
2d38ebaf94010e0feea8a63518e0a9a9
|
|
| BLAKE2b-256 |
e692a1a1ca077b26b448284ac6b77aa24ee329aa63ec67afa1d350c4c5503544
|
Provenance
The following attestation bundles were made for django_resaas-0.0.81.tar.gz:
Publisher:
publish_pypi.yml on metanochava/django_resaas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_resaas-0.0.81.tar.gz -
Subject digest:
e21d0560fa22a265ba902a86420469d4439194eac49295015d0546b4083308c3 - Sigstore transparency entry: 1254056968
- Sigstore integration time:
-
Permalink:
metanochava/django_resaas@efc79c6e8f694673a2cdba652ee93319902d23e3 -
Branch / Tag:
refs/tags/0.0.81 - Owner: https://github.com/metanochava
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@efc79c6e8f694673a2cdba652ee93319902d23e3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_resaas-0.0.81-py3-none-any.whl.
File metadata
- Download URL: django_resaas-0.0.81-py3-none-any.whl
- Upload date:
- Size: 151.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52e7e2e4cba055c078c97636d3beedfb2ccd03ca7c777e9d2a7daae8bc449b20
|
|
| MD5 |
8b5d47814615bccd82579b6f9315c919
|
|
| BLAKE2b-256 |
88b761b1e0bbb0f4488f2d6288d9e53d00012aa68c8f7d2f66662c1f02a3fbd4
|
Provenance
The following attestation bundles were made for django_resaas-0.0.81-py3-none-any.whl:
Publisher:
publish_pypi.yml on metanochava/django_resaas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_resaas-0.0.81-py3-none-any.whl -
Subject digest:
52e7e2e4cba055c078c97636d3beedfb2ccd03ca7c777e9d2a7daae8bc449b20 - Sigstore transparency entry: 1254057104
- Sigstore integration time:
-
Permalink:
metanochava/django_resaas@efc79c6e8f694673a2cdba652ee93319902d23e3 -
Branch / Tag:
refs/tags/0.0.81 - Owner: https://github.com/metanochava
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@efc79c6e8f694673a2cdba652ee93319902d23e3 -
Trigger Event:
push
-
Statement type: