# huanglinbao/kid_sec architecture

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

- Interactive diagram: https://gitdiagram.com/huanglinbao/kid_sec
- Repository: https://github.com/huanglinbao/kid_sec

## Overview

##### Project type and purpose
- This is a full-stack mobile application (“kid_sec”) for parental control.
- The client is a cross-platform Flutter app with native Android (Kotlin) and iOS (Swift) integrations.
- The backend is a Node.js REST API, persisting data in MongoDB, sending push notifications via Firebase Cloud Messaging, and rendering maps via MapBox.

##### File structure
- Top level: “android/”, “ios/” (platform-specific native code and manifests), “lib/” (Flutter/Dart UI + business logic), “assets/” (static JSON and images), “test/” (widget tests).
- “android/app/src/main/kotlin/com/example/kid_sec/MainActivity.kt” implements platform channels to bridge Flutter ↔ native Android for OS-level permissions.
- “lib/screens/” contains UI screens (login, parent home, child home, etc.).
- “lib/widgets/”, “lib/core/”, “lib/utils/” subdivide reusable components, constants, and helpers.
- “pubspec.yaml” lists Flutter dependencies (including firebase_messaging, mapbox_gl, etc.).

##### README for additional insights
- Flutter provides the cross-platform UI.
- Kotlin handles Android permissions via platform channels.
- Node.js and MongoDB serve as the backend API and data store.
- Firebase is used exclusively for push notifications.
- MapBox SDK is used for in-app maps (e.g., child location tracking).

##### Detail
– Split the client into sub-components: UI screens, widget library, network service, platform channel plugin.
– Split the server into API layer, business logic, data access layer.
– Explicitly show data flows: user login flows to Auth API, parent config flows to Settings API, child location polling to Location API → MapBox.
– Show error-handling or retry flows if relevant (e.g., fallback when MapBox is unreachable).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Client Layer
    subgraph "Mobile Client"
        direction TB
        Main["Main Entry Point (lib/main.dart)"]:::client
        UI["UI Screens (lib/screens/)"]:::client
        Widgets["Widget Library (lib/widgets/)"]:::client
        Core["Core Constants & Styles (lib/core/constants/)"]:::client
        Utils["Utility & Helpers (lib/utils/)"]:::client
        Net["Network Service"]:::client
        MapWidget["MapBox Widget (lib/widgets/map.dart)"]:::client
        Pubspec["pubspec.yaml"]:::client

        subgraph "Android Platform Bridge"
            direction TB
            BridgeAndroid["Android Bridge (MainActivity.kt)"]:::client
            ConfigAndroid["Android Config (AndroidManifest.xml, build.gradle)"]:::client
            ResAndroid["Android Resources (res/)"]:::client
        end

        subgraph "iOS Platform Bridge"
            direction TB
            BridgeiOSSwift["iOS Bridge (AppDelegate.swift)"]:::client
            BridgeiOSHeader["Runner-Bridging-Header.h"]:::client
            ConfigiOS["iOS Config (Runner.xcodeproj/, Info.plist, Base.lproj/)"]:::client
        end

        subgraph "Static Assets"
            direction TB
            JSON["JSON Assets (assets/JSON/)"]:::client
            Images["Image Assets (assets/images/)"]:::client
        end
    end

    %% Backend Services Layer
    subgraph "Backend Services"
        direction TB
        API["Node.js REST API"]:::backend
        Controllers["Controllers & Services"]:::backend
        DAL["Data Access Layer"]:::backend
        MongoDB["MongoDB Atlas"]:::db
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        Firebase["Firebase Cloud Messaging"]:::external
        MapBox["MapBox API"]:::external
    end

    %% Connections
    Main --> UI
    Main --> Widgets
    Main --> Core
    Main --> Utils
    Main --> Net
    Main --> Pubspec

    UI --> Net
    Widgets --> UI
    Core --> UI
    Utils --> Net

    Net -->|HTTPS| API
    API --> Controllers
    Controllers --> DAL
    DAL --> MongoDB

    API -->|FCM REST| Firebase
    Firebase -->|Push Notification| Main

    MapWidget -->|MapTile Request| MapBox
    MapBox -->|Map Data| MapWidget

    UI --> BridgeAndroid
    BridgeAndroid --> ConfigAndroid
    BridgeAndroid --> ResAndroid
    UI --> BridgeiOSSwift
    UI --> BridgeiOSHeader
    BridgeiOSSwift --> ConfigiOS
    BridgeiOSHeader --> ConfigiOS

    %% Click Events
    click UI "https://github.com/huanglinbao/kid_sec/tree/main/lib/screens/"
    click Widgets "https://github.com/huanglinbao/kid_sec/tree/main/lib/widgets/"
    click Core "https://github.com/huanglinbao/kid_sec/tree/main/lib/core/constants/"
    click Utils "https://github.com/huanglinbao/kid_sec/tree/main/lib/utils/"
    click Main "https://github.com/huanglinbao/kid_sec/blob/main/lib/main.dart"
    click MapWidget "https://github.com/huanglinbao/kid_sec/blob/main/lib/widgets/map.dart"
    click Pubspec "https://github.com/huanglinbao/kid_sec/blob/main/pubspec.yaml"
    click BridgeAndroid "https://github.com/huanglinbao/kid_sec/blob/main/android/app/src/main/kotlin/com/example/kid_sec/MainActivity.kt"
    click ConfigAndroid "https://github.com/huanglinbao/kid_sec/blob/main/android/app/src/main/AndroidManifest.xml"
    click ResAndroid "https://github.com/huanglinbao/kid_sec/tree/main/android/app/src/main/res/"
    click BridgeiOSSwift "https://github.com/huanglinbao/kid_sec/blob/main/ios/Runner/AppDelegate.swift"
    click BridgeiOSHeader "https://github.com/huanglinbao/kid_sec/blob/main/ios/Runner/Runner-Bridging-Header.h"
    click ConfigiOS "https://github.com/huanglinbao/kid_sec/tree/main/ios/Runner.xcodeproj/"

    %% Styles
    classDef client fill:#E3F2FD,stroke:#2196F3,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#4CAF50,stroke-width:1px
    classDef db fill:#FFF9C4,stroke:#FBC02D,stroke-width:1px
    classDef external fill:#FFF3E0,stroke:#FB8C00,stroke-width:1px
```
