# htsuruo/nippo architecture

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

- Interactive diagram: https://gitdiagram.com/htsuruo/nippo
- Repository: https://github.com/htsuruo/nippo

## Overview

##### Main Components
- Clients: Represent all the Flutter client applications (i.e., Android, iOS, macOS, and Web) as separate nodes or grouped under “Flutter Client.”
- Flutter Business Logic and Presentation: Within the Flutter app, include layers such as:
– UI/Widgets (organized under lib/common and lib/features)
– Navigation and Routing (lib/core/router)
– State Management / Providers (auth_provider, post_provider, user_provider)
– Domain-specific modules (posts, user, setting, sign-in)
- Firebase Backend:
– Authentication: Managed via Google Sign-In.
– Firestore Database: For storing day reports (日報) and user information.
– Cloud Functions: Contains server-side scripts (in firebase/functions) for business logic, extended functionalities, and admin operations.
– Firebase App Check & Security: Security rules in Firestore (firestore.rules) and API key restrictions.
– Firebase Hosting: Serves web content (from firebase/public).
- External Tools:
– FlutterFire CLI: Used for Firebase configuration.
– Other CI/CD integrations such as GitHub workflows (e.g., flutter.yml) and testing setups (e.g., rules tests under firebase/functions/src/test).

##### Relationships and Data Flow
- Interactions between the Flutter Business Logic components and the Firebase services (e.g., state changes trigger authentication calls, post submission calls Cloud Functions, and read/write to Firestore).
- Firebase App Check and Security Rules to the Cloud API endpoints to indicate that requests are validated and secured.
- Integration with Cloud Functions where specific triggers (like post creation or deletion) invoke server-side scripts.

##### Architectural Patterns & Principles
- Separation of Concerns: Clearly demarcate the client-side presentation (UI and state management) from business logic and backend services.
- Modular Design: Note that the lib folder is divided into features (post, user, sign-in, setting) which allows logical separation and potentially easier scalability.
- Security by Design: Emphasize that API requests are secured both at the client (via App Check) and at the database level (via detailed security rules).

##### Relevant Technologies, Frameworks, and Tools
- Flutter: The primary UI framework used for building the client apps.
- Firebase: Provides Authentication, Cloud Firestore, Cloud Functions, and App Check.
- GitHub Actions: For continuous integration/deployment (automated tests and builds).
- Flutterfire CLI: For Firebase integration and setup.
- The use of generated code (like .g.dart files) indicates code generation for models and providers.

##### Elements
– From Flutter client to Authentication (for login/sign-in).
– From Flutter client to Cloud Firestore (for retrieving and updating day reports).
– From Flutter client to Cloud Functions if any server-side processing is needed.
- Annotations or labels that indicate key functionalities (for example, “Google Sign-In,” “App Check Verification,” etc.).

##### Final Steps
- Sketch out the high-level flow first, ensuring every component is included.
- Keep the design both comprehensive (abstracted high-level view) and detailed enough so that other team members can quickly understand the overall architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flutter Client Applications
    subgraph "Flutter Client Applications"
        A("Android App"):::client
        B("iOS App"):::client
        C("macOS App"):::client
        D("Web App"):::client
    end

    %% Flutter Business Logic & Presentation
    subgraph "Flutter Business Logic & Presentation"
        E("Core Business Logic"):::business
        F("Feature Modules"):::business
    end

    %% Firebase Backend
    subgraph "Firebase Backend"
        G("Firebase Authentication<br/>(Google Sign-In)"):::firebase
        H("Cloud Firestore<br/>(Day Reports & User Data)"):::firebase
        I("Cloud Functions<br/>(Server-Side Logic)"):::firebase
        J("Firebase App Check & Security"):::firebase
        K("Firebase Hosting<br/>(Web Content)"):::firebase
    end

    %% External Tools & Integrations
    subgraph "External Tools"
        L("CI/CD Integrations<br/>(GitHub Workflows)"):::external
        M("FlutterFire CLI Integration"):::external
    end

    %% Data Flow Connections
    %% Client Applications to Business Logic
    A -->|"UI/State"&nbsp;| E
    B -->|"UI/State"&nbsp;| E
    C -->|"UI/State"&nbsp;| E
    D -->|"UI/State"&nbsp;| E

    %% Business Logic Interactions
    E -->|"AuthRequest"| G
    E -->|"DataQuery/Update"| H
    E -->|"ServerCall"| I
    F -->|"Feature-Specific Logic"| E

    %% Security validations
    J ---|"Secures"| G
    J ---|"Secures"| H
    J ---|"Secures"| I

    %% External Tools integration
    M -->|"Configures"| G
    L -->|"Deploys/Test"| I
    L -->|"Deploys/Test"| K

    %% Client directly accessing Firebase (e.g., App Check, Hosting)
    D -->|"Web API Calls"| K

    %% Styling Classes
    classDef client fill:#B3E5FC,stroke:#039BE5,stroke-width:2px;
    classDef business fill:#DCEDC8,stroke:#689F38,stroke-width:2px;
    classDef firebase fill:#FFCDD2,stroke:#D32F2F,stroke-width:2px;
    classDef external fill:#FFE082,stroke:#FFA000,stroke-width:2px;

    %% Click Events
    click A "https://github.com/htsuruo/nippo/tree/main/android"
    click B "https://github.com/htsuruo/nippo/tree/main/ios/Runner"
    click C "https://github.com/htsuruo/nippo/tree/main/macos/Runner"
    click D "https://github.com/htsuruo/nippo/blob/main/web/index.html"
    click E "https://github.com/htsuruo/nippo/blob/main/lib/app.dart"
    click F "https://github.com/htsuruo/nippo/tree/main/lib/features"
    click G "https://github.com/htsuruo/nippo/tree/main/lib/core/authentication"
    click H "https://github.com/htsuruo/nippo/blob/main/firebase/firestore.rules"
    click I "https://github.com/htsuruo/nippo/tree/main/firebase/functions"
    click J "https://github.com/htsuruo/nippo/blob/main/firebase/firestore.rules"
    click K "https://github.com/htsuruo/nippo/tree/main/firebase/public"
    click L "https://github.com/htsuruo/nippo/tree/main/.github/workflows"
    click M "https://github.com/htsuruo/nippo/blob/main/lib/firebase_options.dart"
```
