# icnneto/myprojectdictionary architecture

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

- Interactive diagram: https://gitdiagram.com/icnneto/myprojectdictionary
- Repository: https://github.com/icnneto/myprojectdictionary

## Overview

##### Main Components
- Frontend (Client-Side)
- Represented by the contents of the "public" folder.
- Includes HTML pages (e.g., index.html, dashboard.html, login.html) and JavaScript modules/components (organized under public/JS) responsible for UI rendering, page logic, and direct interactions with Firebase (e.g., realtime listeners with onSnapshot, handling add/edit/delete operations).
- Styling with Tailwind CSS and additional CSS files from the "public/css" folder.
- Firebase Backend (Serverless Components)
- Firebase Authentication: Handles user login with Google and GitHub OAuth; interact via Firebase’s client and admin SDKs.
- Firebase Firestore: NoSQL database where the users’ terms are stored under the hierarchy: users/{userId}/termos/{termoId}. Include data fields such as "termo", "descricao", and "favoritado".
- Cloud Functions (located in the "functions" folder):
∙ Function endpoints such as getApiKey, editarTermo, addToIndex, and changeFavoriteIndex.
∙ Integrates with Algolia for search indexing and update operations.
- External Search Service – Algolia
- Responsible for providing fast search and indexing.
- The Cloud Functions handle operations that authenticate and synchronize the Algolia index with changes in Firestore.
- Structure for indexing terms including attributes like objectID, termo, descricao, favoritado, userID, etc.

##### Important Architectural Patterns & Design Principles
- Client-Server Separation: The frontend communicates directly with Firebase for some operations, while more complex workflows (such as indexing with Algolia) are handled through Cloud Functions.
- Real-time Data Flow: The use of onSnapshot in the frontend indicates real-time synchronization with Firestore.
- Serverless Architecture: Leveraging Firebase Cloud Functions reduces the need for a dedicated backend server.
- Secure Data Access: Firebase Authentication coupled with Firestore Security Rules ensures that users access only their own data.
- External Service Integration: The integration with Algolia for fast, efficient searching.

## Diagram (Mermaid)

```mermaid
graph TD
    user("User"):::external

    subgraph "Frontend (Client Side)"
        fePub("Frontend (public)"):::frontend
        indexPage("Index.html"):::frontend
        dashPage("Dashboard.html"):::frontend
        loginPage("Login.html"):::frontend
        jsModules("JS Modules"):::frontend
        firebaseConfig("Firebase Config"):::firebase
    end

    subgraph "Firebase Services"
        firebaseAuth("Firebase Authentication"):::firebase
        firestore("Firebase Firestore"):::firebase
        cloudFunctions("Cloud Functions (getApiKey,editarTermo,addToIndex,changeFavoriteIndex)"):::firebase
        cfIndex("functions/index.js"):::firebase
        cfPackage("functions/package.json"):::firebase
    end

    algolia("Algolia Search"):::external

    %% User to Frontend flow
    user -->|"accesses"| fePub
    fePub -->|"renders"| indexPage
    fePub -->|"renders"| dashPage
    fePub -->|"renders"| loginPage
    fePub -->|"loads modules from"| jsModules
    jsModules -->|"initializes"| firebaseConfig

    %% Frontend interactions with Firebase Services
    firebaseConfig -->|"authenticates with"| firebaseAuth
    firebaseConfig -->|"queries"| firestore
    firebaseConfig -->|"triggers"| cloudFunctions

    fePub -->|"calls"| firebaseAuth
    fePub -->|"updates"| firestore
    fePub -->|"invokes"| cloudFunctions

    %% Cloud Functions internal structure
    cloudFunctions -->|"defined in"| cfIndex
    cloudFunctions -->|"configured by"| cfPackage

    %% Cloud Functions integration with external service
    cloudFunctions -->|"syncs with"| algolia

    %% Click Events
    click fePub "https://github.com/icnneto/myprojectdictionary/tree/main/public"
    click indexPage "https://github.com/icnneto/myprojectdictionary/blob/main/public/index.html"
    click dashPage "https://github.com/icnneto/myprojectdictionary/blob/main/public/pages/dashboard.html"
    click loginPage "https://github.com/icnneto/myprojectdictionary/blob/main/public/pages/login.html"
    click jsModules "https://github.com/icnneto/myprojectdictionary/tree/main/public/JS"
    click firebaseConfig "https://github.com/icnneto/myprojectdictionary/blob/main/public/JS/firebaseConfig.js"
    click cloudFunctions "https://github.com/icnneto/myprojectdictionary/tree/main/functions"
    click cfIndex "https://github.com/icnneto/myprojectdictionary/blob/main/functions/index.js"
    click cfPackage "https://github.com/icnneto/myprojectdictionary/blob/main/functions/package.json"
    click algolia "https://github.com/icnneto/myprojectdictionary/blob/main/public/JS/pages/personalcanva/search/searchAlgolia.js"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef firebase fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD580,stroke:#000,stroke-width:2px;
```
