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
- 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
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.312.tar.gz.
File metadata
- Download URL: django_resaas-0.0.312.tar.gz
- Upload date:
- Size: 104.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afea3e8c06b76163fa79df32476d2fad858224d57c965a165a4521cda172bb0a
|
|
| MD5 |
11d1f955259a43af2c326a7146a710dc
|
|
| BLAKE2b-256 |
4cd65c344781b89506da191a158c6833d383858ae512b4cd7cbeb6b97f77bcc4
|
Provenance
The following attestation bundles were made for django_resaas-0.0.312.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.312.tar.gz -
Subject digest:
afea3e8c06b76163fa79df32476d2fad858224d57c965a165a4521cda172bb0a - Sigstore transparency entry: 1551891188
- Sigstore integration time:
-
Permalink:
metanochava/django_resaas@5e1b952122467cb053b67b9bff22511ed283d87f -
Branch / Tag:
refs/tags/0.0.312 - Owner: https://github.com/metanochava
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@5e1b952122467cb053b67b9bff22511ed283d87f -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_resaas-0.0.312-py3-none-any.whl.
File metadata
- Download URL: django_resaas-0.0.312-py3-none-any.whl
- Upload date:
- Size: 159.7 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 |
9a3e01358c72c142d53b9436512fba7557b7784bc38a15e6801cde1b37a4d139
|
|
| MD5 |
90a2fdab55761548cd4224e977c03df3
|
|
| BLAKE2b-256 |
c86be6eadaf49fe08dc8d23cab7cc3ef34036e84ef604148764e6dcdfafcc930
|
Provenance
The following attestation bundles were made for django_resaas-0.0.312-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.312-py3-none-any.whl -
Subject digest:
9a3e01358c72c142d53b9436512fba7557b7784bc38a15e6801cde1b37a4d139 - Sigstore transparency entry: 1551891207
- Sigstore integration time:
-
Permalink:
metanochava/django_resaas@5e1b952122467cb053b67b9bff22511ed283d87f -
Branch / Tag:
refs/tags/0.0.312 - Owner: https://github.com/metanochava
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@5e1b952122467cb053b67b9bff22511ed283d87f -
Trigger Event:
push
-
Statement type: