# varsharc/intention-ally architecture

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

- Interactive diagram: https://gitdiagram.com/varsharc/intention-ally
- Repository: https://github.com/varsharc/intention-ally

## Overview

##### Main Components
a. Frontend:
- Framework: Next.js (React) – look at the “pages”, “components”, and “frontend” directories.
- Features include dashboards, search configuration screens, results displays, and visualizations (knowledge graphs with D3.js).
- State management using React Context (see contexts folder).
- UI components (SearchBar, MainDashboard, AuthModal, etc.) spread across both “components” and “pages” directories.
b. Backend / Service Layer:
- Python-based services (backend directory containing api.py, scheduler.py, models.py, brave_search.py, and storage.py) that likely handle semantic search logic, clustering, and scheduling tasks.
- Node.js servers and scripts (app-server.js, express-server.js, next-app-server.js, server.js, etc.) that may act as API gateways or integration points.
- “services” directory holding API wrappers for authentication (auth.js), Firebase integration, authority management, and Supabase, providing an abstraction over external APIs.
c. External Integrations:
- Firebase: Used for authentication (Firebase Auth) and data persistence (Firestore); see components/ and contexts/FirebaseContext.js.
- Tavily API: For semantic search integration as described in the README, with fallback to mock data in settings.
- Brave Search (backend/brave_search.py) as a potential search data source.
d. Data and Storage:
- Databases and collections in Firebase (user information, search configurations, and search results/clustering data).
- Data files (JSON in the “data” directory) to mock or test search results.

##### Relationships and Interactions
- The Frontend (Next.js) consumes both internal APIs (from your backend services and “services” layer) and external services (Firebase, Tavily API).
- User interactions on the frontend trigger API calls (likely via the “services/api.js”) to fetch and configure searches, handle authentication, or retrieve search results.
- The Backend (Python scripts and Node.js APIs) performs the semantic analysis, clustering, or data enrichment using inputs from the frontend, and then persists or retrieves data from Firebase.
- External API calls (to Tavily and Brave Search) are mediated by the backend, feeding search data back to the frontend.
- Firebase also functions as the persistence layer (storing user profiles, search configurations, and results).

##### Architectural Patterns and Design Principles
- Separation of concerns: Clearly partition the frontend visual/UI layer from the backend processing and API integration.
- Use of microservices/API gateway pattern: The modular “services” and “backend” directories indicate separate responsibilities (e.g., search, authentication, authority scoring).
- Integration of third-party services: Firebase for auth and data, external search APIs (Tavily/Brave Search) for semantic search.
- State management via React Context and modular component design for easy scalability.

##### Relevant Technologies, Frameworks, and Libraries
- Frontend: Next.js, React, Tailwind CSS, D3.js.
- Backend: Python (for api, scheduling, and search logic), Node.js (for serving Next.js and other API endpoints).
- Data Persistence: Firebase Firestore and Firebase Authentication.
- External APIs: Tavily API and Brave Search.
- Build tools and configuration: Webpack (as seen in the .next cache) and Tailwind configuration files.

