# ishu077/foundation architecture

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

- Interactive diagram: https://gitdiagram.com/ishu077/foundation
- Repository: https://github.com/ishu077/foundation

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“AI-Powered Text Summarization Application”) that provides users with an interface to submit long text, generates concise summaries via Google Gemini AI, caches results in Redis, and stores history in MongoDB.

##### File Structure Analysis
- Top-level split:
- /backend – Node.js/Express server.
- /frontend – React/Vite client.
- Backend folders:
- config (Redis client),
- controllers (auth.js, summary.js),
- middlewares (JWT auth, rateLimiter),
- helper (summariser.js wraps Gemini AI),
- models (MongoDB schemas: user, article, summary),
- routes (user, summary),
- utils (cache utilities for Redis).
- Frontend folders:
- src/components (UI atoms/molecules),
- src/pages (Login, Signup, History),
- App.jsx and Dashboard.jsx for routing and main UI.
- Key config files: package.json, .env, vite.config.js, tailwind.config.js, Redis config.

##### README Insights
- Tech Stack clearly lists React, Vite, Express, MongoDB (Mongoose), Redis, Google Gemini AI, JWT, bcrypt, Helmet, CORS, rate-limiting.
- Caching strategy and rate limiting details.

##### Main Components & Interactions
a. Components:
- React Frontend (Browser)
- Express Backend (monolithic API server)
- MongoDB Database
- Redis Cache & Rate Limiter
- Google Gemini AI (external service)
b. Data Flow & Relationships:
1. User interacts with React UI → browser issues HTTP requests to Express.
2. At Express entry (server.js): CORS & Helmet apply.
3. Requests pass through rateLimiter middleware (uses Redis).
4. Authenticated routes use auth middleware (JWT).
5. Controller logic:
- SummaryController → checks Redis cache via utils/cache.
– If cache MISS: calls summariser helper → Google Gemini → stores result in Redis.
– If cache HIT: returns cached summary.
- CRUD operations read/write to MongoDB via Mongoose models.
6. Responses return to React, which updates UI.
c. Architectural Patterns & Principles:
- Layered MVC-style architecture on backend: routes → middlewares → controllers → models/util.
- Single monolith backend (no microservices).
- Caching layer (Redis) abstracted via utilities.
- External integration as a separate “service” (Gemini AI).
- Stateless front-end; state managed client-side.
d. Key Technologies:
- Frontend: React, Vite, Tailwind CSS, React Router, Google OAuth.
- Backend: Node.js, Express, Mongoose, Redis client, Google Generative AI SDK, JWT, bcrypt, Helmet, CORS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client (Browser)"
        ReactApp["React App"]:::frontend
        App["App.jsx"]:::frontend
        Dashboard["Dashboard.jsx"]:::frontend
        Login["Login Page"]:::frontend
        Signup["Signup Page"]:::frontend
        History["History Page"]:::frontend
        Components["UI Components"]:::frontend
    end

    %% Server Side
    subgraph "Server (Express API)"
        HelmetCORS["Helmet & CORS"]:::backend
        RateLimiter["Rate Limiter"]:::backend
        AuthMW["Auth Middleware (JWT)"]:::backend

        subgraph "Routes"
            UserRoutes["User Routes"]:::backend
            SummaryRoutes["Summary Routes"]:::backend
        end

        subgraph "Controllers"
            AuthCtrl["Auth Controller"]:::backend
            SummaryCtrl["Summary Controller"]:::backend
            Decision{"Cache Hit?"}:::decision
            CacheReturn["Return Cached Summary"]:::backend
        end

        subgraph "Utilities & Helpers"
            CacheUtil["Cache Utils"]:::backend
            Summariser["Summariser Helper"]:::backend
        end

        subgraph "Models"
            UserModel["User Model"]:::backend
            ArticleModel["Article Model"]:::backend
            SummaryModel["Summary Model"]:::backend
        end
    end

    %% Data Stores & External Service
    RedisCache["Redis Cache\n(Cache & Rate Limiter)"]:::db
    Mongo["MongoDB"]:::db
    Gemini["Google Gemini AI"]:::external

    %% Flows
    ReactApp -->|"HTTP requests"| HelmetCORS
    HelmetCORS --> RateLimiter
    RateLimiter --> AuthMW
    AuthMW --> UserRoutes
    AuthMW --> SummaryRoutes

    UserRoutes --> AuthCtrl
    SummaryRoutes --> SummaryCtrl

    SummaryCtrl --> Decision
    Decision -->|Yes| CacheReturn
    CacheReturn --> SummaryCtrl
    Decision -->|No| CacheUtil

    CacheUtil --> RedisCache
    CacheUtil --> Summariser

    Summariser -->|calls AI| Gemini
    Gemini -->|returns summary| Summariser
    Summariser -->|store summary| RedisCache
    Summariser --> SummaryCtrl

    AuthCtrl --> UserModel
    SummaryCtrl --> ArticleModel
    SummaryCtrl --> SummaryModel

    AuthCtrl --> Mongo
    SummaryCtrl --> Mongo

    SummaryCtrl --> ReactApp
    AuthCtrl --> ReactApp

    %% Click Events
    click ReactApp "https://github.com/ishu077/foundation/tree/main/frontend/src"
    click App "https://github.com/ishu077/foundation/blob/main/frontend/src/App.jsx"
    click Dashboard "https://github.com/ishu077/foundation/blob/main/frontend/src/Dashboard.jsx"
    click Login "https://github.com/ishu077/foundation/blob/main/frontend/src/pages/Login.jsx"
    click Signup "https://github.com/ishu077/foundation/blob/main/frontend/src/pages/Signup.jsx"
    click History "https://github.com/ishu077/foundation/blob/main/frontend/src/pages/History.jsx"
    click Components "https://github.com/ishu077/foundation/tree/main/frontend/src/components"
    click HelmetCORS "https://github.com/ishu077/foundation/blob/main/backend/server.js"
    click RateLimiter "https://github.com/ishu077/foundation/blob/main/backend/middlewares/rateLimiter.js"
    click AuthMW "https://github.com/ishu077/foundation/blob/main/backend/middlewares/auth.js"
    click UserRoutes "https://github.com/ishu077/foundation/blob/main/backend/routes/user.js"
    click SummaryRoutes "https://github.com/ishu077/foundation/blob/main/backend/routes/summary.js"
    click AuthCtrl "https://github.com/ishu077/foundation/blob/main/backend/controllers/auth.js"
    click SummaryCtrl "https://github.com/ishu077/foundation/blob/main/backend/controllers/summary.js"
    click CacheUtil "https://github.com/ishu077/foundation/blob/main/backend/utils/cache.js"
    click Summariser "https://github.com/ishu077/foundation/blob/main/backend/helper/summariser.js"
    click UserModel "https://github.com/ishu077/foundation/blob/main/backend/models/user.js"
    click ArticleModel "https://github.com/ishu077/foundation/blob/main/backend/models/article.js"
    click SummaryModel "https://github.com/ishu077/foundation/blob/main/backend/models/summary.js"
    click RedisCache "https://github.com/ishu077/foundation/blob/main/backend/config/redis.js"
    click ViteConfig "https://github.com/ishu077/foundation/blob/main/frontend/vite.config.js"
    click TailwindConfig "https://github.com/ishu077/foundation/blob/main/frontend/tailwind.config.js"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064
    classDef backend fill:#ECEFF1,stroke:#455A64,color:#455A64
    classDef db fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef decision fill:#FFFDE7,stroke:#F9A825,color:#F9A825
```
