Skip to main content

Overview

Profiles are the central entity in Tresa Contafy that represent taxpayer identities (RFC). Each profile corresponds to a specific RFC (Registro Federal de Contribuyentes) and contains all associated invoices, expenses, and tax configurations.
Profiles enable multi-RFC management, allowing users to manage multiple tax entities from a single account.

Why Profiles Matter

In Mexican tax accounting, each RFC is a distinct tax identity that must maintain separate records. Profiles provide:
  • Isolation: Each RFC’s invoices and expenses remain separate
  • Compliance: Tax regime validation per RFC
  • Automation: SAT portal synchronization for automated CFDI downloads
  • Flexibility: Users can manage personal (FISICA) and business (MORAL) entities

Data Structure

The Profile model contains the following key fields:
interface ProfileAttributes {
  id: string;                    // UUID primary key
  user_id: string;               // Owner reference
  nombre: string;                // Legal/commercial name
  rfc: string;                   // RFC (unique)
  tipo_persona: 'FISICA' | 'MORAL';  // Entity type
  regimenes_fiscales: string[];  // SAT tax regime codes
  
  // Validation settings
  validaciones_habilitadas: Record<string, unknown>;
  
  // Profile status
  frozen: boolean;
  frozen_reason: 'plan_limit' | 'user_suspension' | 'payment_issue' | null;
  frozen_at: Date | null;
  
  // SAT credentials (encrypted)
  fiel_cer_encrypted: string | null;
  fiel_key_encrypted: string | null;
  fiel_password_encrypted: string | null;
  
  // SAT sync configuration
  sat_download_last_sync_at: Date | null;
  sat_download_sync_enabled: boolean;
  
  created_at: Date;
  updated_at: Date;
}

Field Details

  • rfc: Must be unique across all profiles in the system
  • tipo_persona:
    • FISICA: Individual taxpayer (Persona Física)
    • MORAL: Business entity (Persona Moral)
  • nombre: Legal or registered business name
regimenes_fiscales is an array of SAT regime codes such as:
  • 601: General de Ley Personas Morales
  • 612: Personas Físicas con Actividades Empresariales
  • 605: Sueldos y Salarios
These codes determine what validations apply when processing CFDIs.
Profiles can be frozen for various reasons:
  • plan_limit: User exceeded their subscription plan limits
  • user_suspension: Manual administrative suspension
  • payment_issue: Subscription payment failed
Frozen profiles cannot create new invoices or expenses.
The e.firma (FIEL) credentials enable automatic synchronization with SAT:
  • fiel_cer_encrypted: Certificate file (encrypted)
  • fiel_key_encrypted: Private key file (encrypted)
  • fiel_password_encrypted: Password for the key (encrypted)
All credentials are encrypted at rest using AES-256 encryption.
  • sat_download_sync_enabled: When true, enables automated CFDI downloads
  • sat_download_last_sync_at: Timestamp of last successful sync
The system periodically checks SAT portal for new CFDIs when sync is enabled.

Relationships

User Relationship

Profile.belongsTo(User, { foreignKey: 'user_id', as: 'user' });
User.hasMany(Profile, { foreignKey: 'user_id', as: 'profiles' });
Each profile belongs to one user, but users can have multiple profiles (subject to plan limits).

Child Entities

Profiles have one-to-many relationships with:
  • Invoices: Income CFDIs (facturas emitidas/recibidas)
  • Expenses: Accrued expenses from CFDIs or manual entries
  • Payrolls: Payroll CFDIs (nómina)
  • Payment Complements: Payment complement CFDIs
All child entities cascade on delete, so deleting a profile removes all associated data.

Plan Limits

The number of active profiles a user can create depends on their subscription plan:

FREE

1 active profile

BASIC

3 active profiles

PRO

10 active profiles

ENTERPRISE

Unlimited profiles

Usage Examples

Creating a Profile

POST /api/profiles
Content-Type: application/json
Authorization: Bearer <token>

{
  "nombre": "Juan Pérez",
  "rfc": "PEXJ850101XXX",
  "tipo_persona": "FISICA",
  "regimenes_fiscales": ["612"],
  "validaciones_habilitadas": {
    "validarRFCIngresos": true,
    "validarRegimenFiscal": true
  }
}

Enabling SAT Synchronization

POST /api/profiles/:id/sat-credentials
Content-Type: multipart/form-data
Authorization: Bearer <token>

- fiel_cer: [certificate.cer file]
- fiel_key: [privatekey.key file]
- fiel_password: "password123"
- sat_download_sync_enabled: true
FIEL credentials are required for automatic SAT downloads. Manual XML uploads do not require FIEL.

Retrieving Profiles

GET /api/profiles
Authorization: Bearer <token>
Response:
{
  "message": "Perfiles obtenidos exitosamente",
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "user_id": "660e8400-e29b-41d4-a716-446655440000",
      "nombre": "Juan Pérez",
      "rfc": "PEXJ850101XXX",
      "tipo_persona": "FISICA",
      "regimenes_fiscales": ["612"],
      "frozen": false,
      "frozen_reason": null,
      "sat_download_sync_enabled": true,
      "sat_download_last_sync_at": "2026-03-07T10:30:00.000Z",
      "created_at": "2026-01-15T09:00:00.000Z",
      "updated_at": "2026-03-07T10:30:00.000Z"
    }
  ],
  "count": 1
}

Best Practices

Validate RFC Format

Always validate RFC format before creating profiles to avoid SAT validation errors.

Set Correct Regime

Ensure regimenes_fiscales matches the actual SAT registration to enable proper validation.

Enable SAT Sync

Use SAT automatic downloads to ensure all CFDIs are captured without manual effort.

Monitor Frozen Status

Check frozen status before allowing operations on a profile to avoid user errors.

Validation Configuration

The validaciones_habilitadas field controls CFDI validation behavior:
{
  "validarRFCIngresos": true,
  "validarRFCGastos": true,
  "validarRegimenFiscal": true,
  "validarUUIDDuplicado": true,
  "bloquearSiRFCNoCoincide": false,
  "bloquearSiRegimenNoCoincide": false
}
  • validarRFCIngresos: Verify RFC matches in income invoices
  • validarRFCGastos: Verify RFC matches in expense invoices
  • validarRegimenFiscal: Check if tax regime matches SAT registry
  • validarUUIDDuplicado: Reject duplicate UUID submissions
  • bloquearSiRFCNoCoincide: Block (vs. warn) on RFC mismatch
  • bloquearSiRegimenNoCoincide: Block (vs. warn) on regime mismatch

Invoices

Income CFDIs linked to profiles

Expenses

Expense CFDIs and manual entries

Subscriptions

Plan limits and profile quotas

Build docs developers (and LLMs) love