# tung204/dntu_focus architecture

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

- Interactive diagram: https://gitdiagram.com/tung204/dntu_focus
- Repository: https://github.com/tung204/dntu_focus

## Overview

##### Project Type and Purpose
- Project Type: Full-stack, cross-platform mobile/desktop/web application built with Flutter.
- Purpose: A productivity app combining Pomodoro timers, AI chat commands, and task scheduling/management, synchronized via Firebase and stored offline via Hive.

##### Main Architectural Components
a. Client Application (Flutter)
- Platforms: Android, iOS, Web, Windows, macOS, Linux.
- Layers inside the client:
- Presentation: Screens and widgets under lib/features/*/presentation and lib/core/widgets
- State Management: BLoC classes (lib/features/*/domain/*.dart using flutter_bloc) and Provider (in lib/core/themes)
- Domain/Business Logic: Cubits, state classes under lib/features/*/domain
- Data Layer: Repositories under lib/features/*/data (task_repository.dart, pomodoro_repository.dart, auth_repository.dart)
- Utilities & Core Services: Hive local storage, BackupService, FirebaseService, GeminiService, NotificationService in lib/core/services
- Routing/Navigation: lib/routes/app_routes.dart and lib/navigation/navigation_manager.dart

b. Local Storage
- Hive database for offline-first persistence (see lib/core/services/backup_service.dart and models under lib/features/tasks/data/models)

c. Cloud & External Services
- Firebase Firestore: Primary data sync for tasks/projects/tags
- Firebase Cloud Messaging: Push notifications for reminders
- Firebase Cloud Functions (functions/index.js): Any custom backend logic or triggers
- Google Gemini AI Service: Natural language processing for AI chat commands (gemini_service.dart)
- Third-Party APIs/Libraries: speech_to_text, flutter_dotenv (for GEMINI_API_KEY), google_fonts

d. Assets & Media
- Local media (audio files, splash video) in assets/images and assets/sounds for white-noise backgrounds

##### Relationships and Data Flows
- User interacts with Flutter UI → UI dispatches events to BLoC/Providers →
–  BLoC calls Repositories →
○  Local: read/write via Hive
○  Remote: read/write via Firebase Firestore or Cloud Functions
○  AI: calls GeminiService (direct HTTP calls with API key)
- Cloud Functions may subscribe to Firestore triggers to process data or send push notifications.
- Firebase Messaging delivers notifications back to the client → NotificationService handles them.
- BackupService periodically syncs Hive data up to Firestore in the background.

##### Architectural Patterns & Principles
- Feature-based modularization: code organized by feature domain (auth, home, tasks, ai_chat, etc.)
- BLoC for unidirectional data flow and state management
- Repository pattern for data abstraction
- Offline-first strategy with Hive, fallback to Firestore when online
- Dependency injection via Provider for theming and environment config

##### Final Checklist
[ ] All major components represented
[ ] Interactions and data flows clearly annotated
[ ] Architectural patterns called out (BLoC, Repository, Offline-First)
[ ] Technology labels (Flutter, Firebase, Hive, Gemini) included

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Flutter Client"
        direction TB
        subgraph "Presentation Layer"
            direction TB
            AuthScreens["Auth Screens"]:::frontend
            click AuthScreens "https://github.com/tung204/dntu_focus/blob/master/lib/features/auth/presentation/*.dart"
            TasksScreens["Tasks Screens"]:::frontend
            click TasksScreens "https://github.com/tung204/dntu_focus/tree/master/lib/features/tasks/presentation/"
            PomodoroScreen["Pomodoro Screen"]:::frontend
            click PomodoroScreen "https://github.com/tung204/dntu_focus/blob/master/lib/features/pomodoro/presentation/pomodoro_screen.dart"
            AIChatScreen["AI Chat Screen"]:::frontend
            click AIChatScreen "https://github.com/tung204/dntu_focus/blob/master/lib/features/ai_chat/presentation/ai_chat_screen.dart"
            HomeScreen["Home Screen & Widgets"]:::frontend
            click HomeScreen "https://github.com/tung204/dntu_focus/tree/master/lib/features/home/presentation/"
            CalendarScreen["Calendar Screen"]:::frontend
            click CalendarScreen "https://github.com/tung204/dntu_focus/blob/master/lib/features/calendar/presentation/calendar_screen.dart"
            ReportScreen["Report Screen"]:::frontend
            click ReportScreen "https://github.com/tung204/dntu_focus/blob/master/lib/features/report/presentation/report_screen.dart"
            SettingsScreens["Settings Screens"]:::frontend
            click SettingsScreens "https://github.com/tung204/dntu_focus/blob/master/lib/features/settings/presentation/*.dart"
            SplashScreen["Splash Screen"]:::frontend
            click SplashScreen "https://github.com/tung204/dntu_focus/blob/master/lib/features/splash/presentation/splash_screen.dart"
        end
        subgraph "State Management (Cubits)"
            direction TB
            AuthCubit["Auth Cubit"]:::frontend
            click AuthCubit "https://github.com/tung204/dntu_focus/blob/master/lib/features/auth/domain/auth_cubit.dart"
            TaskCubit["Task Cubit"]:::frontend
            click TaskCubit "https://github.com/tung204/dntu_focus/blob/master/lib/features/tasks/domain/task_cubit.dart"
            PomodoroCubit["Pomodoro Cubit"]:::frontend
            click PomodoroCubit "https://github.com/tung204/dntu_focus/blob/master/lib/features/pomodoro/domain/pomodoro_cubit.dart"
            HomeCubit["Home Cubit"]:::frontend
            click HomeCubit "https://github.com/tung204/dntu_focus/blob/master/lib/features/home/domain/home_cubit.dart"
            SettingsCubit["Settings Cubit"]:::frontend
            click SettingsCubit "https://github.com/tung204/dntu_focus/blob/master/lib/features/settings/domain/settings_cubit.dart"
        end
        subgraph "Data Layer (Repositories)"
            direction TB
            AuthRepo["Auth Repository"]:::frontend
            click AuthRepo "https://github.com/tung204/dntu_focus/blob/master/lib/features/auth/data/auth_repository.dart"
            TaskRepo["Task Repository"]:::frontend
            click TaskRepo "https://github.com/tung204/dntu_focus/blob/master/lib/features/tasks/data/task_repository.dart"
            PomodoroRepo["Pomodoro Repository"]:::frontend
            click PomodoroRepo "https://github.com/tung204/dntu_focus/blob/master/lib/features/pomodoro/data/pomodoro_repository.dart"
        end
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::frontend
            click UserModel "https://github.com/tung204/dntu_focus/blob/master/lib/features/auth/data/user_model.dart"
            ProjectModel["Project Model"]:::frontend
            click ProjectModel "https://github.com/tung204/dntu_focus/blob/master/lib/features/tasks/data/models/project_model.dart"
            TagModel["Tag Model"]:::frontend
            click TagModel "https://github.com/tung204/dntu_focus/blob/master/lib/features/tasks/data/models/tag_model.dart"
            TaskModel["Task Model"]:::frontend
            click TaskModel "https://github.com/tung204/dntu_focus/blob/master/lib/features/tasks/data/models/task_model.dart"
        end
        subgraph "Core Services"
            direction TB
            BackupService["Backup Service"]:::service
            click BackupService "https://github.com/tung204/dntu_focus/blob/master/lib/core/services/backup_service.dart"
            FirebaseService["Firebase Sync Service"]:::service
            click FirebaseService "https://github.com/tung204/dntu_focus/blob/master/lib/core/services/firebase_service.dart"
            GeminiService["Gemini AI Service"]:::service
            click GeminiService "https://github.com/tung204/dntu_focus/blob/master/lib/core/services/gemini_service.dart"
            NotificationService["Notification Service"]:::service
            click NotificationService "https://github.com/tung204/dntu_focus/blob/master/lib/core/services/unified_notification_service.dart"
        end
        subgraph "Routing & Navigation"
            direction TB
            AppRoutes["App Routes"]:::frontend
            click AppRoutes "https://github.com/tung204/dntu_focus/blob/master/lib/routes/app_routes.dart"
            NavManager["Navigation Manager"]:::frontend
            click NavManager "https://github.com/tung204/dntu_focus/blob/master/lib/core/navigation/navigation_manager.dart"
        end
        subgraph "Themes & Providers"
            direction TB
            ThemeDef["Theme Definition"]:::frontend
            click ThemeDef "https://github.com/tung204/dntu_focus/blob/master/lib/core/themes/theme.dart"
            ThemeProv["Theme Provider"]:::frontend
            click ThemeProv "https://github.com/tung204/dntu_focus/blob/master/lib/core/themes/theme_provider.dart"
        end
        subgraph "Core Widgets & Utils"
            direction TB
            Widgets["Core Widgets"]:::frontend
            click Widgets "https://github.com/tung204/dntu_focus/tree/master/lib/core/widgets/"
            Utils["Core Utils"]:::frontend
            click Utils "https://github.com/tung204/dntu_focus/tree/master/lib/core/utils/"
        end
    end

    FlutterClient["Flutter Client"]:::frontend
    click FlutterClient "https://github.com/tung204/dntu_focus/tree/master/lib/"

    LocalHive["Hive Local DB"]:::db
    Firestore["Firebase Firestore"]:::db
    Messaging["Firebase Cloud Messaging"]:::service
    CloudFunctions["Firebase Cloud Functions"]:::service
    GeminiAI["Google Gemini API"]:::service
    Assets["Media Assets"]:::asset

    FlutterClient -->|"UI Events"| AuthScreens
    AuthScreens -->|"dispatch events"| AuthCubit
    AuthCubit -->|"calls"| AuthRepo
    AuthRepo -->|read/write| LocalHive
    AuthRepo -->|read/write| Firestore

    TaskCubit -->|"calls"| TaskRepo
    TaskRepo -->|read/write| LocalHive
    TaskRepo -->|read/write| Firestore

    PomodoroCubit -->|"calls"| PomodoroRepo
    PomodoroRepo -->|read/write| LocalHive

    BackupService -->|"sync"| Firestore
    LocalHive -->|"periodic sync"| BackupService

    CloudFunctions <-->|"triggers"| Firestore
    Messaging -->|"push notification"| FlutterClient
    FlutterClient -->|"calls"| GeminiAI
    FlutterClient -->|"read assets"| Assets

    classDef frontend fill:#E3F2FD,stroke:#2196F3,color:#0D47A1,stroke-width:2px;
    classDef db fill:#E8F5E9,stroke:#4CAF50,color:#1B5E20,stroke-width:2px,shape:cylinder;
    classDef service fill:#FFF3E0,stroke:#FF9800,color:#E65100,stroke-width:2px;
    classDef asset fill:#ECEFF1,stroke:#90A4AE,color:#37474F,stroke-width:2px,shape:file;
```
