# rohit-k-singh/fintech-news architecture

> Architecture diagram of the GitHub repository rohit-k-singh/fintech-news, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohit-k-singh/fintech-news
- Repository: https://github.com/rohit-k-singh/fintech-news

## Overview

##### Project Type and Purpose
- This is a **Next.js** (React-based) front-end application with server-side rendering (SSR) / static site generation, using **Redux** for state management.
- It fetches finance news from the external **Finlight API** and displays articles on the Home and Details pages.

##### Main Components
- Next.js Application
– App Router (app/layout.tsx, app/page.tsx, app/details/page.tsx)
– Global styles (app/globals.css)
- UI Component Layer
– src/components (Navbar, PageWrapper, Loader, ArticleList, ArticleItem)
– src/screens (Home, ArticleDetails)
- State Management
– Redux store (src/store/index.ts)
– articleSlice (src/store/slices/articleSlice.ts)
– Custom hook (src/hooks/useReduxStore.ts)
- Data-Fetch Layer
– Axios instance configured with env vars (src/utils/axiosInstance.ts)
– Type definitions (src/utils/types.ts)
- External Service
– Finlight API (secured by NEXT_PUBLIC_FINLIGHT_API key)
- Build & Test
– Build tools/config (next.config.ts, tsconfig.json, postcss.config.mjs)
– Tests (Jest: jest.config.js, src/tests/ReadArticle.test.js)

##### Core Relationships & Data Flows
1. **Browser/Client** loads a route (Home or Article Details).
2. Next.js SSR/SSG layer invokes React components under `app/`.
3. Components dispatch Redux actions via the custom hook.
4. Redux Thunks in articleSlice call the axiosInstance.
5. axiosInstance makes HTTP requests to the Finlight API.
6. Responses flow back into Redux store → selectors → UI components render updated state.
7. Static assets and global styles are served from the `public/` directory and `app/globals.css`.

##### Architectural Patterns & Design Principles
- **Component Hierarchy**: Clear separation between layout (Navbar, PageWrapper), screens, and small reusable components (Loader, ArticleItem).
- **State Management**: Centralized store (Redux Toolkit slice) for predictable state transitions and caching of fetched articles.
- **Data-Fetching Abstraction**: Single axiosInstance for all API calls, configured via env vars for flexibility.
- **Next.js SSR/SSG**: Hybrid rendering for performance and SEO.

