# BACKEND_INVENTORY.yml - Platform Marketing Content
# Inventario de backend NestJS
# Version: 1.0.0
# Fecha: 2025-12-08
# Estado: Planificacion (sin implementar)

version: "1.0.0"
proyecto: "Platform Marketing Content"
fecha_actualizacion: "2025-12-08"
estado: planificado

# =============================================================================
# RESUMEN
# =============================================================================

resumen:
  framework: NestJS v10+
  lenguaje: TypeScript
  orm: TypeORM
  modulos_planificados: 8
  entidades_planificadas: 28
  endpoints_estimados: ~143
  dtos_estimados: ~90

# =============================================================================
# MODULOS
# =============================================================================

modulos:
  auth:
    nombre: AuthModule
    proposito: Autenticacion y sesiones
    dependencias_catalogo:
      - "@CATALOG_AUTH"
      - "@CATALOG_SESSION"
    entities:
      - User
      - Role
      - UserSession
      - Invitation
      - AuditLog
    services:
      - AuthService
      - SessionService
      - PasswordService
      - InvitationService
    controllers:
      - AuthController
      - UsersController
      - InvitationsController
    guards:
      - JwtAuthGuard
      - RolesGuard
      - TenantMemberGuard
    endpoints_estimados: 20
    estado: planificado

  tenants:
    nombre: TenantsModule
    proposito: Multi-tenancy y planes
    dependencias_catalogo:
      - "@CATALOG_TENANT"
    entities:
      - Tenant
      - Plan
      - TenantUsage
    services:
      - TenantService
      - PlanService
      - QuotaService
    controllers:
      - TenantsController
      - PlansController
    middleware:
      - TenantContextMiddleware
    decorators:
      - CurrentTenant
    endpoints_estimados: 8
    estado: planificado

  crm:
    nombre: CrmModule
    proposito: Clientes, marcas, productos
    entities:
      - Client
      - Contact
      - Brand
      - Product
      - Opportunity
    services:
      - ClientService
      - ContactService
      - BrandService
      - ProductService
      - OpportunityService
    controllers:
      - ClientsController
      - ContactsController
      - BrandsController
      - ProductsController
      - OpportunitiesController
    endpoints_estimados: 25
    estado: planificado

  projects:
    nombre: ProjectsModule
    proposito: Proyectos y campanas
    entities:
      - Project
      - Campaign
      - Brief
      - CampaignAsset
      - Approval
    services:
      - ProjectService
      - CampaignService
      - BriefService
      - ApprovalService
    controllers:
      - ProjectsController
      - CampaignsController
      - BriefsController
      - ApprovalsController
    endpoints_estimados: 20
    estado: planificado

  generation:
    nombre: GenerationModule
    proposito: Motor de generacion IA
    dependencias_catalogo:
      - "@CATALOG_RATELIMIT"
      - "@CATALOG_WS"
    entities:
      - GenerationJob
      - WorkflowTemplate
      - CustomModel
      - TextGeneration
    services:
      - GenerationService
      - ComfyUIService
      - WorkflowService
      - ModelService
      - TextGenerationService
    controllers:
      - GenerationController
      - WorkflowsController
      - ModelsController
    gateways:
      - GenerationGateway (WebSocket)
    processors:
      - ImageGenerationProcessor (Bull)
      - TextGenerationProcessor (Bull)
    queues:
      - generation:image
      - generation:text
      - generation:training
    endpoints_estimados: 18
    estado: planificado

  assets:
    nombre: AssetsModule
    proposito: DAM (Digital Asset Management)
    entities:
      - Asset
      - AssetVersion
      - Collection
      - CollectionAsset
      - AssetComment
      - Download
    services:
      - AssetService
      - CollectionService
      - StorageService
      - ThumbnailService
    controllers:
      - AssetsController
      - CollectionsController
      - DownloadsController
    endpoints_estimados: 25
    estado: planificado

  automation:
    nombre: AutomationModule
    proposito: Flujos y webhooks
    dependencias_catalogo:
      - "@CATALOG_NOTIFY"
    entities:
      - AutomationFlow
      - AutomationRun
      - WebhookEndpoint
      - EventLog
    services:
      - AutomationService
      - WebhookService
      - EventService
      - N8nIntegrationService
    controllers:
      - AutomationController
      - WebhooksController
    endpoints_estimados: 15
    estado: planificado

  analytics:
    nombre: AnalyticsModule
    proposito: Dashboards y reportes
    entities:
      - Metric
      - Report
      - SavedView
    services:
      - AnalyticsService
      - MetricsService
      - ReportService
    controllers:
      - AnalyticsController
      - ReportsController
    endpoints_estimados: 12
    estado: planificado

