# alexandrim0/tentura architecture

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

- Interactive diagram: https://gitdiagram.com/alexandrim0/tentura
- Repository: https://github.com/alexandrim0/tentura

## Overview

##### Project Type and Purpose
- Tentura is a social network application “based on MeritRank” with multiple features (auth, beacon, chat, comment, profile, etc.).
- The project targets mobile (Android and iOS), web, and even a widgetbook for design previews, showcasing its multi-platform nature.
- The README emphasizes a build process that involves GraphQL code generation and database schema management, reflecting a robust data layer with both remote (GraphQL API) and local (Drift-driven SQLite) data stores.

##### Primary Components of the Architecture
a. Presentation Layer
- UI Screens and Widgets: Located in directories such as lib/app, lib/ui, and each feature’s ui folder (for example, lib/features/auth/ui/screen, lib/features/beacon/ui/screen, etc.).
- BLoC/Cubit Modules: Every feature includes a bloc or cubit in its ui/bloc subdirectories (e.g., auth_cubit.dart, beacon_cubit.dart, chat_cubit.dart). These components manage the state transitions and business logic triggered by user interactions.

b. Business Logic / Domain Layer
- Use Cases and Domain Entities: Found under directories like lib/domain and within each feature’s domain folder. These encapsulate the actual business rules and logic.
- Domain Exceptions and Use Case modules: For handling logic errors and executing business workflows.

c. Data Layer
- Repositories: Each feature has its own repository folder (e.g., lib/features/auth/data/repository) to interface with data sources.
- Data Sources: Includes both remote services (GraphQL-based, as evidenced by lib/data/gql and packages/tentura_sdk for API clients) and local storage (such as Drift for local databases located in lib/data/database).
- Service Modules: Additional abstraction layers for API communication (e.g., remote_api_service.dart, local_secure_storage.dart) and specialized modules like image and token services from the tentura_sdk package.

d. Infrastructure and Integration
- Dependency Injection: The directory lib/app/di (with files like di.dart and modules.dart) suggests a centralized mechanism for managing dependencies.
- External Integrations: GraphQL code generation, API clients, and database schema management tools are part of the build process (as directed in the README).

##### Relationships and Interactions
- User Interaction Flow: The user interacts with the UI layer (screens/widgets). Actions are captured by BLoC/Cubit modules, which are the heart of the business logic.
- Integration with External Services: Show how repository components interact with both remote GraphQL APIs (via the tentura_sdk or internal GraphQL clients) and the local database. Highlight connectors to local (SQLite/Drift) and remote systems.

##### Emphasizing BLoC/Cubit Modules
- How each feature’s BLoC/Cubit module is structured.
- The events (user actions) being sent to these modules.
- The process of state transformation (e.g., loading, success, error states).
- How these modules interface with the domain layer to fetch or process data.

