# googlecreativelab/teachablemachine-community architecture

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

- Interactive diagram: https://gitdiagram.com/googlecreativelab/teachablemachine-community
- Repository: https://github.com/googlecreativelab/teachablemachine-community

## Overview

- A libraries section with machine learning code (for image, pose, and audio) built primarily on TensorFlow.js.
- A snippets section that delivers downloadable code templates, markdown documentation, and instructions for integrating models (including converter examples for various environments).

##### Core Components
a. Libraries:
- Image Library – Contains modules like custom-mobilenet.ts, teachable-mobilenet.ts and utilities (canvas handling, TensorFlow wrappers, webcam management). It includes build configurations (webpack.config.js, tsconfig.json) and tests.
- Pose Library – Similar in structure to the image library but includes custom-posenet.ts, teachable-posenet.ts, and utilities for drawing pose data.
- Audio Library – Although the file tree shows fewer details for audio (just a README and a Dockerfile), recognize it as the third machine learning modality.

b. Snippets:
- Documentation and Code Samples – In markdown, offering deployment examples, converter code for different platforms (audio, image, tiny variants), and even integration examples in other languages.
- Converter Subcomponent – Shows usage examples for Docker deployments, API integrations (with Python code, docker-compose configurations), and even Arduino/C++ examples (for tiny image models).

c. (Secondary) Meta / DevOps Components:
- Configuration files like cloudbuild.yaml for automated builds.
- Dockerfiles and deployment scripts inside both libraries and snippets, indicating a containerized and CI/CD-aware environment.
- GitHub issue templates and contribution guidelines to aid community involvement.

##### Out the Relationships and Data Flow
a. At the highest level, position two major blocks:
– The Machine Learning Libraries (which are the engines that train and run models using TensorFlow.js)
– The Snippets/Converter Section (which shows how to export and integrate these models in various environments and languages).

b. Blocks to show that the libraries generate models (and provide APIs for them) that are “used” by the code examples in the snippets.
– The Libraries feed outputs (trained models, code artifacts) that the Snippets demonstrate integration for.
– There could be interactions between the development workflows (e.g., build, test and deploy cycles) and both libraries and snippets.
d. Optionally, include external entities such as the TensorFlow.js framework as a dependency for both image and pose libraries.

##### Architectural Patterns and Design Principles
a. Modularization: Note that each machine learning modality (image, pose, audio) is encapsulated in its own library with separate source, utility, and test folders.
b. Component Reuse: The tools and utilities (e.g., canvas, webcam management) are reused across libraries. This is an indication of DRY design.
c. Platform Agnosticity: The snippets not only provide JavaScript examples but also cover multiple languages and deployment environments (e.g., Docker setups, mobile integration).

##### Additional Details
a. Underlying technology choices, such as:
– TensorFlow.js (core ML engine)
– TypeScript (evident from tsconfig.json and tslint.json)
– Webpack configurations for bundling
– Docker for containerized deployment (especially in snippets)