##### Putting It All Together
- Below that, place “AxiosInstance” feeding into “Finlight API.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Next.js Front-End Layer
    subgraph "Next.js Front-End" 
        direction TB
        AppRouter["App Router"]:::frontend
        subgraph "Pages (App Router)"
            direction TB
            HomePage["Home Page"]:::frontend
            DetailsPage["Details Page"]:::frontend
        end
        GlobalStyles["Global Styles"]:::frontend

        subgraph "Screens"
            direction TB
            HomeScreen["Home Screen"]:::frontend
            DetailsScreen["Article Details Screen"]:::frontend
        end

        subgraph "UI Components"
            direction TB
            Navbar["Navbar"]:::frontend
            PageWrapper["PageWrapper"]:::frontend
            Loader["Loader"]:::frontend
            ArticleList["ArticleList"]:::frontend
            ArticleItem["ArticleItem"]:::frontend
        end
    end

    %% State Management Layer
    subgraph "State Management" 
        direction TB
        ReduxStore["Redux Store Configuration"]:::state
        ArticleSlice["Redux Article Slice"]:::state
        UseReduxHook["useReduxStore Hook"]:::state
    end

    %% Data Layer
    subgraph "Data-Fetch Layer"
        direction TB
        AxiosInstance["Axios Instance"]:::data
        Types["Type Definitions"]:::data
        FinlightAPI{{"Finlight API"}}:::external
    end

    %% Build & Test Pipeline
    subgraph "Build & Test Pipeline"
        direction TB
        Yarn["Yarn"]:::infra
        NextConfigs["Next.js & TS Configs"]:::infra
        JestConfig["Jest Configuration"]:::infra
        ReadTest["Article Read Test"]:::infra
    end

    %% Connections
    AppRouter -->|"renders"| HomePage
    AppRouter -->|"renders"| DetailsPage
    HomePage -->|"uses"| HomeScreen
    DetailsPage -->|"uses"| DetailsScreen
    HomeScreen -->|"renders"| Navbar
    HomeScreen -->|"wraps"| PageWrapper
    HomeScreen -->|"fetches"| ArticleList
    ArticleList -->|"renders"| ArticleItem
    DetailsScreen -->|"renders"| Loader

    HomeScreen -->|"dispatch action"| ReduxStore
    DetailsScreen -->|"dispatch action"| ReduxStore
    ReduxStore -->|"uses slice"| ArticleSlice
    ArticleSlice -->|"uses hook"| UseReduxHook
    UseReduxHook -->|"calls"| AxiosInstance
    AxiosInstance -->|"HTTP GET /articles"| FinlightAPI
    FinlightAPI -->|"response"| AxiosInstance
    AxiosInstance -->|"dispatch action"| ReduxStore
    ReduxStore -->|"select state"| HomeScreen
    ReduxStore -->|"select state"| DetailsScreen

    GlobalStyles -.-> HomeScreen
    GlobalStyles -.-> DetailsScreen

    %% Build/Test flows
    Yarn -->|build| NextConfigs
    NextConfigs -->|"configures"| AppRouter
    JestConfig -->|runs tests| ReadTest

    %% Click Events
    click AppRouter "https://github.com/rohit-k-singh/fintech-news/blob/main/app/layout.tsx"
    click HomePage "https://github.com/rohit-k-singh/fintech-news/blob/main/app/page.tsx"
    click DetailsPage "https://github.com/rohit-k-singh/fintech-news/blob/main/app/details/page.tsx"
    click GlobalStyles "https://github.com/rohit-k-singh/fintech-news/blob/main/app/globals.css"
    click Navbar "https://github.com/rohit-k-singh/fintech-news/blob/main/src/components/Navbar.tsx"
    click PageWrapper "https://github.com/rohit-k-singh/fintech-news/blob/main/src/components/PageWrapper.tsx"
    click Loader "https://github.com/rohit-k-singh/fintech-news/blob/main/src/components/Loader.tsx"
    click ArticleList "https://github.com/rohit-k-singh/fintech-news/blob/main/src/components/ArticleList.tsx"
    click ArticleItem "https://github.com/rohit-k-singh/fintech-news/blob/main/src/components/ArticleItem.tsx"
    click HomeScreen "https://github.com/rohit-k-singh/fintech-news/blob/main/src/screens/Home.tsx"
    click DetailsScreen "https://github.com/rohit-k-singh/fintech-news/blob/main/src/screens/ArticleDetails.tsx"
    click ReduxStore "https://github.com/rohit-k-singh/fintech-news/blob/main/src/store/index.ts"
    click ArticleSlice "https://github.com/rohit-k-singh/fintech-news/blob/main/src/store/slices/articleSlice.ts"
    click UseReduxHook "https://github.com/rohit-k-singh/fintech-news/blob/main/src/hooks/useReduxStore.ts"
    click AxiosInstance "https://github.com/rohit-k-singh/fintech-news/blob/main/src/utils/axiosInstance.ts"
    click Types "https://github.com/rohit-k-singh/fintech-news/blob/main/src/utils/types.ts"
    click NextConfigs "https://github.com/rohit-k-singh/fintech-news/blob/main/next.config.ts"
    click NextConfigs "https://github.com/rohit-k-singh/fintech-news/blob/main/tsconfig.json"
    click NextConfigs "https://github.com/rohit-k-singh/fintech-news/blob/main/postcss.config.mjs"
    click JestConfig "https://github.com/rohit-k-singh/fintech-news/blob/main/jest.config.js"
    click ReadTest "https://github.com/rohit-k-singh/fintech-news/blob/main/src/tests/ReadArticle.test.js"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef state fill:#E6F4EA,stroke:#28A745,color:#28A745;
    classDef data fill:#FFF4E5,stroke:#FF8C00,color:#FF8C00;
    classDef infra fill:#F2F2F2,stroke:#6A737D,color:#6A737D;
    classDef external fill:#F8F9FA,stroke:#586069,color:#586069,stroke-dasharray: 5 5;
```
