# tarek3222/translatify architecture

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

- Interactive diagram: https://gitdiagram.com/tarek3222/translatify
- Repository: https://github.com/tarek3222/translatify

## Overview

##### Project type and purpose
- Translatify is a *cross-platform Flutter client app* (mobile/web/desktop) for tourists to discover and chat with translators, perform AI and image-based translations, manage bookings/payments, and personalize their profile.
- There is no in-repo backend; all data operations happen via remote APIs (your own backend, Google Translate, AWS, Stripe) and local storage (shared prefs).

##### File structure for architectural layers
- **lib/core**: core services (dependency injection, networking, theming, routing, utilities, reusable widgets)
- **lib/features**: 14 feature modules (onboarding, auth, home, chat, google_translate, main, payment, settings, sign_in/up, translator_profile, user_profile) each with:
- data (models, repos, local/remote data sources)
- logic (BLoCs/Cubits and states)
- ui (views and widgets)
- **platform dirs** (android, ios, linux, macos, windows, web) host Flutter platform code.

##### Main components
A. **Presentation Layer** (UI + Navigation)
- Feature UI modules (Widgets/Views)
- Core AppRouter (routes)
- Main entry point (main.dart → TranslatorsApp)
B. **State Management Layer**
- BLoC/Cubit instances per feature
- Connected to UI via BlocBuilder/BlocConsumer
C. **Domain/Data Layer**
- Repositories (e.g., ChatsRepo, TranslatorsListRepo, PaymentRepo, etc.)
- Data Sources
- Remote (Dio-Retrofit API clients)
- Local (SharedPreferences helpers, local data sources for caching)
D. **Core Services**
- DI Container (Get_it)
- Network Info (connectivity check)
- DioFactory & ApiService
- SharedPreferences helper
- Theming & Localization
E. **External Services**
- Your backend API (BASE_URL endpoints)
- Google Translate API
- AWS Translate/TTS
- Stripe API

##### Relationships & Data Flow
1. **UI → BLoC/Cubit**
- User interaction in a View dispatches events to its Cubit.
2. **Cubit → Repository**
- Cubit calls a method on its corresponding Repo.
3. **Repo → Data Source**
- Repo decides between remote or local data source.
4. **Remote Data Source → ApiService → External API**
- Uses DioFactory to get Dio instance, then Retrofit-generated service to call endpoints.
5. **Local Data Source → SharedPreferences**
- Caches data (e.g., chats cache, favorites).
6. **External API Response → Models → Cubit → UI**
- Data flows back via models (generated with json_serializable) to update Cubit state, then UI rebuilds.

##### Architectural patterns & design principles
- **MVVM + BLoC**: Views observe Cubit (like ViewModel) states.
- **Dependency Injection**: All services (ApiService, Repos, Cubits) are registered in a get_it container at startup.
- **Layered Architecture**: Clear separation between presentation, logic, data, and infrastructure.
- **Feature-first modularization**: Each domain area is self-contained under lib/features.

##### Elements
- **Components** labeled with their package names (e.g., lib/features/chat/logic/ChatCubit).
- Rectangles for components (UI, Cubit, Repo, DataSource)
- Clouds for external APIs (Google, AWS, Stripe, backend)