##### Additional Elements
- Clear labels for each component.
- External system components such as GraphQL APIs, local secure storage, and database connectors.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        PS_Core["Core UI (Screens/Widgets)"]
        PS_Global["Global UI Components"]
        PS_Auth["Auth Screen"]
        PS_Beacon["Beacon Screen"]
        PS_Chat["Chat Screen"]
    end

    %% BLoC/Cubit Layer
    subgraph "BLoC/Cubit Layer"
        B_Auth["AuthCubit"]
        B_Beacon["BeaconCubit"]
        B_Chat["ChatCubit"]
        B_Comment["CommentCubit"]
        B_Other["Other Feature Blocs"]
    end

    %% BLoC/Cubit Details Inset
    subgraph "BLoC/Cubit Details"
        BE_Auth["AuthEvent"]
        BP_Auth["AuthCubit Processing\n(Loading,Success,Error)"]
        BE_Beacon["BeaconEvent"]
        BP_Beacon["BeaconCubit Processing\n(Loading,Success,Error)"]
        BE_Chat["ChatEvent"]
        BP_Chat["ChatCubit Processing\n(Loading,Success,Error)"]
        BE_Comment["CommentEvent"]
        BP_Comment["CommentCubit Processing\n(Loading,Success,Error)"]
        UI_Update["UI State Update"]
    end

    %% Domain Layer
    subgraph "Domain Layer"
        D_UseCase["Use Cases & Domain Entities"]
    end

    %% Data Layer
    subgraph "Data Layer"
        R_Auth["Auth Repository"]
        R_Beacon["Beacon Repository"]
        R_Chat["Chat Repository"]
        R_Comment["Comment Repository"]
        DS_Remote["Remote API (GraphQL)"]
        DS_Local["Local Database (SQLite/Drift)"]
        DS_Services["Data Services"]
    end

    %% Infrastructure & Integration
    subgraph "Infrastructure & Integration"
        I_DI["DI Container"]
        I_Ext["External SDK/API & CodeGen"]
        I_Platform["Multi-Platform Configurations\n(Android, iOS, Web)"]
    end

    %% Relationships
    %% User interactions with UI
    User["User"]:::presentation
    User -->|"interacts"| PS_Core
    User -->|"interacts"| PS_Global

    %% UI triggering events for features
    PS_Auth -->|"triggers"| BE_Auth
    PS_Beacon -->|"triggers"| BE_Beacon
    PS_Chat -->|"triggers"| BE_Chat

    %% BLoC/Cubit Layer connections to BLoC Details inset
    BE_Auth --> BP_Auth
    BP_Auth --> UI_Update
    BE_Beacon --> BP_Beacon
    BP_Beacon --> UI_Update
    BE_Chat --> BP_Chat
    BP_Chat --> UI_Update
    BE_Comment --> BP_Comment
    BP_Comment --> UI_Update

    %% Linking UI directly to BLoC modules (for state update cycle)
    PS_Core -->|"receives state updates"| UI_Update

    %% UI drives corresponding BLoC modules
    PS_Auth -->|"sends event"| B_Auth
    PS_Beacon -->|"sends event"| B_Beacon
    PS_Chat -->|"sends event"| B_Chat
    %% Comment UI is assumed part of additional feature flows and connected similarly
    PS_Global -->|"may trigger"| B_Comment

    %% BLoC modules calling Domain use cases
    B_Auth -->|"invokes"| D_UseCase
    B_Beacon -->|"invokes"| D_UseCase
    B_Chat -->|"invokes"| D_UseCase
    B_Comment -->|"invokes"| D_UseCase

    %% Domain layer interaction with Data layer through Repositories
    D_UseCase -->|"calls"| R_Auth
    D_UseCase -->|"calls"| R_Beacon
    D_UseCase -->|"calls"| R_Chat
    D_UseCase -->|"calls"| R_Comment

    %% Repositories interacting with Data Sources
    R_Auth -->|"fetch/update"| DS_Remote
    R_Auth -->|"cache/read/write"| DS_Local
    R_Beacon -->|"fetch/update"| DS_Remote
    R_Beacon -->|"cache/read/write"| DS_Local
    R_Chat -->|"fetch/update"| DS_Remote
    R_Chat -->|"cache/read/write"| DS_Local
    R_Comment -->|"fetch/update"| DS_Remote
    R_Comment -->|"cache/read/write"| DS_Local

    %% Data Services support Data Sources
    DS_Services --> DS_Remote
    DS_Services --> DS_Local

    %% Infrastructure connections
    I_DI -->|"injects dependencies into"| B_Auth
    I_DI -->|"injects dependencies into"| B_Beacon
    I_DI -->|"injects dependencies into"| B_Chat
    I_DI -->|"injects dependencies into"| B_Comment
    I_DI -->|"injects into"| D_UseCase
    I_DI -->|"injects into"| R_Auth
    I_DI -->|"injects into"| R_Beacon
    I_DI -->|"injects into"| R_Chat
    I_DI -->|"injects into"| R_Comment

    I_Ext --> DS_Remote
    I_Ext --> DS_Services

    I_Platform --> PS_Core
    I_Platform --> PS_Global

    %% Styling
    classDef presentation fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef bloc fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef domain fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef data fill:#FADBD8,stroke:#CB4335,stroke-width:2px;
    classDef infra fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef details fill:#FCF3CF,stroke:#B9770E,stroke-width:2px;

    class User,PS_Core,PS_Global,PS_Auth,PS_Beacon,PS_Chat presentation;
    class B_Auth,B_Beacon,B_Chat,B_Comment,B_Other bloc;
    class BE_Auth,BP_Auth,BE_Beacon,BP_Beacon,BE_Chat,BP_Chat,BE_Comment,BP_Comment,UI_Update details;
    class D_UseCase domain;
    class R_Auth,R_Beacon,R_Chat,R_Comment,DS_Remote,DS_Local,DS_Services data;
    class I_DI,I_Ext,I_Platform infra;

