High-Level Architecture
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The flext-target-ldif project is a specialized Singer Target designed to export data records into the LDAP Data Interchange Format (LDIF). It serves as an integration component within the FLEXT ecosystem, leveraging standardized infrastructure from flext-core, flext-ldif, and flext-meltano to provide a typed, robust, and enterprise-ready data loading solution for LDAP-compatible systems. Sources: README.md:1-12, src/flext_target_ldif/writer.py:1-10
The architecture follows the Singer SDK pattern, where a central FlextTargetLdif class manages stream-specific Sink objects. These sinks utilize a FlextTargetLdifWriter to handle the low-level formatting, line wrapping, and Base64 encoding required by the LDIF specification (RFC 2849). Sources: src/flext_target_ldif/target.py:22-45, src/flext_target_ldif/models.py:214-230
Core Components
The system is organized into several key architectural layers:
1. Target Controller (target.py)
The FlextTargetLdif class acts as the entry point and orchestrator. It handles configuration validation against a Pydantic-based schema and manages the lifecycle of Sinks. Sources: src/flext_target_ldif/target.py:22-42
2. Sink Management (models.py)
Nested within the FlextTargetLdifModels.TargetLdif namespace, the Sink class manages the processing of Singer batches and records for a specific stream. It is responsible for initializing the writer with appropriate file paths and templates. Sources: src/flext_target_ldif/models.py:214-235
3. LDIF Writer (writer.py)
The FlextTargetLdifWriter is the engine that transforms JSON records into LDIF entries. It manages file handles, applies Distinguished Name (DN) templates, performs attribute mapping, and ensures compliant line wrapping. Sources: src/flext_target_ldif/writer.py:32-62
Component Relationship
The following diagram illustrates the relationship between the main architectural components:
Data Flow and Transformation
The data flow follows a synchronous path from the Singer record stream to the final LDIF file:
- Record Reception: The
Sinkreceives a record viaprocess_record. Sources: src/flext_target_ldif/models.py:255-265 - Transformation:
FlextTargetLdifUtilitiesprovides static methods to normalize attributes, format phone numbers, and ensure LDAP-compatible booleans. Sources: src/flext_target_ldif/utilities.py:164-210 - DN Generation: The
Writeruses adn_template(e.g.,uid={uid},ou=users,dc=example,dc=com) to generate the entry's Distinguished Name. Sources: src/flext_target_ldif/writer.py:133-140 - LDIF Encoding: Values containing non-ASCII characters or starting with specific reserved characters (like
:or<) are automatically Base64 encoded. Sources: src/flext_target_ldif/writer.py:142-151 - Output: Entries are buffered and written to the target file with version headers and optional timestamps. Sources: src/flext_target_ldif/writer.py:166-180
Record Processing Sequence
Configuration Schema
The target is configured using a set of parameters defined in FlextTargetLdifSettings.
| Parameter | Type | Default | Description |
|---|---|---|---|
output_path | string | ./output | Directory where LDIF files are stored. |
dn_template | string | uid={uid},ou=users,dc=example,dc=com | Template for generating LDAP DNs. |
file_naming_pattern | string | {stream_name}_{timestamp}.ldif | Pattern for output filenames. |
line_length | integer | 78 | Max characters per line before folding. |
base64_encode | boolean | False | Force Base64 encoding for all attributes. |
attribute_mapping | object | {} | Map Singer fields to LDAP attributes. |
Sources: src/flext_target_ldif/target.py:32-40, src/flext_target_ldif/models.py:53-85
Technical Implementations
Line Wrapping (Folding)
LDIF requires lines longer than a specific length (default 78) to be folded. The Writer implements this by continuing the content on a new line starting with a single space.
Sources: src/flext_target_ldif/writer.py:218-230
Attribute Normalization
The RecordTransformer class in utilities.py provides specialized logic for LDAP compatibility:
- Booleans: Converts Python
True/Falseto LDAPTRUE/FALSE. - Timestamps: Normalizes ISO formats for LDAP timestamp attributes.
- Names: Capitalizes name fields (e.g.,
givenname,sn).
Sources: src/flext_target_ldif/utilities.py:171-205
Conclusion
The High-Level Architecture of flext-target-ldif emphasizes specification compliance and modularity. By separating the Singer protocol handling (Sink) from the LDIF-specific formatting logic (Writer), the system ensures that complex LDAP requirements—such as DN templating, line folding, and Base64 encoding—are handled transparently while maintaining high performance and strict type safety through the FLEXT core framework. Sources: src/flext_target_ldif/models.py:21-45, src/flext_target_ldif/writer.py:12-30