# xxpakogamer10xx/laboratoriodigital architecture

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

- Interactive diagram: https://gitdiagram.com/xxpakogamer10xx/laboratoriodigital
- Repository: https://github.com/xxpakogamer10xx/laboratoriodigital

## Overview

##### Project type and purpose
- This is a cross‑platform Flutter application (mobile, web, desktop) called “Laboratorio Digital.”
- It provides interactive educational tools powered by Google’s Generative AI (Gemini) and Firebase (Authentication & Firestore).
- The core use cases: user login/registration, conversation‑style AI assistants (mathematics, physics, IEEE norms), graph/visualization tools (area under a curve, motion graphs), PDF/image analysis, and persistent chat history.

##### File structure
- Top‑level “android/”, “ios/”, “linux/”, “macos/”, “windows/” folders: platform‑specific native hosting code and build scripts.
- “lib/”: all Dart source for UI and business logic—main.dart, pages for each feature (MathExpertPage.dart, AreaVisualizerPage.dart, etc.), auth_gate.dart, firebase_options.dart.
- “assets/” & “fonts/”: static resources (Logo.jpg, custom fonts).
- “web/”: Web‑specific entry (index.html, manifest.json).
- “test/”: widget/unit tests.
- Configuration/build files: pubspec.yaml, .env (Gemini API key), firebase.json, platform build scripts (CMakeLists.txt, Gradle .kts).

##### Key insights from README
- Architecture is client‑heavy: Flutter UI + state management → calls Firebase SDKs and Gemini API.
- Persistent history stored in Firestore.
- Visualization uses CustomPaint & fl_chart.
- LaTeX rendering via flutter_math_fork and math_expressions.

