# paulononaka/flutter_firebase_auth_firestore architecture

> Architecture diagram of the GitHub repository paulononaka/flutter_firebase_auth_firestore, 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/paulononaka/flutter_firebase_auth_firestore
- Repository: https://github.com/paulononaka/flutter_firebase_auth_firestore

## Overview

##### Main components
- Mobile App (Flutter): This includes presentation, business logic, and state management. The Flutter app uses features such as Flutter Bloc for state management, GetIt for dependency injection, Freezed for immutable objects, and integrates with Firebase services (Firebase Authentication, Firestore, and Push Notifications). The source code is structured mainly in the “app/lib” directory (components, pages, design system, models, navigation, network) and supports platform-specific builds for Android and iOS.
- Server Backend: Implemented using NestJS, the server handles logic such as REST calls and push notifications (via Firebase integration) and deals with order management, STI_STD functionality, and cloud functions. This is visible from the “server” folder which contains controllers, services, DTOs, and models.
- Firebase Services: These are used both by the mobile app (e.g., authentication and push notifications) and by the server (to trigger cloud functions / scheduled functions on GCP).
- External Services: Like Google Cloud Functions, REST endpoints, and any external APIs called by the REST client in the Flutter app.

##### File structure and architectural choices
- In the Flutter app:
- The “app/lib” directory clearly separates design system components and tokens (a pattern indicating strong design guidelines).
- There are dedicated directories for different pages and features (like sign in, sign up, home, order, profile, test_details, tests, and welcome); this denotes a decomposed UI/feature-based structure.
- The “di” (dependency injection) directory and “network” (REST client) support modularity and separation of concerns.
- The Flutter project supports different flavors/environments by having “main_prod.dart” and “main_local.dart”.
- In the Server:
- Your server folder follows a modular pattern with feature directories (“orders”, “sti_std”, and “firebase”) and uses a typical NestJS directory layout (controllers, services, modules).
- Configuration files like “tsconfig.json” and “nest-cli.json” define build and run parameters for the backend.

##### Important architectural notes to capture
- Separation of concerns – the mobile app handles presentation and user interactions (front-end) while the backend manages business logic, data processing, and external integrations.
- Use of Flutter Bloc and dependency injection, showing how state flows and data flows from user interactions to backend calls.
- For the server, note that NestJS’s modular architecture (controllers and services) ensures clear boundaries and testability.

##### Final assembly
User Interaction → Flutter App (UI and Business Logic via Bloc) → REST Client → Server (NestJS Modules)
Additionally, show side connections between Flutter App and Firebase for direct integrations, while the Server may also interact with Firebase for tasks like push notifications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile App Section
    subgraph "Mobile App (Flutter)"
        direction TB
        MA["Flutter App Core"]:::mobile
        UI["UI/Pages Components"]:::mobile
        SM["State Management (Flutter Bloc)"]:::mobile
        DI["Dependency Injection (GetIt)"]:::mobile
        DS["Reusable Design Components"]:::mobile
        RC["REST Client Integration"]:::mobile
        FI["Firebase Integration (Mobile)"]:::mobile
        AND["Platform Specific Build (Android)"]:::mobile
        IOS["Platform Specific Build (iOS)"]:::mobile
    end

    %% Server Backend Section
    subgraph "Server Backend (NestJS)"
        direction TB
        NS["NestJS Core & Entry Points"]:::server
        OM["Order Management Module"]:::server
        STI["STI_STD Module"]:::server
        SFI["Firebase Integration (Server)"]:::server
        CONF["Configuration & Build Settings"]:::server
    end

    %% External Services Section
    subgraph "External Services"
        direction TB
        FB["Firebase Services (Auth, Firestore, Push)"]:::external
        EXT["External REST_API/Cloud_Functions"]:::external
    end

    %% Mobile App Internal Connections
    MA --> UI
    UI --> SM
    DI --> SM
    DS --> UI
    SM --> RC
    RC --> FI
    FI -- "connects_to" --> FB
    AND --> MA
    IOS --> MA

    %% Communication between Mobile App and Server Backend
    RC -- "REST_API_calls" --> NS

    %% Server Backend Internal Structure
    NS --> OM
    NS --> STI
    NS --> SFI
    CONF --> NS
    SFI -- "sends_notifications" --> FB
    NS -- "integrates_with" --> EXT

    %% Click Events for Mobile App
    click MA "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/app/lib/app.dart"
    click UI "https://github.com/paulononaka/flutter_firebase_auth_firestore/tree/main/app/lib/pages"
    click SM "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/app/lib/pages/home/home_bloc.dart"
    click DI "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/app/lib/di/container.dart"
    click DS "https://github.com/paulononaka/flutter_firebase_auth_firestore/tree/main/app/lib/design_system"
    click RC "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/app/lib/network/rest_client.dart"
    click FI "https://github.com/paulononaka/flutter_firebase_auth_firestore/tree/main/app/lib/firebase"
    click AND "https://github.com/paulononaka/flutter_firebase_auth_firestore/tree/main/app/android"
    click IOS "https://github.com/paulononaka/flutter_firebase_auth_firestore/tree/main/app/ios"

    %% Click Events for Server Backend
    click NS "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/server/src/app.module.ts"
    click OM "https://github.com/paulononaka/flutter_firebase_auth_firestore/tree/main/server/src/orders"
    click STI "https://github.com/paulononaka/flutter_firebase_auth_firestore/tree/main/server/src/sti_std"
    click SFI "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/server/src/firebase/push_notification.ts"
    click CONF "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/server/nest-cli.json"

    %% Click Event for External/Firebase
    click FB "https://github.com/paulononaka/flutter_firebase_auth_firestore/blob/main/firebase.json"

    %% Class Definitions for Colors
    classDef mobile fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef server fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
```
