# flinedev/bartycrouch architecture

> Architecture diagram of the GitHub repository flinedev/bartycrouch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/flinedev/bartycrouch
- Repository: https://github.com/flinedev/bartycrouch

## Overview

##### Main Components
- Command-Line Interface / Entry Point: Represented by the main.swift in Sources/BartyCrouch, which parses command-line arguments and determines whether to run “update” or “lint” (or other) commands.
- Configuration Module: The configuration is loaded from a TOML file (usually generated by “bartycrouch init”) and managed by modules under Sources/BartyCrouchConfiguration (e.g. Configuration.swift, Options, and Extensions). This component defines which tasks to run and paths to scan.
- Command Modules: Under Sources/BartyCrouchKit/Commands there are several command handlers (InitCommand, LintCommand, UpdateCommand). They act as controllers that orchestrate the process.
- Task Handlers: Each update task (interfaces, code, transform, normalize, translate) has its own implementation under Sources/BartyCrouchKit/TaskHandlers. They encapsulate the logic for updating localized strings, scanning files, and applying transformations.
- File Handling Components: Modules in Sources/BartyCrouchKit/FileHandling (e.g. CodeFileHandler, StringsFileUpdater, TranslateTransformer) are responsible for scanning directories (including ignoring certain subpaths) and processing code/IB files.
- Translation and External Services: The translator modules under Sources/BartyCrouchTranslator integrate with external services (such as DeepLApi and MicrosoftTranslatorApi) to support machine translation. These components connect via their respective API clients.
- Utility and Global Modules: Provide common helpers, global options, extensions, and constants (think Sources/BartyCrouchUtility and files under Globals) that support the above operations.
- Build Integration: The Demo project and the build script serve as an example of how BartyCrouch is integrated into Xcode build phases, triggering the update and lint commands automatically.

##### Relationships and Interactions
- The main CLI parses user input, reads in configuration data, and passes control to one or more command modules.
- Each command (e.g., update) further delegates to several Task Handlers; for instance, the "update" task is broken into sub-tasks (interfaces, code, transform, normalize, and possibly translate).
- The Task Handlers use File Handling components to scan the project directories (as specified by the configuration) for resources like Swift code files, storyboard files, or .strings files.
- When machine translation is enabled, the translator components call out to external APIs (encapsulated in the MicrosoftTranslatorApi or DeepLApi modules) and then update the localizable resources.
- Utility modules support these tasks with helper functions and extension methods for better string and file manipulation.
- Tests and Demo components validate and showcase the usage of these modules.

##### Architectural Patterns/Design Principles
- Modularity: The project is clearly divided into modules (Command, Configuration, File Handling, Task Handling, Translator) to separate concerns.
- Command Pattern: Handling “update” and “lint” via separate commands.
- Dependency Inversion: Higher-level tasks depend on abstract file operations and translator services (allowing for easy extensions or replacements).
- Extension and Configurability: The configuration file (.bartycrouch.toml) drives behavior, making it flexible for different project setups.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Build Integration / Demo Project"]:::demo
    B["Command-Line Interface (main.swift)"]:::cli
    C["Configuration Module (.bartycrouch.toml)"]:::config
    D["Command Modules"]:::commands
    E["Task Handlers (Update Engine)"]:::tasks
    F["File Handling Components"]:::file
    G["Translation & External Services"]:::translator
    H["Utility & Global Modules"]:::utility

    A -->|"triggers"| B
    B -->|"loads"| C
    C -->|"routes_to"| D
    D -->|"executes"| E
    E -->|"scans_files"| F
    E -->|"invokes_translation"| G
    H -->|"supports"| E

    click B "https://github.com/flinedev/bartycrouch/blob/main/Sources/BartyCrouch/main.swift"
    click C "https://github.com/flinedev/bartycrouch/tree/main/Sources/BartyCrouchConfiguration"
    click D "https://github.com/flinedev/bartycrouch/tree/main/Sources/BartyCrouchKit/Commands"
    click E "https://github.com/flinedev/bartycrouch/tree/main/Sources/BartyCrouchKit/TaskHandlers"
    click F "https://github.com/flinedev/bartycrouch/tree/main/Sources/BartyCrouchKit/FileHandling"
    click G "https://github.com/flinedev/bartycrouch/tree/main/Sources/BartyCrouchTranslator"
    click H "https://github.com/flinedev/bartycrouch/tree/main/Sources/BartyCrouchUtility"
    click A "https://github.com/flinedev/bartycrouch/tree/main/Demo/Untouched"

    classDef cli fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef config fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef commands fill:#ccccff,stroke:#000099,stroke-width:2px;
    classDef tasks fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef file fill:#ffd9b3,stroke:#cc6600,stroke-width:2px;
    classDef translator fill:#d9b3ff,stroke:#6600cc,stroke-width:2px;
    classDef utility fill:#ccffff,stroke:#009999,stroke-width:2px;
    classDef demo fill:#e6e6e6,stroke:#666666,stroke-width:2px;
```
