
- Implemented comprehensive multi-tenant data isolation using database-level security - Built JWT authentication system with role-based access control (Super Admin, Org Admin, User, Viewer) - Created RESTful API endpoints for user and organization operations - Added complete audit logging for all data modifications with IP tracking - Implemented API rate limiting and input validation with security middleware - Built webhook processing engine with async event handling and retry logic - Created external API call handlers with circuit breaker pattern and error handling - Implemented data synchronization between external services and internal data - Added integration health monitoring and status tracking - Created three mock external services (User Management, Payment, Communication) - Implemented idempotency for webhook processing to handle duplicates gracefully - Added comprehensive security headers and XSS/CSRF protection - Set up Alembic database migrations with proper SQLite configuration - Included extensive documentation and API examples Architecture features: - Multi-tenant isolation at database level - Circuit breaker pattern for external API resilience - Async background task processing - Complete audit trail with user context - Role-based permission system - Webhook signature verification - Request validation and sanitization - Health monitoring endpoints Co-Authored-By: Claude <noreply@anthropic.com>
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, Enum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from app.db.base import Base
|
|
import enum
|
|
|
|
|
|
class AuditAction(str, enum.Enum):
|
|
CREATE = "create"
|
|
UPDATE = "update"
|
|
DELETE = "delete"
|
|
LOGIN = "login"
|
|
LOGOUT = "logout"
|
|
VIEW = "view"
|
|
|
|
|
|
class AuditLog(Base):
|
|
__tablename__ = "audit_logs"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
organization_id = Column(Integer, ForeignKey("organizations.id"), nullable=False)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
|
|
action = Column(Enum(AuditAction), nullable=False)
|
|
resource_type = Column(String(100), nullable=False)
|
|
resource_id = Column(String(100))
|
|
details = Column(Text)
|
|
ip_address = Column(String(45))
|
|
user_agent = Column(Text)
|
|
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
organization = relationship("Organization", back_populates="audit_logs")
|
|
user = relationship("User", back_populates="audit_logs_created") |