# taneja-garvit/newswave architecture

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

## Overview

##### Main Components
- Frontend (dApp): Represented by the "truthwave-shared" directory, this component contains all the client-side code, React components (including specific components like BlockchainVisual, NewsFeed, and WalletConnect), styling (Tailwind), routing (via pages like Index, Article, and NotFound), and configuration for Vite.
- Backend: Located under the "news backend" directory, this Node.js/Express server is responsible for handling API requests, interfacing with Ethereum (via Web3.js), and serving as the intermediary between the frontend and external services.
- Decentralized Storage (IPFS): Used for storing news content (text, images, PDFs) in a tamper-proof way.
- Blockchain (Sepolia Testnet): Ensures that metadata (content hash, credibility scores, timestamps) is recorded on-chain for transparency.
- OpenAI API: Integrated to analyze news content and provide a credibility/trust metric.
- External Services/Utilities: This includes libraries dealing with Ethereum interactions and possibly other utilities (“ethereum.ts”, “ipfs.ts”, “openai.ts”, “utils.ts”) that reside in the “lib” folder.

##### Relationships and Interactions
- The Frontend (React client) enables users to upload news, view the public news feed, and display credibility scores.
- User-uploaded news goes from the Frontend to the Backend via an API call.
- The Backend handles the submission:
- It first stores the content on IPFS.
- Then, it updates the blockchain (Sepolia Testnet) with the content metadata.
- In parallel, it sends the news content to the OpenAI API to obtain a credibility/trust score.
- Once processed, the public news feed (accessible to the frontend) shows posts with data coming from a combination of blockchain records and IPFS storage.
- The Backend may also expose endpoints to fetch news data and status updates, which are consumed by the frontend.

##### Architectural Patterns and Design Principles
- Decoupled/Modular Architecture: The separation between the frontend and backend—with clear API boundaries—ensures that each component can evolve independently.
- Use of Decentralized Storage and Blockchain: The design leverages immutable data storage (IPFS) and transparent recording (blockchain) and combines these with centralized processing (backend API) to achieve security without compromising user anonymity.
- API Integration: The backend acts as a bridge integrating third-party services (OpenAI for credibility scoring).

##### Relevant Technologies and Frameworks
- Frontend: React.js, Vite, Tailwind CSS, and Web3.js.
- Backend: Node.js/Express (as indicated by the package-lock.json and directory structure).
- Blockchain: Ethereum Sepolia Testnet via Web3.js.
- Decentralized Storage: IPFS.
- External Service: OpenAI API.
- Additional: Use of TypeScript (as evidenced by .ts and .tsx files) and configuration files (e.g., bun.lockb, tailwind.config.ts, tsconfig.json).

##### Be Detailed Yet Clear
- Major components and interactions are included.
- As a software engineer, break the overall system into as many logical segments as possible so that each component’s function and interaction can be easily understood.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend dApp (React/Vite)"]:::frontend
        RC["React Components"]:::frontend
        RP["Routing Pages"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        BE["API Server (Node.js/Express)"]:::backend
        ES["Decentralized Storage (IPFS)"]:::backend
        BC["Blockchain (Sepolia Testnet)"]:::backend
        OA["OpenAI API (Credibility Scoring)"]:::backend
        EU["External Utilities/Integrations"]:::backend
    end

    %% Data Flow
    FE -->|"UploadNews"| BE
    BE -->|"StoreContent"| ES
    BE -->|"RecordMetadata"| BC
    BE -->|"CredibilityAnalysis"| OA
    OA -->|"CredibilityScore"| BE
    BE -->|"NewsFeedData"| FE
    EU --- BE

    %% Click Events
    click FE "https://github.com/taneja-garvit/newswave/tree/main/truthwave-shared-3955509780c8444de33439b8b6295b8954d575a5"
    click RC "https://github.com/taneja-garvit/newswave/tree/main/truthwave-shared-3955509780c8444de33439b8b6295b8954d575a5/src/components"
    click RP "https://github.com/taneja-garvit/newswave/tree/main/truthwave-shared-3955509780c8444de33439b8b6295b8954d575a5/src/pages"
    click BE "https://github.com/taneja-garvit/newswave/tree/main/news backend/newsWaveBackend"
    click EU "https://github.com/taneja-garvit/newswave/tree/main/truthwave-shared-3955509780c8444de33439b8b6295b8954d575a5/src/lib"

    %% Styles
    classDef frontend fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef backend fill:#AED6F1,stroke:#5DADE2,stroke-width:2px;
```
