# kargilhero/financial-dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/kargilhero/financial-dashboard
- Repository: https://github.com/kargilhero/financial-dashboard

## Overview

##### Project Type & Purpose
- This is a full-stack, monolithic web application: a **Financial Dashboard** built with **Node.js/Express** on the backend, **EJS** template rendering, and static front-end assets (HTML/CSS/JS) delivered from the `public/` folder.
- It offers user authentication, a suite of financial calculators and planners, to-do management, real-time charts, stock/news integration, currency conversion, and an admin message panel.

##### High-Level Architecture Components
a. Frontend (Client Browser)
- Static assets: `public/css/*.css`, `public/js/*.js`
- EJS templates: `views/*.ejs`, partials like `navbar.ejs`
- Charting libraries (Chart.js or ApexCharts) for data visualization
b. Backend (Express Server)
- Entry point: `server.js`
- Middleware: `express-session` (session handling), `bcrypt` (password hashing), body parsers, static file serving
- Routing & Controllers (grouped in server.js or separate route files):
– Auth (login, register, password reset via Nodemailer)
– Dashboard & tools (net worth, loan, tax, retirement, debt)
– To-Do CRUD
– Stock & news fetch
– Contact form & admin messages
c. Data Layer
- **MySQL** database (users, sessions, to-dos, messages, tool inputs/results)
- ORM or raw queries in controllers/models
d. External Services
- Currency conversion API
- Stock price & news APIs
- SMTP service via **Nodemailer** for password recovery emails

##### Relationships & Data Flows
- Client → HTTP(S) GET/POST → Express routes
- Routes → Controllers → (a) MySQL for CRUD, (b) External API calls
- Controllers → Render EJS views or send JSON → Client
- Session middleware tracks login state (session cookie stored on client → server memory or DB)
- Nodemailer invoked by backend to send emails

##### Architectural Patterns & Principles
- MVC‐style separation:
- **View**: EJS templates + static assets
- **Controller/Route**: request handling, business logic
- **Model/Data**: MySQL tables accessed via queries or an ORM layer
- Layered architecture: presentation, application, data, external integration
- Single-process monolith, modularized by feature (auth, tools, to-do, admin)
- Use of middleware for cross‐cutting concerns (logging, sessions, security)

