# flakysl/translatable architecture

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

- Interactive diagram: https://gitdiagram.com/flakysl/translatable
- Repository: https://github.com/flakysl/translatable

## Overview

##### Project Type and Purpose
- This is an open-source Rust library (“translatable”) for internationalization (i18n), providing both compile-time and run-time translation lookup, ISO-639-1 language support, TOML-based translation files, and a compile-time procedural macro for validation and code generation.

##### File Structure Analysis
- Top-level crates/directories:
- translatable/            — the main library, exposes `translation!` macro, `Language`, and runtime API
- translatable_proc/       — the procedural-macro crate that parses translation files at compile time and generates Rust code
- translatable_shared/     — a shared library of data types, templating logic, common utilities used by both the macro and runtime crates
- translatable/tests/…     — integration and unit tests for the main crate
- translatable.toml        — user-provided configuration for file path, seek_mode, overlap
- translations/            — user translation files (TOML)

- CI/deployment files (`.github/workflows`, `Makefile`), cargo manifests (`Cargo.toml`, `Cargo.lock`), formatting, linting configs.

##### Insights from README
- The library provides macros for static and dynamic translations.
- It reads `.toml` translation files via a walk-dir algorithm.
- It performs compile-time checks for static parameters (language code validity, path existence) via the procedural macro.
- At run-time or dynamic paths, it returns `Result<String, Error>` with lazy error retrieval.
- It emphasizes ergonomics and extensibility (custom file structures, template replacements).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer Application
    App["Consumer Application"]:::external

    %% Compile-time Layer
    subgraph "Compile-Time (Build)" 
        direction TB
        TransProc["translatable_proc"]:::compileTime
    end

    %% Shared Logic
    subgraph "Shared Library"
        direction TB
        TransShared["translatable_shared"]:::shared
    end

    %% Runtime Library
    subgraph "Run-Time Library"
        direction TB
        TransRuntime["translatable"]:::runtime
    end

    %% File System
    subgraph "File System" 
        direction TB
        Config["translatable.toml"]:::filesystem
        TransFiles["translations/"]:::filesystem
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline" 
        direction TB
        Workflow1[".github/workflows/overall-coverage.yml"]:::external
        Workflow2[".github/workflows/publish.yml"]:::external
        Tests["translatable/tests/"]:::external
    end

    CratesIO["Crates.io Registry"]:::external

    %% Relationships
    App -->|"invokes translation! macro"| TransProc
    TransProc -->|"reads config & translations"| Config
    TransProc -->|"reads config & translations"| TransFiles
    TransProc -->|"generates code, links types"| TransShared
    App -->|"calls runtime API"| TransRuntime
    TransRuntime -->|"uses shared logic"| TransShared
    TransShared -->|"dynamic lookup"| TransFiles
    TransShared -->|"dynamic lookup"| Config

    Tests -->|"run tests"| Workflow1
    Tests -->|"run tests"| Workflow2
    Workflow2 -->|"publishes crate"| CratesIO

    %% Click Events
    click TransRuntime "https://github.com/flakysl/translatable/tree/main/translatable/"
    click TransRuntime "https://github.com/flakysl/translatable/blob/main/translatable/Cargo.toml"
    click TransRuntime "https://github.com/flakysl/translatable/blob/main/translatable/src/lib.rs"
    click TransRuntime "https://github.com/flakysl/translatable/blob/main/translatable/src/error.rs"
    click Tests "https://github.com/flakysl/translatable/tree/main/translatable/tests/"

    click TransProc "https://github.com/flakysl/translatable/tree/main/translatable_proc/"
    click TransProc "https://github.com/flakysl/translatable/blob/main/translatable_proc/Cargo.toml"
    click TransProc "https://github.com/flakysl/translatable/blob/main/translatable_proc/src/lib.rs"
    click TransProc "https://github.com/flakysl/translatable/tree/main/translatable_proc/src/data/"
    click TransProc "https://github.com/flakysl/translatable/tree/main/translatable_proc/src/macro_generation/"
    click TransProc "https://github.com/flakysl/translatable/tree/main/translatable_proc/src/macro_input/"

    click TransShared "https://github.com/flakysl/translatable/tree/main/translatable_shared/"
    click TransShared "https://github.com/flakysl/translatable/blob/main/translatable_shared/Cargo.toml"
    click TransShared "https://github.com/flakysl/translatable/blob/main/translatable_shared/src/lib.rs"
    click TransShared "https://github.com/flakysl/translatable/tree/main/translatable_shared/src/macros/"
    click TransShared "https://github.com/flakysl/translatable/tree/main/translatable_shared/src/misc/"
    click TransShared "https://github.com/flakysl/translatable/tree/main/translatable_shared/src/translations/"

    click Config "https://github.com/flakysl/translatable/blob/main/translatable.toml"
    click TransFiles "https://github.com/flakysl/translatable/tree/main/translations/"

    click Workflow1 "https://github.com/flakysl/translatable/blob/main/.github/workflows/overall-coverage.yml"
    click Workflow2 "https://github.com/flakysl/translatable/blob/main/.github/workflows/publish.yml"

    %% Styles
    classDef compileTime fill:#c6dbff,stroke:#3182bd,color:#08306b
    classDef shared fill:#e5f5e0,stroke:#31a354,color:#006d2c
    classDef runtime fill:#fee6ce,stroke:#e6550d,color:#7f2704
    classDef filesystem fill:#f0f0f0,stroke:#999,color:#333
    classDef external fill:#f7f7f7,stroke:#aaa,color:#555,stroke-dasharray: 2 2
```