##### Detail and Clarity
– Frontend pages/components (Home, Search Configuration, Search Results, and Settings).
– Functional modules in the Backend (API endpoints, semantic search logic, scheduling, and storage).
– Data components (User, Search Configurations, Search Results) along with how they are stored in Firebase Firestore.
– Integration points for external APIs.
- Avoid unnecessary over-complication but do partition the system into distinct sub-components for clear understanding.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Frontend"
        Pages("Pages (Next.js)"):::frontend
        UI("UI Components"):::frontend
        Auth("Auth Components"):::frontend
        State("State Management (FirebaseContext)"):::frontend
    end

    %% Backend Components
    subgraph "Backend"
        subgraph "Python Services"
            API_py("api.py"):::backend
            Scheduler("scheduler.py"):::backend
            Models("models.py"):::backend
            Brave("brave_search.py"):::backend
            Storage("storage.py"):::backend
        end
        subgraph "Node.js Servers"
            AppServer("app-server.js"):::backend
            ExpressServer("express-server.js"):::backend
            NextAppServer("next-app-server.js"):::backend
            NextServer("next-server.js"):::backend
            Server("server.js"):::backend
            HtmlServer("html-server.js"):::backend
            HtmlTestServer("html-test-server.js"):::backend
            SimpleServer("simple-server.js"):::backend
        end
        subgraph "Services Layer"
            ServicesAPI("api.js"):::backend
            ServicesAuth("auth.js"):::backend
            Authority("authorityService.js"):::backend
            ServicesFirebase("firebase.js"):::backend
            ServicesSupabase("supabase.js"):::backend
        end
    end

    %% Data and Storage
    subgraph "Data & Storage"
        DataFiles("Data Files"):::database
        Firestore("Firebase Firestore"):::database
    end

    %% External Services
    subgraph "External Services"
        Firebase("Firebase"):::external
        Tavily("Tavily API"):::external
        BraveAPI("Brave Search API"):::external
    end

    %% Connections from Frontend to Services Layer and External
    Pages -->|"calls"| ServicesAPI
    UI -->|"fetches"| ServicesAPI
    Auth -->|"authenticates"| ServicesAuth
    State -->|"syncs"| Firebase

    %% Services Layer interactions with Backend Services
    ServicesAPI -->|"processes"| API_py
    ServicesAPI -->|"routes"| NextServer
    ServicesAuth -->|"handles"| ExpressServer
    ServicesFirebase -->|"persists to"| Firestore
    ServicesFirebase -->|"integrates"| Firebase
    ServicesSupabase -->|"manages"| Authority

    %% Python Services interactions
    API_py -->|"uses mock_data"| DataFiles
    API_py -->|"integrates"| Tavily
    API_py -->|"triggers"| Brave
    Brave -->|"calls"| BraveAPI

    %% Additional Backend interconnections (illustrative)
    Scheduler -->|"schedules"| API_py
    Models -->|"data-model"| API_py
    Storage -->|"stores files"| Firestore

    %% Styling Classes
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef external fill:#ffe5cc,stroke:#333,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend
    click Pages "https://github.com/varsharc/intention-ally/tree/main/pages"
    click UI "https://github.com/varsharc/intention-ally/tree/main/components"
    click Auth "https://github.com/varsharc/intention-ally/tree/main/components/auth"
    click State "https://github.com/varsharc/intention-ally/blob/main/contexts/FirebaseContext.js"

    %% Click Events for Python Services
    click API_py "https://github.com/varsharc/intention-ally/blob/main/backend/api.py"
    click Scheduler "https://github.com/varsharc/intention-ally/blob/main/backend/scheduler.py"
    click Models "https://github.com/varsharc/intention-ally/blob/main/backend/models.py"
    click Brave "https://github.com/varsharc/intention-ally/blob/main/backend/brave_search.py"
    click Storage "https://github.com/varsharc/intention-ally/blob/main/backend/storage.py"

    %% Click Events for Node.js Servers
    click AppServer "https://github.com/varsharc/intention-ally/blob/main/app-server.js"
    click ExpressServer "https://github.com/varsharc/intention-ally/blob/main/express-server.js"
    click NextAppServer "https://github.com/varsharc/intention-ally/blob/main/next-app-server.js"
    click NextServer "https://github.com/varsharc/intention-ally/blob/main/next-server.js"
    click Server "https://github.com/varsharc/intention-ally/blob/main/server.js"
    click HtmlServer "https://github.com/varsharc/intention-ally/blob/main/html-server.js"
    click HtmlTestServer "https://github.com/varsharc/intention-ally/blob/main/html-test-server.js"
    click SimpleServer "https://github.com/varsharc/intention-ally/blob/main/simple-server.js"

    %% Click Events for Services Layer
    click ServicesAPI "https://github.com/varsharc/intention-ally/blob/main/services/api.js"
    click ServicesAuth "https://github.com/varsharc/intention-ally/blob/main/services/auth.js"
    click Authority "https://github.com/varsharc/intention-ally/blob/main/services/authorityService.js"
    click ServicesFirebase "https://github.com/varsharc/intention-ally/blob/main/services/firebase.js"
    click ServicesSupabase "https://github.com/varsharc/intention-ally/blob/main/services/supabase.js"

    %% Click Events for Data
    click DataFiles "https://github.com/varsharc/intention-ally/tree/main/data"
```