##### Final Recommendations
a. Clearly label every component with its purpose.
– Machine Learning core libraries (image, pose, audio)
– Documentation and integration (snippets, converters)
– Deployment/DevOps artifacts (Docker, cloudbuild files)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Dependencies
    subgraph "External Dependencies"
        TF["TensorFlow.js"]:::external
        TS["TypeScript & Webpack"]:::external
    end

    %% Machine Learning Libraries Subgraph
    subgraph "Machine Learning Libraries"
        %% Image Library
        subgraph "Image Library"
            IMAGE_LIB["Image Library"]:::libraryMain
            I1["custom-mobilenet.ts"]:::librarySub
            I2["teachable-mobilenet.ts"]:::librarySub
            I3["utils: canvas.ts"]:::librarySub
            I4["utils: tf.ts"]:::librarySub
            I5["utils: webcam.ts"]:::librarySub
            IMAGE_LIB --> I1
            IMAGE_LIB --> I2
            IMAGE_LIB --> I3
            IMAGE_LIB --> I4
            IMAGE_LIB --> I5
        end

        %% Pose Library
        subgraph "Pose Library"
            POSE_LIB["Pose Library"]:::libraryMain
            P1["custom-posenet.ts"]:::librarySub
            P2["teachable-posenet.ts"]:::librarySub
            P3["utils: canvas.ts"]:::librarySub
            P4["utils: pose-draw.ts"]:::librarySub
            P5["utils: webcam.ts"]:::librarySub
            POSE_LIB --> P1
            POSE_LIB --> P2
            POSE_LIB --> P3
            POSE_LIB --> P4
            POSE_LIB --> P5
        end

        %% Audio Library
        subgraph "Audio Library"
            AUDIO_LIB["Audio Library"]:::libraryMain
            A_RD["README.md & Dockerfile"]:::librarySub
            AUDIO_LIB --> A_RD
        end
    end

    %% Model Artifacts (output from ML Libraries)
    ModelArtifacts["Model Artifacts"]:::model

    %% Snippets and Integration Subgraph
    subgraph "Snippets and Integration"
        SNIPPETS["Snippets"]:::snippetMain
        DCS["Documentation & Code Samples"]:::snippetSub
        CONV["Converter Subcomponent"]:::snippetSub
        SNIPPETS --> DCS
        SNIPPETS --> CONV
    end

    %% Meta / DevOps Subgraph
    subgraph "Meta / DevOps"
        DEVOPS["Meta/DevOps"]:::devopsMain
        DEVOPS_CONFIG["Cloud Build & Docker Configurations"]:::devopsSub
        DEVOPS_GUIDE["Contribution Guidelines & Issue Templates"]:::devopsSub
        DEVOPS --> DEVOPS_CONFIG
        DEVOPS --> DEVOPS_GUIDE
    end

    %% Connecting Dependencies to ML Libraries
    TF --> IMAGE_LIB
    TF --> POSE_LIB
    TS --> IMAGE_LIB
    TS --> POSE_LIB
    TS --> AUDIO_LIB

    %% Aggregating Model Outputs from ML Libraries
    IMAGE_LIB --> ModelArtifacts
    POSE_LIB --> ModelArtifacts
    AUDIO_LIB --> ModelArtifacts

    %% Libraries feed Model Artifacts to Snippets for integration
    ModelArtifacts --> SNIPPETS

    %% DevOps interacts with both Libraries and Snippets
    DEVOPS_CONFIG --- IMAGE_LIB
    DEVOPS_CONFIG --- POSE_LIB
    DEVOPS_CONFIG --- AUDIO_LIB
    DEVOPS_CONFIG --- SNIPPETS

    %% Click Events for Library Components
    click IMAGE_LIB "https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image/"
    click I1 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/image/src/custom-mobilenet.ts"
    click I2 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/image/src/teachable-mobilenet.ts"
    click I3 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/image/src/utils/canvas.ts"
    click I4 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/image/src/utils/tf.ts"
    click I5 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/image/src/utils/webcam.ts"

    click POSE_LIB "https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/pose/"
    click P1 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/pose/src/custom-posenet.ts"
    click P2 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/pose/src/teachable-posenet.ts"
    click P3 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/pose/src/utils/canvas.ts"
    click P4 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/pose/src/utils/pose-draw.ts"
    click P5 "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/pose/src/utils/webcam.ts"

    click AUDIO_LIB "https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/audio/"
    click A_RD "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/audio/README.md"

    %% Click Events for Snippets Components
    click DCS "https://github.com/googlecreativelab/teachablemachine-community/tree/master/snippets/markdown/"
    click CONV "https://github.com/googlecreativelab/teachablemachine-community/tree/master/snippets/converter/"

    %% Click Events for Meta/DevOps Components
    click DEVOPS_CONFIG "https://github.com/googlecreativelab/teachablemachine-community/blob/master/libraries/cloudbuild.yaml"
    click DEVOPS_GUIDE "https://github.com/googlecreativelab/teachablemachine-community/blob/master/CONTRIBUTE.md"

    %% Class Definitions for Styling
    classDef libraryMain fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef librarySub fill:#b0e0e6,stroke:#000,stroke-width:1px;
    classDef snippetMain fill:#f0e68c,stroke:#000,stroke-width:1px;
    classDef snippetSub fill:#fafad2,stroke:#000,stroke-width:1px;
    classDef devopsMain fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef devopsSub fill:#e0e0e0,stroke:#000,stroke-width:1px;
    classDef external fill:#ffcccb,stroke:#000,stroke-width:1px;
    classDef model fill:#c8a2c8,stroke:#000,stroke-width:1px;
```
