# mitchkoko/moonbase-template architecture

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

- Interactive diagram: https://gitdiagram.com/mitchkoko/moonbase-template
- Repository: https://github.com/mitchkoko/moonbase-template

## Overview

##### Project type and purpose
- This is a cross-platform Flutter social media template (“Moonbase”) supporting Android, iOS, Web, Windows, macOS, and Linux.
- It implements authentication (email, Google, Apple via Firebase Auth), a Firestore-backed posts/comments feed, content moderation, user blocking, and subscription monetization via RevenueCat.
- It follows a Clean Architecture / BLoC (Cubit) pattern, with distinct domain, data, and presentation layers.

##### File structure
- Top-level directories for each target platform (android, ios, web, windows, macos, linux) plus the core Dart code under `lib/`.
- Under `lib/features/...` each feature is organized into three sub-folders:
- data: concrete Firebase or RevenueCat implementations
- domain: pure entities and repository interfaces
- presentation: UI Widgets, Cubits, and Pages
- A global `lib/themes/`, `lib/components/`, and `main.dart` for app entry and theming.
- Config files: `pubspec.yaml`, Firebase initialization in `main.dart`, and build scripts in each platform folder.

##### README for additional insights
- Tech stack: Flutter/Dart, Firebase Auth & Firestore, RevenueCat.
- Architectural pattern: Clean Architecture + BLoC with Cubits.
- Usage: follow instructions to set up Firebase, run `flutter pub get`, then `flutter run`.

