# analytica-manulife/frontend architecture

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

- Interactive diagram: https://gitdiagram.com/analytica-manulife/frontend
- Repository: https://github.com/analytica-manulife/frontend

## Overview

##### Project type and purpose
- This is an ASP.NET Core Razor Pages web frontend (monolithic) targeting .NET 9.0.
- It delivers a finance dashboard and workflow: user authentication, budget management, invoice upload and parsing, stock portfolio display and trading, and news aggregation.

##### File structure
- Top-level “Frontend” project contains:
- Pages (Razor views and code‐behind) – the presentation layer
- Model – domain DTOs, JSON converters, naming policy filters
- Service – HTTP client wrappers for downstream APIs
- Middleware – cross-cutting concerns (authentication)
- Filter – JSON parsing and invoice conversion helpers
- wwwroot – static assets (CSS, JS, Bootstrap, jQuery)
- Program.cs / appsettings*.json – host configuration and DI setup
- No DB code here; data storage and business logic live in external APIs.

##### Key insights from README
- Minimal README; naming implies “Frontend” only.
- Interaction is primarily via REST‐style APIs (BudgetApiService, InvoiceService, NewsService, PortfolioService, StockService, YahooFinanceService, StockSuggestionService, AuthService).

##### Main components & relationships
A. Browser / Client
- Requests HTML, CSS, JS, and uses forms and AJAX calls to the Razor Pages endpoints.
B. Web Server (ASP.NET Core / Kestrel or IIS)
1. Middleware Pipeline
- AuthenticationCheckMiddleware ensures user identity before hitting pages.
2. Routing → Razor Pages handlers
- Each page (e.g. /Budget, /Portfolio, /MarketWatch, /UploadInvoice) invokes its PageModel (code‐behind).
3. Service Layer
- PageModel calls Service classes (e.g. BudgetApiService) injected via DI.
- Services perform HttpClient calls to external microservices or third‐party APIs.
4. Filter & Converter Modules
- Incoming JSON uses JsonSnakeCaseNamingPolicy, Nullable*Converters for JSON ↔ Model mapping.
- InvoiceParser + InvoiceItemConverter transform raw invoice payloads into domain objects.
5. Models
- DTOs (Account, Budget, Portfolio, StockTransaction, StoryResponse, etc.) represent data in the UI.
C. External Systems (downstream APIs)
- Auth API / Identity Provider
- Budget microservice
- Invoice processing service
- News aggregation API
- Portfolio / Trading API
- Yahoo Finance external API
- Stock suggestion engine

##### Architectural patterns & design principles
- Layered architecture (Presentation → Application Services → External APIs)
- Dependency Injection for services and filters (built‐in ASP.NET Core DI)
- Middleware for cross-cutting concerns (authentication, error handling)
- DTO / Converter pattern for JSON mapping and domain modeling
- Razor Pages MVC style (Pages + PageModels)