# =============================================================================
# SHARED/COMMON
# =============================================================================

shared:
  decorators:
    - CurrentUser
    - CurrentTenant
    - Roles
    - Public
  guards:
    - JwtAuthGuard
    - RolesGuard
    - TenantMemberGuard
    - ThrottlerGuard
  interceptors:
    - TransformInterceptor
    - LoggingInterceptor
    - TimeoutInterceptor
  filters:
    - HttpExceptionFilter
    - ValidationExceptionFilter
  pipes:
    - ValidationPipe
    - ParseUUIDPipe
  middleware:
    - TenantContextMiddleware
    - LoggerMiddleware

# =============================================================================
# INTEGRACIONES EXTERNAS
# =============================================================================

integraciones:
  comfyui:
    tipo: HTTP API
    proposito: Generacion de imagenes
    servicio: ComfyUIService
    config_requerida:
      - COMFYUI_URL
      - COMFYUI_API_KEY

  openai:
    tipo: HTTP API
    proposito: Generacion de texto
    servicio: TextGenerationService
    config_requerida:
      - OPENAI_API_KEY

  n8n:
    tipo: Webhook
    proposito: Automatizacion de flujos
    servicio: N8nIntegrationService
    config_requerida:
      - N8N_WEBHOOK_URL
      - N8N_API_KEY

  stripe:
    tipo: HTTP API + Webhooks
    proposito: Pagos y suscripciones (Fase 4)
    servicio: StripeService
    config_requerida:
      - STRIPE_SECRET_KEY
      - STRIPE_WEBHOOK_SECRET

  s3_minio:
    tipo: S3 API
    proposito: Storage de assets
    servicio: StorageService
    config_requerida:
      - S3_ENDPOINT
      - S3_ACCESS_KEY
      - S3_SECRET_KEY
      - S3_BUCKET

# =============================================================================
# COLAS (BullMQ)
# =============================================================================

queues:
  "generation:image":
    processor: ImageGenerationProcessor
    concurrency: 2
    prioridad: true

  "generation:text":
    processor: TextGenerationProcessor
    concurrency: 10

  "generation:training":
    processor: TrainingProcessor
    concurrency: 1
    limiter:
      max: 5
      duration: 86400000

  "assets:processing":
    processor: AssetProcessor
    concurrency: 5

  "notifications:email":
    processor: EmailProcessor
    concurrency: 5

# =============================================================================
# ESTRUCTURA DE CARPETAS (Planificada)
# =============================================================================

estructura:
  path: apps/backend/src
  carpetas:
    - common/
    - config/
    - modules/
    - shared/
    - main.ts
    - app.module.ts

  modulo_template: |
    modules/{nombre}/
    ├── {nombre}.module.ts
    ├── controllers/
    │   └── {nombre}.controller.ts
    ├── services/
    │   └── {nombre}.service.ts
    ├── entities/
    │   └── {entidad}.entity.ts
    ├── dto/
    │   ├── create-{entidad}.dto.ts
    │   └── update-{entidad}.dto.ts
    └── __tests__/
        └── {nombre}.service.spec.ts

# =============================================================================
# REFERENCIAS
# =============================================================================

referencias:
  definicion_modulos: docs/02-definicion-modulos/
  requerimientos: docs/03-requerimientos/
  guia_setup: docs/95-guias-desarrollo/GUIA-SETUP.md
  guia_convenciones: docs/95-guias-desarrollo/GUIA-CONVENCIONES.md
  adr_stack: docs/97-adr/ADR-001-stack-tecnologico.md
  adr_cola: docs/97-adr/ADR-004-cola-tareas.md

# =============================================================================
# METADATOS
# =============================================================================

metadata:
  creado_por: Requirements-Analyst
  fecha_creacion: "2025-12-08"
  ultima_actualizacion: "2025-12-08"
  estado_implementacion: pendiente
