# thisisantonio/sociolingo architecture

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

## Overview

##### Project Type & Purpose
- This is a full-stack chat application. The frontend is built in Flutter (enabling iOS, Android, Web, Desktop, etc.) while the backend uses Node.js (implemented as Firebase Cloud Functions) to support database management, notifications, and language translation utilizing the OpenAI API.
- The main goals include real-time chat, user registration/authentication via Firebase Auth, data persistence using Firestore, push notifications via Firebase Cloud Messaging (FCM), and AI-powered language translation.

##### File Structure
- At the root, the “chat_app” directory contains all the project artifacts. Notice separate directories for different platform builds (android, ios, macos, linux, windows, and web) – showing that Flutter’s cross-platform capabilities are in use.
- The "lib" folder stores the Dart code including models, UI screens, and services. This is the frontend’s business logic.
- A “functions” directory exists at the same level as the Flutter code. This Node.js folder contains the backend API code (with ESLint config, package.json, and index.js) that implements the server-side functionality, including integration with the OpenAI API for language translation.
- There are Firebase configuration files (.firebase, firebase.json, .firebaserc) spreading across the project, highlighting heavy reliance on Firebase for authentication, data storage, and messaging.

##### Key Components
- Frontend Client (Flutter Chat Application):
- UI Components and Screens (login, chat, registration, etc.) (located in “lib/screens”).
- Mobile and Web Clients represented by multi-platform builds.
- Local services (theme manager, language and platform detection, etc.).
- Backend Services:
- Firebase Authentication: for user sign-up/sign-in.
- Cloud Firestore: for real-time messages and data storage.
- Firebase Cloud Messaging (FCM): for delivering notifications.
- Cloud Functions (Node.js): This acts as the custom API endpoint layer to handle server-side logic such as interacting with the external OpenAI API for language translation.
- External Services:
- OpenAI API: utilized for AI-powered translation (calls made from Cloud Functions).

##### Relationships & Interactions
- Connection from the Flutter Client to Cloud Firestore to illustrate real-time chat and data persistence.
- A bidirectional flow between Flutter Client and Firebase Cloud Messaging for sending/receiving notifications.
- That Cloud Functions (Node.js API) is invoked by either the Flutter app or via Firestore triggers, and in turn makes HTTP API calls to the external OpenAI service for translation purposes.
- Optionally, include the connection from the client app to Firebase Storage if assets are used, as suggested by the "assets" folder.

##### Architectural Patterns & Design Principles
- Separation of concerns:
- Presentation Layer (Flutter UI)
- Data Layer (Firebase Firestore, Auth, FCM)
- Business Logic/Server-Side Integrations (Cloud Functions, OpenAI translation)
- Modular design: The Node.js functions directory shows that the backend logic is separated from the UI code.
- Real-time data flow: Demonstrate how data is synchronized with Firestore in near real-time.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend - Flutter Client"
        FLUI["UI Screens"]:::frontend
        FLBL["Business Logic & Models"]:::frontend
        FLSVC["Local Services"]:::frontend
        subgraph "Platforms"
            Android["Android"]:::platform
            iOS["iOS"]:::platform
            Web["Web"]:::platform
            Windows["Windows"]:::platform
            Macos["macOS"]:::platform
            Linux["Linux"]:::platform
        end
    end

    subgraph "Backend & Firebase"
        subgraph "Firebase Services"
            FAuth["Firebase Auth"]:::firebase
            FStore["Cloud Firestore"]:::firebase
            FCM["Firebase Cloud Messaging"]:::firebase
            FConfig["Firebase Configuration"]:::firebase
        end
        subgraph "Cloud Functions (Node.js API)"
            CFS["Cloud Functions"]:::backend
        end
    end

    OAI["OpenAI API (Language Translation)"]:::external

    %% Connections from Flutter Client to Firebase Services and Cloud Functions
    FLUI -->|"register&login"| FAuth
    FLUI -->|"sendMessages"| FStore
    FCM <-->|"notify"| FLUI
    FLUI -->|"translateText"| CFS

    %% Additional trigger from Firestore to Cloud Functions
    FStore -->|"trigger"| CFS

    %% Cloud Functions calling External OpenAI API
    CFS -->|"calls"| OAI

    %% Click Events for Flutter Client Components
    click FLUI "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/lib/screens"
    click FLBL "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/lib/model"
    click FLSVC "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/lib/services"
    click Android "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/android"
    click iOS "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/ios"
    click Web "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/web"
    click Windows "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/windows"
    click Macos "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/macos"
    click Linux "https://github.com/thisisantonio/sociolingo/tree/main/chat_app/linux"

    %% Click Event for Cloud Functions
    click CFS "https://github.com/thisisantonio/sociolingo/blob/main/chat_app/functions/index.js"

    %% Click Events for Firebase Configuration
    click FConfig "https://github.com/thisisantonio/sociolingo/blob/main/chat_app/firebase.json"
    click FConfig "https://github.com/thisisantonio/sociolingo/blob/main/chat_app/.firebaserc"
    click FConfig "https://github.com/thisisantonio/sociolingo/blob/main/chat_app/.firebase"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef firebase fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef platform fill:#E0FFFF,stroke:#000,stroke-width:1px;
```
