# ritheeshshetty/advance-web-sunshine architecture

> Architecture diagram of the GitHub repository ritheeshshetty/advance-web-sunshine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ritheeshshetty/advance-web-sunshine
- Repository: https://github.com/ritheeshshetty/advance-web-sunshine

## Overview

##### Project Type and Purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) news-site application focused on privacy.
- The backend (in `backend1/`) provides JWT-based authentication, user management, admin analytics, and proxies requests to the external NewsAPI.
- The frontend (in `sunshine1/`) is a React single-page app that uses Context API for global state, implements infinite scrolling for article feeds, and supports user/admin views and dark mode.

##### File Structure
- Top-level split:
- `backend1/` – Node.js + Express server
– `controllers/` (business logic for auth, news grouping, admin)
– `routes/` (public & protected API endpoints: auth, news, userData, admin)
– `middleware/` (JWT verification, admin checks)
– `models/` (Mongoose schemas: User, Stats)
– `db.js` (MongoDB connection)
– `index.js` (server bootstrap)
– `backup/` (bson dumps of Mongo collections)
- `sunshine1/` – React frontend
– `public/` (static HTML, manifest, robots.txt)
– `src/components/` (UI pieces: Login, Signup, News feed, Admin layouts)
– `src/context/userData/` (Context & Provider for auth & user state)
– `src/App.js` & `src/index.js` (app entry)
- Config files: `package.json`, `Procfile`, `vercel.json` (deployment settings).

##### README Insights
- News grouped via NewsAPI calls.
- Infinite scroll + progress bar on feed.
- JWT auth with bcrypt + salt; user data in MongoDB.
- Admin dashboard shows user lists + analytics.
- Context API for efficient state access in React.