##### Detail
- Every unique service and filter as its own component.
- Clearly that there is no direct database—it all flows through external microservices.
- Don’t omit the Middleware layer—authentication is core to every page.
- Pages logically (Budget, Portfolio, MarketWatch, News, Invoice Upload) to show feature boundaries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        BROWSER["Browser"]:::client
        STATIC["Static Assets (wwwroot)"]:::static
        subgraph "Razor Pages"
            IDX["Index Page"]:::page
            LOGIN["Login Page"]:::page
            LOGOUT["Logout Page"]:::page
            BUDGET["Budget Page"]:::page
            PORTF["Portfolio Page"]:::page
            MARKET["MarketWatch Page"]:::page
            NEWS["NewsPage"]:::page
            UPINV["UploadInvoice Page"]:::page
            LAYOUT["_Layout.cshtml"]:::page
            VALID["_ValidationScriptsPartial.cshtml"]:::page
        end
        BROWSER -->|"GET HTML/CSS/JS"| STATIC
        BROWSER -->|"GET/POST Forms & AJAX"| IDX
    end

    %% Application Layer
    subgraph "Application Layer"
        subgraph Middleware
            AUTHM["AuthenticationCheckMiddleware"]:::middleware
        end
        subgraph "PageModels and Handlers"
            IDXM["Index Model"]:::page
            LOGINM["Login Model"]:::page
            LOGOUTM["Logout Model"]:::page
            BUDGETM["Budget Model"]:::page
            PORTFM["Portfolio Model"]:::page
            MARKETM["MarketWatch Model"]:::page
            NEWSM["NewsPage Model"]:::page
            UPINVM["UploadInvoice Model"]:::page
        end
        subgraph Services
            AUTHS["AuthService"]:::service
            BUDGETS["BudgetApiService"]:::service
            INVOS["InvoiceService"]:::service
            NEWSS["NewsService"]:::service
            PORTFS["PortfolioService"]:::service
            STOCKS["StockService"]:::service
            SUGGST["StockSuggestionService"]:::service
            YAHOO["YahooFinanceService"]:::service
        end
        subgraph FiltersConverters
            JSONP["JsonSnakeCaseNamingPolicy"]:::filter
            NDOUBLE["NullableDoubleConverter"]:::filter
            NINT["NullableIntConverter"]:::filter
            NLONG["NullableLongConverter"]:::filter
            IPARSER["InvoiceParser"]:::filter
            IITEMC["InvoiceItemConverter"]:::filter
        end
        subgraph Models
            ACCOUNT["Account DTO"]:::model
            BUDGETM2["Budget DTOs"]:::model
            INVOICED["Invoice DTOs"]:::model
            LOGINR["LoginResponse DTO"]:::model
            NEWSA["NewsArticle DTOs"]:::model
            PORTFOM["Portfolio DTO"]:::model
            STOCKD["Stock DTOs"]:::model
            TRANSACT["StockTransaction DTOs"]:::model
            REQUESTS["Buy/Sell/BudgetRequests"]:::model
        end

        STATIC --> AUTHM
        AUTHM --> IDXM
        IDX --> IDXM
        LOGIN --> LOGINM
        LOGOUT --> LOGOUTM
        BUDGET --> BUDGETM
        PORTF --> PORTFM
        MARKET --> MARKETM
        NEWS --> NEWSM
        UPINV --> UPINVM

        IDXM --> AUTHS
        LOGINM --> AUTHS
        LOGOUTM --> AUTHS
        BUDGETM --> BUDGETS
        BUDGETM --> JSONP
        BUDGETM --> NDOUBLE
        UPINVM --> INVOS
        INVOS --> IPARSER
        IPARSER --> IITEMC
        BUDGETM --> BUDGETM2

        PORTFM --> PORTFS
        PORTFM --> STOCKS
        STOCKS --> YAHOO
        PORTFM --> SUGGST
        NEWSM --> NEWSS
        NEWSM --> JSONP
        AUTHS --> ACCOUNT
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        AUTHAPI["Auth API"]:::external
        BUDGETAPI["Budget Microservice"]:::external
        INVOICEAPI["Invoice Processing Service"]:::external
        NEWSAPI["News Aggregation API"]:::external
        PORTAPI["Portfolio/Trading API"]:::external
        YAHOOAPI["Yahoo Finance API"]:::external
        SUGGESTAPI["Stock Suggestion Engine"]:::external
    end

    AUTHS -->|"HTTP JSON"| AUTHAPI
    BUDGETS -->|"HTTP JSON"| BUDGETAPI
    INVOS -->|"HTTP JSON"| INVOICEAPI
    NEWSS -->|"HTTP JSON"| NEWSAPI
    PORTFS -->|"HTTP JSON"| PORTAPI
    YAHOO -->|"HTTP JSON"| YAHOOAPI
    SUGGST -->|"HTTP JSON"| SUGGESTAPI

    %% Click Events
    click IDX "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/Index.cshtml"
    click LOGIN "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/Login.cshtml"
    click LOGOUT "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/Logout.cshtml"
    click BUDGET "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/Budget.cshtml"
    click PORTF "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/Portfolio.cshtml"
    click MARKET "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/MarketWatch.cshtml"
    click NEWS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/NewsPage.cshtml"
    click UPINV "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/UploadInvoice.cshtml"
    click LAYOUT "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/Shared/_Layout.cshtml"
    click VALID "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Pages/Shared/_ValidationScriptsPartial.cshtml"
    click STATIC "https://github.com/analytica-manulife/frontend/tree/main/Frontend/wwwroot"
    click AUTHM "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Middleware/AuthenticationCheckMiddleware.cs"
    click AUTHS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/AuthService.cs"
    click BUDGETS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/BudgetApiService.cs"
    click INVOS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/InvoiceService.cs"
    click NEWSS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/NewsService.cs"
    click PORTFS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/PortfolioService.cs"
    click STOCKS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/StockService.cs"
    click SUGGST "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/StockSuggestionService.cs"
    click YAHOO "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Service/YahooFinanceService.cs"
    click ACCOUNT "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/Account.cs"
    click BUDGETM2 "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/Budget.cs"
    click INVOICED "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/Invoice.cs"
    click LOGINR "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/LoginResponse.cs"
    click NEWSA "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/NewsArticle.cs"
    click PORTFOM "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/Portfolio.cs"
    click STOCKD "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/Stock.cs"
    click TRANSACT "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/StockTransaction.cs"
    click REQUESTS "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/BuyStockRequest.cs"
    click JSONP "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Filter/JsonSnakeCaseNamingPolicy.cs"
    click NDOUBLE "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/NullableDoubleConverter.cs"
    click NINT "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/NullableIntConverter.cs"
    click NLONG "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Model/NullableLongConverter.cs"
    click IPARSER "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Filter/InvoiceParser.cs"
    click IITEMC "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Filter/InvoiceItemConverter.cs"
    click Program "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Program.cs"
    click appsettings "https://github.com/analytica-manulife/frontend/blob/main/Frontend/appsettings.json"
    click appsettingsDev "https://github.com/analytica-manulife/frontend/blob/main/Frontend/appsettings.Development.json"
    click launch "https://github.com/analytica-manulife/frontend/blob/main/Frontend/Properties/launchSettings.json"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085;
    classDef static fill:#ffd8b1,stroke:#e09f3e;
    classDef page fill:#cce5ff,stroke:#004085;
    classDef middleware fill:#cce5ff,stroke:#004085;
    classDef service fill:#cce5ff,stroke:#004085;
    classDef filter fill:#fff3cd,stroke:#856404;
    classDef model fill:#e2e3e5,stroke:#6c757d;
    classDef external fill:#d4edda,stroke:#155724;
```
