# eshan-b/sunny-snippets architecture

> Architecture diagram of the GitHub repository eshan-b/sunny-snippets, 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/eshan-b/sunny-snippets
- Repository: https://github.com/eshan-b/sunny-snippets

## Overview

Based on your project’s file structure and README content, Sunny Snippets is a full-stack web application built with Next.js and Tailwind CSS. The app is designed to display positive news articles (fetched from an external news API) while using sentiment analysis to filter out negative content, and it leverages Firebase (Firestore) for storing saved articles and Clerk for authentication.

##### Main System Components
- Client/User Browser: Represents users interacting with the web application.
- Next.js Frontend: This includes the overall UI layer built with React, Tailwind CSS, and NextUI. Highlight the “app” directory which hosts the pages and layouts, and the “components” directory that holds reusable UI parts (e.g., Navbar, Hero Section, News Cards, Profile Dropdown).
- API/Service Layer:
- External News API Integration: A component responsible for fetching uplifting news articles. (Refer to utils/news-api.ts)
- Sentiment Analysis Service: The service that filters news articles based on their positivity (see services/sentiment-analysis.ts using the sentiment npm package).
- Backend/Data Storage:
- Firebase/Firestore: Represents the backend data store where saved articles are retrieved and deleted (point out firebase.config.ts and utils/firestore.ts).
- Authentication:
- Clerk Authentication Service: Although not directly found in the file tree, it is mentioned in the README as a service for MFA and login functionality.

##### Visualizing Relationships and Data Flow
- From the Client (web browser) to the Next.js Frontend when rendering pages.
- From the Frontend to the External News API: for retrieving real-time news articles.
- From the Frontend to the Sentiment Analysis module: where articles are processed and filtered.
- Between the Frontend and Firebase: to manage saved articles (retrieve and delete operations).
- From the Client to the Clerk Authentication Service: to handle login and user management, affecting protected routes like account pages.

##### Highlighting Architectural Patterns
- Separation of concerns: the routing and page management in the “app” directory (which follows Next.js conventions) versus the modularization of business logic (services, utilities, components).
- That the file structure suggests usage of layout components (e.g., layout.tsx) and dynamic routing (e.g., app/account/[[...account]]) which follow Next.js best practices.
- That the project uses a component-based architecture typical of modern React applications.
- The middleware.ts can be represented as a global-level request handler which might be used for runtime authorization or redirection.

##### Details on Technologies and Frameworks
- Next.js: central to rendering pages, server-side logic, and routing.
- Tailwind CSS & NextUI: Provide styling and theming for UI components.
- Firebase (Firestore): For persistent data storage for user articles.
- Clerk: For handling multi-factor authentication.
- Sentiment npm Package: To analyze article sentiment scores.
- External News API (The Guardian News API as mentioned in the README): As the data provider for news articles.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    Client("User Browser"):::client
    Middleware("Middleware (middleware.ts)"):::middleware

    subgraph "Frontend Layer"
        subgraph "Pages & Layouts"
            layout("Layout (app/layout.tsx)"):::frontend
            home("Home Page (app/page.tsx)"):::frontend
            account("Account Layout (app/account/[[...account]]/layout.tsx)"):::frontend
            articles("Articles Layout (app/articles/layout.tsx)"):::frontend
        end
        subgraph "UI Components"
            navbar("Navbar (components/navbar.tsx)"):::frontend
            hero("Hero Section (components/hero-section.tsx)"):::frontend
            newscard("News Card (components/news-card.tsx)"):::frontend
            profile("Profile Dropdown (components/profile-dropdown.tsx)"):::frontend
        end
    end

    subgraph "Service Layer"
        newsAPI("External News API (utils/news-api.ts)"):::service
        sentiment("Sentiment Analysis (services/sentiment-analysis.ts)"):::service
        subgraph "Firebase/Firestore"
            firebaseConfig("Firebase Config (firebase.config.ts)"):::database
            firestore("Firestore Utils (utils/firestore.ts)"):::database
        end
        clerk("Clerk Authentication"):::auth
    end

    %% Arrows / Relationships
    Client -->|"HTTPRequest"| Middleware
    Middleware -->|"RoutesRequest"| home
    Client -->|"login"| clerk
    home -->|"fetchNews"| newsAPI
    home -->|"analyze"| sentiment
    newscard <-->|"saveUnsaved"| firestore
    profile -->|"authInfo"| clerk

    %% Styles
    classDef client fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef middleware fill:#d6eaf8,stroke:#333,stroke-width:2px;
    classDef frontend fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef service fill:#a9dfbf,stroke:#333,stroke-width:2px;
    classDef database fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef auth fill:#f5b7b1,stroke:#333,stroke-width:2px;

    %% Click Events
    click layout "https://github.com/eshan-b/sunny-snippets/blob/main/app/layout.tsx"
    click home "https://github.com/eshan-b/sunny-snippets/blob/main/app/page.tsx"
    click account "https://github.com/eshan-b/sunny-snippets/blob/main/app/account/[[...account]]/layout.tsx"
    click articles "https://github.com/eshan-b/sunny-snippets/blob/main/app/articles/layout.tsx"
    click navbar "https://github.com/eshan-b/sunny-snippets/blob/main/components/navbar.tsx"
    click hero "https://github.com/eshan-b/sunny-snippets/blob/main/components/hero-section.tsx"
    click newscard "https://github.com/eshan-b/sunny-snippets/blob/main/components/news-card.tsx"
    click profile "https://github.com/eshan-b/sunny-snippets/blob/main/components/profile-dropdown.tsx"
    click newsAPI "https://github.com/eshan-b/sunny-snippets/blob/main/utils/news-api.ts"
    click sentiment "https://github.com/eshan-b/sunny-snippets/blob/main/services/sentiment-analysis.ts"
    click firebaseConfig "https://github.com/eshan-b/sunny-snippets/blob/main/firebase.config.ts"
    click firestore "https://github.com/eshan-b/sunny-snippets/blob/main/utils/firestore.ts"
    click Middleware "https://github.com/eshan-b/sunny-snippets/blob/main/middleware.ts"
```