##### Main Components & Interactions
a. Components
- React Frontend (Browser)
- Express Backend (Node.js server)
- MongoDB Database
- External NewsAPI Service
- (Optional) Deployment/Hosting Platform (e.g., Vercel, Heroku)
b. Data Flows & Relationships
1. User → Browser → React UI
2. React UI ↔ Express REST API over HTTPS
3. Express ↔ MongoDB (Mongoose ORM) for user & stats data
4. Express → External NewsAPI for article data
5. Admin actions: React Admin UI → Admin endpoints → DB read/write
6. JWT issuance & verification on protected endpoints
c. Architectural Patterns
- Client-Server (SPA + REST API)
- Token-based auth (JWT)
- Context API for state management (frontend)
- MVC-style layering in backend (routes → controllers → models)
d. Key Technologies & Libraries
- React, Context API, React Router, infinite-scroll libraries
- Node.js, Express, Mongoose
- bcryptjs, jsonwebtoken
- NewsAPI (third-party HTTP calls)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External
    Browser["User (Browser)"]:::external

    %% Frontend Layer
    subgraph "React Frontend"
        direction TB
        PublicStatic["Public Static Assets"]:::frontend
        AppEntryIndex["index.js"]:::frontend
        AppEntryApp["App.js"]:::frontend
        UserContext["UserContext.js"]:::frontend
        UserState["UserState.js"]:::frontend
        HomePage["Landing/Home"]:::frontend
        Login["Login"]:::frontend
        Signup["Signup"]:::frontend
        PrivateRoute["PrivateRoute"]:::frontend
        News["News Feed"]:::frontend
        NewsItem["News Item"]:::frontend
        Spinner["Spinner / Progress Bar"]:::frontend
        AdminLayout["Admin Layout"]:::frontend
        AdminUsers["Admin Users"]:::frontend
        AdminStats["Admin Stats"]:::frontend
    end

    Browser --> PublicStatic
    Browser --> AppEntryIndex
    AppEntryIndex --> AppEntryApp
    AppEntryApp --> UserContext
    AppEntryApp --> UserState
    AppEntryApp --> HomePage
    AppEntryApp --> Login
    AppEntryApp --> Signup
    AppEntryApp --> PrivateRoute
    AppEntryApp --> News
    AppEntryApp --> NewsItem
    AppEntryApp --> Spinner
    AppEntryApp --> AdminLayout
    AppEntryApp --> AdminUsers
    AppEntryApp --> AdminStats
    News -->|"infinite scroll requests /news?page=N"| AppEntryApp

    %% Frontend to Backend
    AppEntryApp -->|"REST API calls (/auth, /news, /userData, /admin)"| ExpressServer

    %% Backend Layer
    subgraph "Express Backend"
        direction TB
        ExpressServer["Express Server (index.js)"]:::backend
        DBConnection["MongoDB Connection (db.js)"]:::backend
        AuthRoute["auth.js"]:::backend
        NewsRoute["news.js"]:::backend
        UserDataRoute["userData.js"]:::backend
        AdminRoute["admin-router.js"]:::backend
        FetchUser["fetchuser.js"]:::backend
        AdminMiddleware["admin-middleware.js"]:::backend
        AdminControllers["admin-controllers.js"]:::backend
        UserModel["User.js"]:::backend
        StatsModel["Stats.js"]:::backend
        Backup["Backup Snapshots"]:::backend
    end

    ExpressServer --> DBConnection
    ExpressServer --> AuthRoute
    ExpressServer --> NewsRoute
    ExpressServer --> UserDataRoute
    ExpressServer --> AdminRoute
    AuthRoute --> FetchUser
    AdminRoute --> AdminMiddleware
    AdminRoute --> AdminControllers
    AdminControllers --> UserModel
    AdminControllers --> StatsModel
    DBConnection --> MongoDB
    MongoDB["MongoDB"]:::db
    MongoDB --> Backup
    ExpressServer --> ExternalNewsAPI

    %% External Services
    ExternalNewsAPI["NewsAPI Service"]:::external

    %% Deployment Configurations
    subgraph "Deployment Configs"
        direction TB
        Procfile["Procfile"]:::backend
        VercelBackend["vercel.json (backend)"]:::backend
        VercelRoot["vercel.json (root)"]:::backend
    end

    ExpressServer --> Procfile
    ExpressServer --> VercelBackend
    ExpressServer --> VercelRoot

    %% Click Events
    click PublicStatic "https://github.com/ritheeshshetty/advance-web-sunshine/tree/main/sunshine1/public/"
    click AppEntryIndex "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/index.js"
    click AppEntryApp "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/App.js"
    click UserContext "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/context/userData/UserContext.js"
    click UserState "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/context/userData/UserState.js"
    click HomePage "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/HomePage.js"
    click Login "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/Login.js"
    click Signup "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/Signup.js"
    click PrivateRoute "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/PrivateRoute.js"
    click News "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/News.js"
    click NewsItem "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/NewsItem.js"
    click Spinner "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/Spinner.js"
    click AdminLayout "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/layouts/Admin-Layout.js"
    click AdminUsers "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/layouts/Admin-Users.js"
    click AdminStats "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/sunshine1/src/components/layouts/Admin-Stats.js"
    click ExpressServer "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/index.js"
    click DBConnection "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/db.js"
    click AuthRoute "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/routes/auth.js"
    click NewsRoute "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/routes/news.js"
    click UserDataRoute "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/routes/userData.js"
    click AdminRoute "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/routes/admin-router.js"
    click FetchUser "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/middleware/fetchuser.js"
    click AdminMiddleware "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/middleware/admin-middleware.js"
    click AdminControllers "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/controllers/admin-controllers.js"
    click UserModel "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/models/User.js"
    click StatsModel "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/models/Stats.js"
    click Backup "https://github.com/ritheeshshetty/advance-web-sunshine/tree/main/backend1/backup/"
    click Procfile "https://github.com/ritheeshshetty/advance-web-sunshine/tree/main/backend1/Procfile"
    click VercelBackend "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/backend1/vercel.json"
    click VercelRoot "https://github.com/ritheeshshetty/advance-web-sunshine/blob/main/vercel.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#000
    classDef backend fill:#D0FFD0,stroke:#000
    classDef external fill:#FFE0B2,stroke:#000
    classDef db fill:#E0E0E0,stroke:#000
```