##### Components
a. Main components
- Frontend (Flutter UI)
- State Management (BLoC/Cubit layer)
- Domain Layer (Entities & Repository Interfaces)
- Data Layer (Firebase Services & RevenueCat Service)
- External Services (Firebase Auth, Firestore, RevenueCat, Google Sign-In, Apple Sign-In)
- Platforms (Android, iOS, Web, Desktop)
b. Relationships and interactions
- UI widgets dispatch events to Cubits.
- Cubits call domain-level repository interfaces.
- Data layer implements those interfaces, talking to Firebase or RevenueCat SDKs.
- External services persist and retrieve data (e.g., Firestore reads/writes posts/comments).
- RevenueCat handles subscription purchases and provides offerings data.
c. Architectural patterns and principles
- Clean Architecture layered separation (Presentation → Domain → Data → External).
- Dependency inversion: presentation depends on domain interfaces; data layer depends on those interfaces.
- BLoC/Cubit for unidirectional data flow.
- Repository pattern to abstract external APIs.
d. Key technologies and libraries
- Flutter framework (Widgets, runApp)
- flutter_bloc / Cubit for state management
- firebase_auth, cloud_firestore for backend
- revenuecat_flutter (or custom service wrapper)
- google_sign_in, sign_in_with_apple

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Platforms
    subgraph "Platforms"
        Android[Android]:::platform
        iOS[iOS]:::platform
        Web[Web]:::platform
        macOS[macOS]:::platform
        Windows[Windows]:::platform
        Linux[Linux]:::platform
    end

    %% Flutter Engine and Layers
    subgraph "Flutter Engine"
        %% Presentation Layer
        subgraph "Presentation Layer"
            UIAuth["Auth UI"]:::presentation
            UIHome["Home UI"]:::presentation
            UIMod["Moderation UI"]:::presentation
            UIProfile["Profile Page"]:::presentation
            UISettings["Settings UI"]:::presentation
            UISub["Subscriptions UI"]:::presentation
            Components["Shared Components"]:::presentation
            Themes["Themes"]:::presentation
            MainApp["main.dart"]:::presentation
        end

        %% State Management
        subgraph "State Management"
            AuthCubit["AuthCubit"]:::stateMgmt
            PostCubit["PostCubit"]:::stateMgmt
            ModCubit["ModerationCubit"]:::stateMgmt
            OfferingsCubit["OfferingsCubit"]:::stateMgmt
            SubCubit["SubscriptionCubit"]:::stateMgmt
        end

        %% Domain Layer
        subgraph "Domain Layer"
            AppUser["AppUser Entity"]:::domain
            AuthRepoI["AuthRepo Interface"]:::domain
            PostEnt["Post Entity"]:::domain
            CommentEnt["Comment Entity"]:::domain
            PostRepoI["PostRepo Interface"]:::domain
            BlockedEnt["BlockedUser Entity"]:::domain
            ModRepoI["ModerationRepo Interface"]:::domain
        end

        %% Data Layer
        subgraph "Data Layer"
            FBAuthRepo["FirebaseAuthRepo"]:::data
            FBPostRepo["FirebasePostRepo"]:::data
            FBModRepo["FirebaseModerationRepo"]:::data
            RCConstants["RevenueCat Constants"]:::data
            RCService["RevenueCat Service"]:::data
        end

        %% External Services
        subgraph "External Services"
            FirebaseAuth["Firebase Auth"]:::external
            Firestore["Firestore"]:::external
            RevenueCat["RevenueCat"]:::external
            GoogleSignIn["Google Sign-In"]:::external
            AppleSignIn["Apple Sign-In"]:::external
        end
    end

    %% Connections
    Android --> MainApp
    iOS --> MainApp
    Web --> MainApp
    macOS --> MainApp
    Windows --> MainApp
    Linux --> MainApp

    MainApp --> UIAuth
    MainApp --> UIHome
    MainApp --> UIMod
    MainApp --> UIProfile
    MainApp --> UISettings
    MainApp --> UISub
    MainApp --> Components
    MainApp --> Themes

    UIAuth --> AuthCubit
    UIHome --> PostCubit
    UIMod --> ModCubit
    UISub --> OfferingsCubit
    UISub --> SubCubit

    AuthCubit --> AuthRepoI
    PostCubit --> PostRepoI
    ModCubit --> ModRepoI
    OfferingsCubit --> RCService
    SubCubit --> RCService

    AuthRepoI --> FBAuthRepo
    PostRepoI --> FBPostRepo
    ModRepoI --> FBModRepo

    FBAuthRepo --> FirebaseAuth
    FBAuthRepo --> GoogleSignIn
    FBAuthRepo --> AppleSignIn

    FBPostRepo --> Firestore
    FBModRepo --> Firestore

    RCService --> RevenueCat

    %% Click Events
    click UIAuth "https://github.com/mitchkoko/moonbase-template/tree/main/lib/features/auth/presentation"
    click UIHome "https://github.com/mitchkoko/moonbase-template/tree/main/lib/features/home/presentation"
    click UIMod "https://github.com/mitchkoko/moonbase-template/tree/main/lib/features/moderation/presentation"
    click UIProfile "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/profile/profile_page.dart"
    click UISettings "https://github.com/mitchkoko/moonbase-template/tree/main/lib/features/settings/presentation"
    click UISub "https://github.com/mitchkoko/moonbase-template/tree/main/lib/features/subscriptions/presentation"
    click Components "https://github.com/mitchkoko/moonbase-template/tree/main/lib/components"
    click Themes "https://github.com/mitchkoko/moonbase-template/tree/main/lib/themes"
    click MainApp "https://github.com/mitchkoko/moonbase-template/blob/main/lib/main.dart"

    click AuthCubit "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/auth/presentation/cubits/auth_cubit.dart"
    click PostCubit "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/home/presentation/cubits/post_cubit.dart"
    click ModCubit "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/moderation/presentation/cubits/moderation_cubit.dart"
    click OfferingsCubit "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/subscriptions/presentation/cubits/offerings_cubit.dart"
    click SubCubit "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/subscriptions/presentation/cubits/subscription_cubit.dart"

    click AppUser "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/auth/domain/entities/app_user.dart"
    click AuthRepoI "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/auth/domain/repos/auth_repo.dart"
    click PostEnt "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/home/domain/entities/post.dart"
    click CommentEnt "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/home/domain/entities/comment.dart"
    click PostRepoI "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/home/domain/repos/post_repo.dart"
    click BlockedEnt "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/moderation/domain/entities/blocked_user.dart"
    click ModRepoI "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/moderation/domain/repos/moderation_repo.dart"

    click FBAuthRepo "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/auth/data/firebase_auth_repo.dart"
    click FBPostRepo "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/home/data/firebase_post_repo.dart"
    click FBModRepo "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/moderation/data/firebase_moderation_repo.dart"
    click RCConstants "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/subscriptions/data/revenuecat_constants.dart"
    click RCService "https://github.com/mitchkoko/moonbase-template/blob/main/lib/features/subscriptions/data/revenuecat_service.dart"

    %% Styles
    classDef presentation fill:#d0e7ff,stroke:#0366d6,color:#0366d6
    classDef stateMgmt fill:#d4f8d4,stroke:#28a745,color:#28a745
    classDef domain fill:#ffe0b2,stroke:#f39c12,color:#d35400
    classDef data fill:#e8d5f9,stroke:#8e44ad,color:#6f42c1
    classDef external fill:#f0f0f0,stroke:#6c757d,color:#6c757d
    classDef platform fill:#fafafa,stroke:#adb5bd,color:#495057
```