##### Detail level
- Core global services (DI, Networking, Theme) centrally at top or bottom.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer (Blue)
    subgraph "Presentation Layer" 
        style Presentation fill:#CCE5FF,stroke:#3399FF,stroke-width:2px
        Main["main.dart\n(Entry Point)"]:::presentation
        TranslatorsApp["TranslatorsApp\n(App Widget)"]:::presentation
        AppRouter["AppRouter\n(Routing)"]:::presentation
        Routes["Routes\n(Definitions)"]:::presentation
        subgraph "Theme & Styles"
            Theme["AppTheme"]:::presentation
            Colors["AppColors"]:::presentation
            Styles["AppStyles"]:::presentation
        end
    end

    %% State Management Layer (Green)
    subgraph "State Management Layer"
        style State fill:#D5F5E3,stroke:#28B463,stroke-width:2px
        ChatCubit["ChatCubit"]:::state
        ChatState["ChatState"]:::state
        ChatsListCubit["ChatsListCubit"]:::state
        ChatsListState["ChatsListState"]:::state
        PaymentCubit["PaymentCubit"]:::state
        PaymentStates["PaymentStates"]:::state
    end

    %% Data/Domain Layer (Orange)
    subgraph "Data/Domain Layer"
        style Data fill:#FFE5CC,stroke:#FF9933,stroke-width:2px
        ChatsRepo["ChatsRepo"]:::data
        TranslatorsListRepo["TranslatorsListRepo"]:::data
        CheckoutRepo["CheckOutRepo"]:::data
        CreateCustomerRepo["CreateCustomerRepo"]:::data

        ApiService["ApiService"]:::data
        StripeApiService["StripeApiService"]:::data
        TranslateService["TranslateService"]:::data
        ImageService["ImageService"]:::data
        TTSService["TTSService"]:::data

        ChatLocalDS["ChatLocalDataSource"]:::data
        TranslatorsLocalDS["TranslatorsListLocalDataSource"]:::data
        PaymentLocalDS["PaymentTranslatorsLocalDataSource"]:::data
    end

    %% Core Services (Gray)
    subgraph "Core Services"
        style Core fill:#F2F3F4,stroke:#B2BABB,stroke-width:2px
        DI["DependencyInjection"]:::core
        DioFactory["DioFactory"]:::core
        NetworkInfo["NetworkInfo"]:::core
        APIErrorHandler["ApiErrorHandler"]:::core
        SharedPref["SharedPreferenceHelper"]:::core
        AppConstants["AppConstants"]:::core
    end

    %% External Systems (Purple)
    subgraph "External Systems"
        style External fill:#E8DAEF,stroke:#A569BD,stroke-width:2px
        BackendAPI["Backend API\n(Your server)"]:::external
        GoogleAPI["Google Translate API"]:::external
        AWSAPI["AWS Translate/TTS"]:::external
        StripeAPI["Stripe API"]:::external
    end

    %% Relationships
    Main --> TranslatorsApp
    TranslatorsApp --> AppRouter
    AppRouter --> Routes
    TranslatorsApp --> Theme
    TranslatorsApp --> Colors
    TranslatorsApp --> Styles

    %% Presentation to State
    TranslatorsApp --> ChatCubit
    TranslatorsApp --> ChatsListCubit
    TranslatorsApp --> PaymentCubit

    %% State to Data
    ChatCubit --> ChatsRepo
    ChatsListCubit --> ChatsRepo
    PaymentCubit --> CheckoutRepo
    PaymentCubit --> CreateCustomerRepo

    %% Repo to DataSource
    ChatsRepo --> ApiService
    ChatsRepo --> ChatLocalDS
    TranslatorsListRepo --> ApiService
    TranslatorsListRepo --> TranslatorsLocalDS
    CheckoutRepo --> StripeApiService
    CreateCustomerRepo --> StripeApiService
    TranslateService --> ApiService
    ImageService --> ApiService
    TTSService --> ApiService

    %% DataSource to Core Services
    ApiService --> DioFactory
    ApiService --> NetworkInfo
    ApiService --> APIErrorHandler
    ChatLocalDS --> SharedPref
    TranslatorsLocalDS --> SharedPref
    PaymentLocalDS --> SharedPref

    %% Repos to External
    ApiService --> BackendAPI
    StripeApiService --> StripeAPI
    TranslateService --> GoogleAPI
    ImageService --> GoogleAPI
    TTSService --> AWSAPI

    %% Core init
    DI --> DioFactory
    DI --> NetworkInfo
    DI --> APIErrorHandler
    DI --> SharedPref
    DI --> AppConstants
    DI --> ApiService
    DI --> ChatsRepo
    DI --> TranslatorsListRepo
    DI --> CheckoutRepo
    DI --> CreateCustomerRepo
    DI --> ChatCubit
    DI --> ChatsListCubit
    DI --> PaymentCubit

    %% Click Events
    click Main "https://github.com/tarek3222/translatify/blob/main/lib/main.dart"
    click TranslatorsApp "https://github.com/tarek3222/translatify/blob/main/lib/translators_app.dart"
    click AppRouter "https://github.com/tarek3222/translatify/blob/main/lib/core/routing/app_router.dart"
    click Routes "https://github.com/tarek3222/translatify/blob/main/lib/core/routing/routes.dart"
    click Theme "https://github.com/tarek3222/translatify/blob/main/lib/core/theme/app_theme.dart"
    click Colors "https://github.com/tarek3222/translatify/blob/main/lib/core/theme/app_colors.dart"
    click Styles "https://github.com/tarek3222/translatify/blob/main/lib/core/theme/app_styles.dart"
    click ChatCubit "https://github.com/tarek3222/translatify/blob/main/lib/features/chat/logic/chat_cubit/chat_cubit.dart"
    click ChatState "https://github.com/tarek3222/translatify/blob/main/lib/features/chat/logic/chat_cubit/chat_state.dart"
    click ChatsListCubit "https://github.com/tarek3222/translatify/blob/main/lib/features/chat/logic/cubit/chats_list_cubit.dart"
    click ChatsListState "https://github.com/tarek3222/translatify/blob/main/lib/features/chat/logic/cubit/chats_list_state.dart"
    click PaymentCubit "https://github.com/tarek3222/translatify/blob/main/lib/features/payment/logic/payment_cubit/payment_cubit.dart"
    click PaymentStates "https://github.com/tarek3222/translatify/blob/main/lib/features/payment/logic/payment_cubit/payment_states.dart"
    click ChatsRepo "https://github.com/tarek3222/translatify/blob/main/lib/features/chat/data/repo/chats_repo.dart"
    click TranslatorsListRepo "https://github.com/tarek3222/translatify/blob/main/lib/features/home/data/repos/translators_list_repo.dart"
    click CheckoutRepo "https://github.com/tarek3222/translatify/blob/main/lib/features/payment/data/repos/check_out_repo.dart"
    click CreateCustomerRepo "https://github.com/tarek3222/translatify/blob/main/lib/features/payment/data/repos/create_customer_repo.dart"
    click ApiService "https://github.com/tarek3222/translatify/blob/main/lib/core/networking/api_service.dart"
    click StripeApiService "https://github.com/tarek3222/translatify/blob/main/lib/features/payment/data/data_source/remote_data_source/stripe_api_services.dart"
    click TranslateService "https://github.com/tarek3222/translatify/blob/main/lib/features/google_translate/data/services/translate_service.dart"
    click ImageService "https://github.com/tarek3222/translatify/blob/main/lib/features/google_translate/data/services/image_service.dart"
    click TTSService "https://github.com/tarek3222/translatify/blob/main/lib/features/google_translate/data/services/tts_service.dart"
    click ChatLocalDS "https://github.com/tarek3222/translatify/blob/main/lib/features/chat/data/data_source/local_data_source/chats_list_local_data_source.dart"
    click TranslatorsLocalDS "https://github.com/tarek3222/translatify/blob/main/lib/features/home/data/date_source/local_data_source/translators_list_local_data_source.dart"
    click PaymentLocalDS "https://github.com/tarek3222/translatify/blob/main/lib/features/payment/data/data_source/local_data_source/payment_translators_local_data_source.dart"
    click DI "https://github.com/tarek3222/translatify/blob/main/lib/core/di/depandecy_injection.dart"
    click DioFactory "https://github.com/tarek3222/translatify/blob/main/lib/core/networking/dio_factory.dart"
    click NetworkInfo "https://github.com/tarek3222/translatify/blob/main/lib/core/networking/network_info.dart"
    click APIErrorHandler "https://github.com/tarek3222/translatify/blob/main/lib/core/networking/api_error_handler.dart"
    click SharedPref "https://github.com/tarek3222/translatify/blob/main/lib/core/helpers/shared_preference_helper.dart"
    click AppConstants "https://github.com/tarek3222/translatify/blob/main/lib/core/utils/app_constants.dart"

    %% Styles
    classDef presentation fill:#CCE5FF,stroke:#3399FF,color:#000
    classDef state fill:#D5F5E3,stroke:#28B463,color:#000
    classDef data fill:#FFE5CC,stroke:#FF9933,color:#000
    classDef core fill:#F2F3F4,stroke:#B2BABB,color:#000
    classDef external fill:#E8DAEF,stroke:#A569BD,color:#000
```
