# hash-studios/prism architecture

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

- Interactive diagram: https://gitdiagram.com/hash-studios/prism
- Repository: https://github.com/hash-studios/prism

## Overview

##### Project Type & Purpose
- Prism is a full-stack mobile application built primarily with Flutter (using Dart) targeting Android (with iOS support) that delivers high-quality wallpapers and home screen setups.
- Its purpose is to provide an attractive, high-performance user interface for browsing, downloading, and setting wallpapers and setups, while also managing user interactions (such as authentication, notifications, and social sharing) and interacting with external services (e.g., WallHaven, Pexels, Firebase, Google Sign-In).

##### Analyzing the File Structure
- Top-Level Directories:
– The “android” and “ios” directories contain platform-specific configurations and native wrappers (with build scripts, Gradle settings, Fastlane for deployment, and Xcode projects).
– The “lib” directory is the heart of the Flutter codebase. It is subdivided into various feature modules: analytics, auth, data, notifications, payments, routes, theme, ui (with further subdirectories for pages and widgets), and more.
– Additional folders like “assets” (for images, fonts, and animations) and configuration files (pubspec.yaml, pubspec.lock, analysis_options.yaml) round out the project.
- Architectural Clues:
– The use of “Provider” in multiple directories and data modules indicates that state management is handled via the Provider pattern.
– A modular structure is apparent (authentication, data fetching, notifications, theming) which hints at separation of concerns.
– There are also industry-standard integrations (Firebase services, Google Ads, local notifications, in-app payments) reflective of common mobile app practices.

##### Key Components & Their Interactions

A. User Interface (UI) Layer
- UI Pages: Located in lib/ui/pages – different pages such as Home, Search, Profile, Setup, Upload, etc.
- UI Widgets: Individual components (for animations, buttons, menus, popups) in subdirectories like lib/ui/widgets.
- Navigation: The routing system in lib/routes that defines app navigation routes and routing constants.

B. Business Logic & State Management
- Providers: Numerous “provider” modules in directories under lib/data (for ads, categories, collections, notifications, etc.) and in global directories; these manage app state and data updates.
- Services: Analytics (lib/analytics), Logger (lib/logger) and Notification services (both local notifications and Firebase messaging).
- Theme & Config: Theme configuration, dark mode, and custom widget behavior (lib/theme).

C. Data Layer & Integrations
- External Data Sources: Modules for fetching data from WallHaven and Pexels (lib/data/wallhaven and lib/data/pexels) as well as user profile and setups.
- Cloud & Local Storage: Firebase integration (Cloud Firestore, Firebase Analytics, etc.), caching with Hive (in pubspec dependencies) and local storage for caching images.
- Authentication: The user sign-in and authentication flow (lib/auth with google_auth.dart and various user models).
- Payment & Ads: Integration for payments (using RevenueCat through purchases_flutter) and Google Mobile Ads for rewarded video ads.

D. Platform & Build Infrastructure
- CI/CD Pipelines: The workflows and scripts under the .github directory for continuous integration and deployment.

##### Architectural Patterns & Design Principles
- Layered Architecture: Separate presentation (UI), business logic/state management (Provider and services), and data (API calls, local storage).
- Modular Design: The clear separation of concerns across directories (auth, data, routes, theme, notifications) supports easier testing, maintenance, and scalability.
- Provider Pattern: A central pattern used throughout for state management and dependency injection.
- Integration with External APIs/Services: Emphasize connections to third-party APIs (WallHaven, Pexels, Firebase).

- At the top, show the “User Interface” layer that includes screens (Home, Profile, Upload, etc.).
- Further below, map out the “Data & Integration” layer, highlighting components for fetching wallpapers from WallHaven and Pexels, caching (Hive), Firebase interactions, authentication, and payment services.
– Data flow: From the Data Layer to State Management and eventually to the UI.
– Dependencies: For example, external services (Firebase, third-party APIs) influencing both the Data and Auth layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI_Pages["UI Pages"]:::ui
        UI_Widgets["UI Widgets"]:::ui
        UI_Navigation["Navigation/Routing"]:::ui
    end

    %% Business Logic & State Management
    subgraph "Business Logic & State Management"
        Providers["Providers (State Management)"]:::business
        Analytics["Analytics Service"]:::business
        Logger["Logger Service"]:::business
        Notifications["Notification Services"]:::business
        Theme["Theme & Configuration"]:::business
    end

    %% Data Layer & Integrations
    subgraph "Data Layer & Integrations"
        External_WH["External Data Source: WallHaven"]:::data
        External_PX["External Data Source: Pexels"]:::data
        Authentication["Authentication"]:::data
        PaymentAds["Payment & Ads"]:::data
    end

    %% Platform & Build Infrastructure
    subgraph "Platform & Build Infrastructure"
        Android["Native Android Wrappers"]:::platform
        iOS["Native iOS Wrappers"]:::platform
        CI_CD["CI/CD Pipelines"]:::platform
    end

    %% Connections: Data Layer to Business Logic
    External_WH -->|"provides_data"| Providers
    External_PX -->|"provides_data"| Providers
    Authentication -->|"authenticates"| Providers
    PaymentAds -->|"provides_payments"| Providers

    %% Business Logic internal dependencies
    Analytics -->|"supplies_info"| Providers
    Logger -->|"logs_to"| Providers
    Notifications -->|"triggers"| Providers
    Theme -->|"configures"| Providers

    %% Connections: Business Logic to UI Layer
    Providers -->|"updates"| UI_Pages
    Providers -->|"updates"| UI_Widgets
    UI_Navigation -->|"navigates"| UI_Pages

    %% Deployment and Platform
    UI_Pages -->|"deployed_on"| Android
    UI_Pages -->|"deployed_on"| iOS
    CI_CD -->|"builds_and_deploys"| Android
    CI_CD -->|"builds_and_deploys"| iOS

    %% Styles
    classDef ui fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef business fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#8a6d3b,stroke-width:2px;
    classDef platform fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events
    click UI_Pages "https://github.com/hash-studios/prism/tree/master/lib/ui/pages"
    click UI_Widgets "https://github.com/hash-studios/prism/tree/master/lib/ui/widgets"
    click UI_Navigation "https://github.com/hash-studios/prism/tree/master/lib/routes"
    click Providers "https://github.com/hash-studios/prism/tree/master/lib/data"
    click Analytics "https://github.com/hash-studios/prism/blob/master/lib/analytics/analytics_service.dart"
    click Logger "https://github.com/hash-studios/prism/blob/master/lib/logger/logger.dart"
    click Notifications "https://github.com/hash-studios/prism/blob/master/lib/notifications/localNotification.dart"
    click Theme "https://github.com/hash-studios/prism/tree/master/lib/theme"
    click External_WH "https://github.com/hash-studios/prism/tree/master/lib/data/wallhaven"
    click External_PX "https://github.com/hash-studios/prism/tree/master/lib/data/pexels"
    click Authentication "https://github.com/hash-studios/prism/tree/master/lib/auth"
    click PaymentAds "https://github.com/hash-studios/prism/tree/master/lib/payments"
    click Android "https://github.com/hash-studios/prism/tree/master/android"
    click iOS "https://github.com/hash-studios/prism/tree/master/ios"
    click CI_CD "https://github.com/hash-studios/prism/tree/master/.github/workflows"
```
