# dvillanuevav/portafolio-management architecture

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

- Interactive diagram: https://gitdiagram.com/dvillanuevav/portafolio-management
- Repository: https://github.com/dvillanuevav/portafolio-management

## Overview

##### Project type and purpose
- This is a back-end portfolio management solution composed of:
- A .NET Web API (“API” project) for CRUD and read operations on portfolio balances and share-price records.
- A collection of Azure Functions (“Functions” project) that perform background jobs:
– Balance computation at day’s end (timer-trigger & HTTP-trigger).
– Processing new deposit messages from an Azure Storage Queue.
– Maintaining an in-memory Redis cache of daily share-price quotas via Cosmos DB change feed.
- A shared “Common” library for domain entities, validation, and settings.
- Azure resources: Cosmos DB (NoSQL), Azure Storage Queue, Redis Cache.

##### File structure
- Top-level:
- src/API – Web API endpoints subdivided by feature (Balances, SharePrices).
- src/Functions – Azure Functions grouped by feature (Balances.Compute, Deposits.Compute, SharePrices.WriteThroughCache).
- src/Common – Shared domain models, validators, settings classes.
- tests – Unit tests targeting Azure Functions.
- Infrastructure/config:
- API/appsettings.json & Cosmos/Redis connection strings.
- Functions/host.json, local.settings.json, serviceDependencies.json for emulator connectivity.
- launchSettings.json for local debugging.

##### README for additional insights
- Dependency list: Azure Cosmos Emulator, Azurite, Redis.

##### Elements
- Data stores in another (e.g., orange).
- Clients/API in a third (e.g., blue).

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Clients and API Layer
  subgraph "Clients & API" 
    direction TB
    Clients["Clients (Postman/SwaggerUI, Front-ends)"]:::client
    API["API (ASP.NET Core Web API)"]:::api
    GetBalance["GetBalanceByDate Endpoint"]:::api
    GetSharesGet["GetSharesPrices Endpoint"]:::api
    PostShares["PostSharePrices Endpoint"]:::api
    Common["Common Library"]:::common
  end

  %% Functions Layer
  subgraph "Azure Functions" 
    direction TB
    FuncBalanceTimer["fn-balance-compute-timer (Timer Trigger)"]:::func
    FuncBalanceHttp["fn-balance-compute-timer (HTTP Trigger)"]:::func
    FuncDepositQueue["fn-shares-compute-queue (Queue Trigger)"]:::func
    FuncSharePricesCache["fn-shareprices-cache-changefeed (Cosmos Change Feed)"]:::func
  end

  %% Azure Services Layer
  subgraph "Azure Services"
    direction TB
    Queue["Azure Storage Queue\n(incoming-deposits)"]:::data
    Cosmos["Azure Cosmos DB\n(SharePrices, Balances, Deposits)"]:::data
    Redis["Redis Cache"]:::data
  end

  %% Relationships
  Clients -->|"POST /api/balances"| GetBalance
  Clients -->|"GET /api/share-prices"| GetSharesGet
  Clients -->|"POST /api/share-prices"| PostShares
  Clients -->|"GET /api/compute-balance-adhoc"| FuncBalanceHttp

  GetBalance -->|"Query"| Redis
  GetBalance -->|"Fallback Read"| Cosmos

  PostShares -->|"Writes SharePriceRecord"| Cosmos
  FuncDepositQueue -->|"Reads DepositMessage"| Queue
  FuncDepositQueue -->|"Writes Deposit Entity"| Cosmos

  Cosmos -->|"Change Feed"| FuncSharePricesCache
  FuncSharePricesCache -->|"Updates Quotas"| Redis

  FuncBalanceTimer -->|"Reads Balances & Deposits & SharePrices"| Cosmos
  FuncBalanceTimer -->|"Writes Daily Balance"| Cosmos
  FuncBalanceTimer -->|"Updates Cache"| Redis

  %% Common library usage
  API --> Common
  FuncBalanceTimer --> Common
  FuncBalanceHttp --> Common
  FuncDepositQueue --> Common
  FuncSharePricesCache --> Common

  %% Click events
  click API "https://github.com/dvillanuevav/portafolio-management/tree/main/src/API"
  click GetBalance "https://github.com/dvillanuevav/portafolio-management/blob/main/src/API/Features/Balances/GetBalanceByDate/Endpoint.cs"
  click GetSharesGet "https://github.com/dvillanuevav/portafolio-management/blob/main/src/API/Features/SharePrices/GetSharesPrices/Endpoint.cs"
  click PostShares "https://github.com/dvillanuevav/portafolio-management/blob/main/src/API/Features/SharePrices/PostSharePrices/Endpoint.cs"
  click Common "https://github.com/dvillanuevav/portafolio-management/tree/main/src/Common"
  click FuncBalanceTimer "https://github.com/dvillanuevav/portafolio-management/blob/main/src/Functions/Features/Balances/Compute/FunctionTimer.cs"
  click FuncBalanceHttp "https://github.com/dvillanuevav/portafolio-management/blob/main/src/Functions/Features/Balances/Compute/FunctionHttp.cs"
  click FuncDepositQueue "https://github.com/dvillanuevav/portafolio-management/blob/main/src/Functions/Features/Deposits/Compute/FunctionQueue.cs"
  click FuncSharePricesCache "https://github.com/dvillanuevav/portafolio-management/blob/main/src/Functions/Features/SharePrices/WriteThroughCache/FunctionChangeFeed.cs"
  click Redis "https://github.com/dvillanuevav/portafolio-management/blob/main/src/Functions/Features/SharePrices/WriteThroughCache/SharePriceCache.cs"

  %% Styles
  classDef client fill:#D6E9FE,stroke:#4A90E2,color:#0B3D91,stroke-width:1px;
  classDef api fill:#E8F1FC,stroke:#577399,color:#1F3A93,stroke-width:1px;
  classDef func fill:#D6F5F0,stroke:#28A745,color:#1B5E20,stroke-width:1px;
  classDef data fill:#FFF5E6,stroke:#FFA500,color:#8A4500,stroke-width:1px;
  classDef common fill:#F0F0F0,stroke:#A0A0A0,color:#505050,stroke-width:1px;
```