a. Main components
- Flutter Client
– UI Layer (Widgets, Pages)
– Business Logic / State Management (could be Provider, setState, etc.)
– Data Services (FirebaseAuth, FirestoreService, GeminiService, FileService)
- Platform Runners (Android, iOS, Web, Desktop hosts)
- External Services
– Firebase Authentication
– Firebase Firestore (chat histories, user profiles)
– Google Generative AI (Gemini API)
– (Optionally) Cloud Storage for file uploads if used
b. Relationships & data flow
– User interacts with Flutter UI → triggers Business Logic → calls Data Services.
– Authentication flows: Flutter → Firebase Auth → returns user token → gating UI.
– Chat/assistant flows: Flutter → GeminiService (HTTP REST/gRPC) → AI responses → store & retrieve history in Firestore → render in UI.
– Visualization tools: Flutter UI → CustomPaint/fl_chart → compute/render graphs locally.
– PDF/Image analysis: Flutter → FileService → pass binary to Gemini or custom parser → return analysis.
c. Architectural patterns & design principles
– Layered pattern: Presentation → Domain (business logic) → Data (services/SDK wrappers).
– Separation of concerns: each assistant page corresponds to its own service class (e.g., MathExpertService).
– External API integration via environment‑driven configuration (`flutter_dotenv`).
– Plugin-based platform integration for file picking, permissions, device info.
d. Key technologies & frameworks
– Flutter (Dart) for UI & logic
– Firebase SDKs (Auth, Firestore)
– Google Generative AI API (`google_generative_ai` package)
– Visualization: CustomPaint, fl_chart
– Math parsing/rendering: math_expressions, flutter_math_fork
– File & permissions: file_picker, permission_handler, device_info_plus
– Environment management: flutter_dotenv
– Markdown rendering: flutter_markdown

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Platform Runners
    subgraph "Platform Runners"
        direction TB
        Android["Android Shell"]:::platform
        iOS["iOS Shell"]:::platform
        Linux["Linux Shell"]:::platform
        macOS["macOS Shell"]:::platform
        Windows["Windows Shell"]:::platform
        WebRunner["Web Shell"]:::platform
    end

    %% Flutter Engine
    FlutterEngine["Flutter Engine"]:::engine

    %% Flutter Client Layers
    subgraph "Flutter Client"
        direction TB
        subgraph "UI Layer" 
            direction TB
            AuthGate["AuthGate"]:::ui
            LoginPage["LoginPage"]:::ui
            RegisterPage["RegisterPage"]:::ui
            LoginOrRegister["LoginOrRegisterPage"]:::ui
            ForgotPassword["ForgotPasswordPage"]:::ui
            HomeScreen["HomeScreen"]:::ui
            subgraph "AI Assistant Pages"
                MathExpert["MathExpertPage"]:::ui
                PhysicsExpert["PhysicsExpertPage"]:::ui
                IeeeGenerator["IeeeGeneratorPage"]:::ui
            end
            subgraph "Visualization Tools"
                AreaVisualizer["AreaVisualizerPage"]:::ui
                MotionGraph["MotionGraphPage"]:::ui
                ShapesPage["ShapesPage"]:::ui
            end
        end

        subgraph "Logic Layer"
            direction TB
            AuthService["AuthService"]:::logic
            MathExpertService["MathExpertService"]:::logic
            PhysicsService["PhysicsExpertService"]:::logic
            IeeeService["IeeeGeneratorService"]:::logic
            VisualizationService["VisualizationService"]:::logic
            FileService["FileService"]:::logic
        end

        subgraph "Data Layer"
            direction TB
            FirebaseAuthSDK["FirebaseAuth SDK"]:::data
            FirestoreService["FirestoreService"]:::data
            GeminiService["GeminiService"]:::data
            FirebaseStorage["FirebaseStorage (optional)"]:::data
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        FirebaseAuth["Firebase Authentication"]:::external
        Firestore["Firestore Database"]:::database
        GeminiAPI["Gemini API"]:::external
        CloudStorage["Cloud Storage"]:::external
    end

    %% Connections: Platform to Engine
    Android --> FlutterEngine
    iOS --> FlutterEngine
    Linux --> FlutterEngine
    macOS --> FlutterEngine
    Windows --> FlutterEngine
    WebRunner --> FlutterEngine

    %% Engine to Client
    FlutterEngine --> FlutterClient

    %% UI to Logic
    AuthGate --> AuthService
    LoginPage --> AuthService
    RegisterPage --> AuthService
    LoginOrRegister --> AuthService
    ForgotPassword --> AuthService
    HomeScreen --> AuthService

    MathExpert --> MathExpertService
    PhysicsExpert --> PhysicsService
    IeeeGenerator --> IeeeService

    AreaVisualizer --> VisualizationService
    MotionGraph --> VisualizationService
    ShapesPage --> FileService

    %% Logic to Data
    AuthService --> FirebaseAuthSDK
    MathExpertService --> GeminiService
    PhysicsService --> GeminiService
    IeeeService --> GeminiService
    VisualizationService --> FirestoreService
    FileService --> FirebaseStorage

    %% Data to External
    FirebaseAuthSDK --> FirebaseAuth
    FirestoreService --> Firestore
    GeminiService --> GeminiAPI
    FirebaseStorage --> CloudStorage

    %% Return flows (simplified)
    FirebaseAuth --> FirebaseAuthSDK --> AuthService --> AuthGate
    GeminiAPI --> GeminiService --> MathExpertService --> MathExpert
    Firestore --> FirestoreService --> VisualizationService --> AreaVisualizer

    %% Click Events
    click FlutterClient "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/lib/"
    click FlutterEngine "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/main.dart"
    click WebRunner "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/main_web.dart"
    click AuthGate "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/auth_gate.dart"
    click LoginPage "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/login_page.dart"
    click RegisterPage "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/register_page.dart"
    click LoginOrRegister "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/login_or_register_page.dart"
    click ForgotPassword "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/forgot_password_page.dart"
    click HomeScreen "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/HomeScreen.dart"
    click MathExpert "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/MathExpertPage.dart"
    click PhysicsExpert "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/PhysicsExpertPage.dart"
    click IeeeGenerator "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/IeeeGeneratorPage.dart"
    click AreaVisualizer "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/AreaVisualizerPage.dart"
    click MotionGraph "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/MotionGraphPage.dart"
    click ShapesPage "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/ShapesPage.dart"
    click FirebaseAuthSDK "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/firebase_options.dart"
    click WebRunner "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/lib/html_stub.dart"
    click FlutterClient "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/assets/"
    click FlutterClient "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/fonts/"
    click FirebaseAuth "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/firebase.json"
    click Android "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/android/"
    click iOS "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/ios/"
    click Linux "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/linux/"
    click macOS "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/macos/"
    click Windows "https://github.com/xxpakogamer10xx/laboratoriodigital/tree/main/windows/"
    click test "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/test/widget_test.dart"
    click pubspec "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/pubspec.yaml"
    click env "https://github.com/xxpakogamer10xx/laboratoriodigital/blob/main/.env"

    %% Styles
    classDef platform fill:#f9f,stroke:#333,stroke-width:1px
    classDef engine fill:#b3e5fc,stroke:#333,stroke-width:1px
    classDef ui fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef logic fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef data fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef external fill:#ffccbc,stroke:#333,stroke-width:1px
    classDef database fill:#ffecb3,stroke:#333,stroke-width:1px
```