##### Detail & Granularity
- Every external dependency (currency API, stock API, SMTP) as its own node.
- Session store—either in-memory or in the MySQL DB—as part of the Data Layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/UI Layer
    subgraph "Client/UI Layer"    
        direction TB
        Browser["Web Browser"]:::frontend
        StaticCSS["Static CSS (public/css/)"]:::frontend
        StaticJS["Static JS (public/js/)"]:::frontend
        EJSViews["EJS Templates (views/)"]:::frontend
    end

    %% Server/Application Layer
    subgraph "Server/Application Layer"
        direction TB
        Server["Express Server (server.js)"]:::backend
        Middleware["Middleware\n(express-session, bcrypt, body-parser)"]:::backend
        subgraph "Routing & Controllers"
            direction TB
            AuthRouter["Auth Routes"]:::backend
            ToolsRouter["Financial Tools Routes"]:::backend
            ToDoRouter["To-Do Routes"]:::backend
            StockNewsRouter["Stock/News Routes"]:::backend
            ContactRouter["Contact/Admin Routes"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MySQL[(MySQL Database)]:::database
        SessionStore[(Session Store)]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        CurrencyAPI["Currency Conversion API"]:::external
        StockAPI["Stock Price API"]:::external
        NewsAPI["News API"]:::external
        SMTP["SMTP Service (Nodemailer)"]:::external
    end

    %% Connections
    Browser -->|HTTPS GET/POST| Server
    Server --> Middleware
    Middleware --> AuthRouter
    Middleware --> ToolsRouter
    Middleware --> ToDoRouter
    Middleware --> StockNewsRouter
    Middleware --> ContactRouter

    AuthRouter -->|SQL Queries| MySQL
    ToolsRouter -->|SQL Queries| MySQL
    ToDoRouter -->|SQL Queries| MySQL
    StockNewsRouter -->|SQL Queries| MySQL
    ContactRouter -->|SQL Queries| MySQL

    AuthRouter -->|sends email| SMTP
    ToolsRouter -->|fetch data| CurrencyAPI
    StockNewsRouter -->|fetch data| StockAPI
    StockNewsRouter -->|fetch data| NewsAPI

    MySQL --> SessionStore
    Middleware --> SessionStore

    Server -->|renders EJS| EJSViews
    Server -->|serves files| StaticCSS
    Server -->|serves files| StaticJS

    StaticCSS --> Browser
    StaticJS --> Browser
    EJSViews --> Browser

    %% Click Events
    click StaticCSS "https://github.com/kargilhero/financial-dashboard/tree/main/public/css/"
    click StaticJS "https://github.com/kargilhero/financial-dashboard/tree/main/public/js/"
    click EJSViews "https://github.com/kargilhero/financial-dashboard/tree/main/views/"
    click Server "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click AuthRouter "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click toolsRouter "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click ToDoRouter "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click StockNewsRouter "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click ContactRouter "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click SMTP "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click CurrencyAPI "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click StockAPI "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"
    click NewsAPI "https://github.com/kargilhero/financial-dashboard/blob/main/server.js"

    click EJSViews "https://github.com/kargilhero/financial-dashboard/tree/main/views/"
    click StaticCSS "https://github.com/kargilhero/financial-dashboard/tree/main/public/css/"
    click StaticJS "https://github.com/kargilhero/financial-dashboard/tree/main/public/js/"

    %% Detailed View Clicks
    click Navbar "https://github.com/kargilhero/financial-dashboard/blob/main/views/navbar.ejs"
    click LoginView "https://github.com/kargilhero/financial-dashboard/blob/main/views/login.ejs"
    click RegisterView "https://github.com/kargilhero/financial-dashboard/blob/main/views/register.ejs"
    click ForgotView "https://github.com/kargilhero/financial-dashboard/blob/main/views/forgot-password.ejs"
    click ResetView "https://github.com/kargilhero/financial-dashboard/blob/main/views/reset-password.ejs"
    click AdminLogin "https://github.com/kargilhero/financial-dashboard/blob/main/views/login-admin.ejs"

    click NetWorthView "https://github.com/kargilhero/financial-dashboard/blob/main/views/networth.ejs"
    click NetWorthScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/networth.js"
    click LoanView "https://github.com/kargilhero/financial-dashboard/blob/main/views/loan.ejs"
    click LoanScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/loan.js"
    click TaxView "https://github.com/kargilhero/financial-dashboard/blob/main/views/tax.ejs"
    click TaxScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/tax.js"
    click ConverterView "https://github.com/kargilhero/financial-dashboard/blob/main/views/converter.ejs"
    click ConverterScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/conveter.js"
    click RetirementView "https://github.com/kargilhero/financial-dashboard/blob/main/views/retirement.ejs"
    click DebtView "https://github.com/kargilhero/financial-dashboard/blob/main/views/debt-planner.ejs"

    click TodoView "https://github.com/kargilhero/financial-dashboard/blob/main/views/todo.ejs"
    click TodoScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/todo.js"

    click NewsView "https://github.com/kargilhero/financial-dashboard/blob/main/views/news.ejs"
    click NewsScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/news.js"
    click StocksView "https://github.com/kargilhero/financial-dashboard/blob/main/views/stocks.ejs"

    click ContactView "https://github.com/kargilhero/financial-dashboard/blob/main/views/contact.ejs"
    click ContactScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/contact.js"
    click AdminMessages "https://github.com/kargilhero/financial-dashboard/blob/main/views/admin/messages.ejs"

    click HomeView "https://github.com/kargilhero/financial-dashboard/blob/main/views/home.ejs"
    click HomeScript "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/home.js"
    click HomeCSS "https://github.com/kargilhero/financial-dashboard/blob/main/public/css/home.css"
    click AboutCSS "https://github.com/kargilhero/financial-dashboard/blob/main/public/css/about.css"

    click GlobalCSS "https://github.com/kargilhero/financial-dashboard/blob/main/public/css/style.css"
    click GlobalCSS2 "https://github.com/kargilhero/financial-dashboard/blob/main/public/css/styles.css"
    click GlobalJS "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/script.js"
    click GlobalJS2 "https://github.com/kargilhero/financial-dashboard/blob/main/public/js/scripts.js"

    %% Styles
    classDef frontend fill:#CEF2FF,stroke:#1E88E5,color:#000
    classDef backend fill:#DFFFE0,stroke:#43A047,color:#000
    classDef database fill:#FFE0B2,stroke:#FB8C00,color:#000
    classDef external fill:#E1BEE7,stroke:#8E24AA,color:#000
```