%% Click Events
    %% Presentation Layer Clicks
    click PS_Core "https://github.com/alexandrim0/tentura/tree/main/lib/app"
    click PS_Global "https://github.com/alexandrim0/tentura/tree/main/lib/ui"
    click PS_Auth "https://github.com/alexandrim0/tentura/tree/main/lib/features/auth/ui/screen"
    click PS_Beacon "https://github.com/alexandrim0/tentura/tree/main/lib/features/beacon/ui/screen"
    click PS_Chat "https://github.com/alexandrim0/tentura/tree/main/lib/features/chat/ui/screen"

    %% BLoC/Cubit Modules Clicks
    click B_Auth "https://github.com/alexandrim0/tentura/blob/main/lib/features/auth/ui/bloc/auth_cubit.dart"
    click B_Auth "https://github.com/alexandrim0/tentura/blob/main/lib/features/auth/ui/bloc/auth_state.dart"
    click B_Beacon "https://github.com/alexandrim0/tentura/blob/main/lib/features/beacon/ui/bloc/beacon_cubit.dart"
    click B_Beacon "https://github.com/alexandrim0/tentura/blob/main/lib/features/beacon/ui/bloc/beacon_state.dart"
    click B_Chat "https://github.com/alexandrim0/tentura/blob/main/lib/features/chat/ui/bloc/chat_cubit.dart"
    click B_Comment "https://github.com/alexandrim0/tentura/blob/main/lib/features/comment/ui/bloc/comment_cubit.dart"
    click B_Comment "https://github.com/alexandrim0/tentura/blob/main/lib/features/comment/ui/bloc/comment_state.dart"

    %% Domain Layer Clicks
    click D_UseCase "https://github.com/alexandrim0/tentura/tree/main/lib/domain"

    %% Data Layer Clicks
    click R_Auth "https://github.com/alexandrim0/tentura/blob/main/lib/features/auth/data/repository/auth_repository.dart"
    click R_Beacon "https://github.com/alexandrim0/tentura/blob/main/lib/features/beacon/data/repository/beacon_repository.dart"
    click R_Chat "https://github.com/alexandrim0/tentura/blob/main/lib/features/chat/data/repository/chat_repository.dart"
    click R_Comment "https://github.com/alexandrim0/tentura/blob/main/lib/features/comment/data/repository/comment_repository.dart"
    click DS_Remote "https://github.com/alexandrim0/tentura/tree/main/lib/data/gql"
    click DS_Local "https://github.com/alexandrim0/tentura/tree/main/lib/data/database"
    click DS_Services "https://github.com/alexandrim0/tentura/tree/main/lib/data/service"

    %% Infrastructure & Integration Clicks
    click I_DI "https://github.com/alexandrim0/tentura/tree/main/lib/app/di"
    click I_Ext "https://github.com/alexandrim0/tentura/tree/main/packages/tentura_sdk/lib/src/client"
```
