DEV Community

Cover image for Building a Document Pipeline for Cross-Border Company Registration (PT ES Case Study)
Diogo Heleno
Diogo Heleno

Posted on Originally published at m21global.com

Building a Document Pipeline for Cross-Border Company Registration (PT ES Case Study)

Legal and compliance teams rarely think of company registration as a data pipeline problem, but that's exactly what it is. A fixed set of input documents, a set of transformation steps (translation, certification, apostille), a validation step (acceptance by a registry), and a deadline. If you've ever built an ETL job, this will feel familiar.

This post walks through how to model that pipeline for a concrete, recurring case: a Portuguese company opening a branch in Spain, which needs documents translated and legally certified before the Spanish Registro Mercantil will accept them. The legal background for this specific scenario is covered in detail in this M21Global article. Here, I want to focus on the implementation side: how to track state, avoid the most common failure mode, and automate what can actually be automated.

Why this is a pipeline, not a checklist

The naive approach is a checklist: translate the deed, translate the tax ID, translate the power of attorney, done. That fails in practice because each document has dependencies and an intermediate state that matters:

  • A document needs to be authenticated before it can be apostilled.
  • It needs to be apostilled before (in most cases) it gets translated.
  • The translation needs certification in a form the destination authority recognizes.
  • Some authorities additionally require the apostille to also cover the translation.

Miss a step, and you don't get a partial result. You get a hard rejection weeks later, after the registry reviews the filing. That's the equivalent of a pipeline failing at the very last stage after consuming all your runtime budget. You want to fail fast, locally, with validation at each stage.

Modeling the document state machine

Each document in this process moves through a small number of states. Something like this captures it:

DRAFTED -> AUTHENTICATED -> APOSTILLED -> TRANSLATED -> CERTIFIED -> SUBMITTED -> ACCEPTED/REJECTED
Enter fullscreen mode Exit fullscreen mode

A minimal tracking schema, even in a spreadsheet or a lightweight Airtable/Notion base, saves you from the most common mistake teams make here: translating a document before it's apostilled, then discovering the destination registry wants the apostille to cover the translation too, and starting over.

from enum import Enum
from dataclasses import dataclass, field
from datetime import date

class DocState(Enum):
    DRAFTED = "drafted"
    AUTHENTICATED = "authenticated"
    APOSTILLED = "apostilled"
    TRANSLATED = "translated"
    CERTIFIED = "certified"
    SUBMITTED = "submitted"
    ACCEPTED = "accepted"
    REJECTED = "rejected"

@dataclass
class LegalDocument:
    name: str
    source_lang: str
    target_lang: str
    state: DocState = DocState.DRAFTED
    apostille_on_translation_required: bool = False
    history: list = field(default_factory=list)

    def transition(self, new_state: DocState, note: str = ""):
        self.history.append((date.today().isoformat(), self.state.value, new_state.value, note))
        self.state = new_state
Enter fullscreen mode Exit fullscreen mode

This isn't production software, it's a way to force explicit answers to questions like "has this specific document's apostille been confirmed, or are we assuming it based on another document in the batch?" Assumption-based tracking is where these filings quietly break.

The one API gap you can't engineer around

There's no API for an apostille. The Portuguese apostille, for example, is issued exclusively by the Procuradoria-Geral da República, as a physical or digitally signed annex to the original document. You can't automate the issuance step. What you can automate is:

  • Tracking which documents require it (anything going to a foreign public registry generally does, under the Hague Apostille Convention, which both Portugal and Spain are party to).
  • Flagging documents where the apostille needs to cover the translation itself, not just the source document, since this varies by destination registry and is the detail most often missed.
  • Generating a submission checklist per document, cross-referenced against the specific Registro Mercantil's published requirements, since requirements vary by Spanish province.

A simple rules table does most of the work:

REQUIREMENTS = {
    "deed_of_incorporation": {"apostille_original": True, "apostille_translation": "varies_by_registry"},
    "commercial_registry_certificate": {"apostille_original": True, "apostille_translation": "varies_by_registry"},
    "power_of_attorney": {"apostille_original": True, "apostille_translation": "varies_by_registry"},
    "corporate_resolution_minutes": {"apostille_original": True, "apostille_translation": "varies_by_registry"},
}
Enter fullscreen mode Exit fullscreen mode

That "varies_by_registry" value isn't a cop-out, it's accurate, and encoding it explicitly instead of hardcoding a guess is what prevents rejected filings. Confirm it with the destination Registro Mercantil before translation starts, not after.

Terminology consistency across documents

This case involves Portuguese and Spanish, two languages close enough that it's tempting to assume a 1:1 glossary. It isn't. Terms like sucursal, apoderado, escritura pública or poder notarial have direct-looking Spanish equivalents, but the legal scope behind each term is defined by Spanish corporate law, not by the Portuguese source concept. A mistranslated scope of powers in a power of attorney has real consequences once someone signs on the company's behalf.

If you're coordinating translation across multiple documents and possibly multiple translators, a shared termbase matters more here than in most translation workflows. If you're using CAT tools (memoQ, Trados) or even a lightweight shared glossary in a spreadsheet, lock these terms before translation starts, not after:

glossary:
  sucursal: "branch"
  apoderado: "attorney-in-fact / authorized representative"
  escritura_publica: "public deed"
  poder_notarial: "notarial power of attorney"
Enter fullscreen mode Exit fullscreen mode

Inconsistent terminology across documents that reference each other (e.g., the power of attorney and the board minutes both referring to the same representative) is a red flag for a registry reviewer, even if each document is individually correct.

Building a reusable template for repeat filings

If your company expands into multiple markets, or handles this for multiple clients, this pipeline is worth templating once:

  1. Document inventory per jurisdiction pair (source country → destination country).
  2. State machine per document, as above.
  3. Apostille requirement matrix, confirmed against the specific destination authority, not assumed from a previous filing.
  4. Shared glossary per language pair, versioned alongside the documents.
  5. A submission checklist generated from steps 1-4, reviewed by someone who actually knows the receiving registry's practice, since published requirements and actual practice sometimes diverge.

None of this replaces legal or certified translation expertise. It does mean that by the time a document reaches a certified translator or a notary, you already know exactly what state it's in and what's still missing, instead of finding out from a rejection letter.

For the legal detail on certified vs. sworn translation requirements, the apostille sequence, and which documents the Spanish Registro Mercantil specifically requires, see the source article on M21Global.

Top comments (0)