# hi-imcodeman/stock-nse-india architecture

> Architecture diagram of the GitHub repository hi-imcodeman/stock-nse-india, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hi-imcodeman/stock-nse-india
- Repository: https://github.com/hi-imcodeman/stock-nse-india

## Overview

This package provides direct Node.js access to NSE India market data, plus REST and GraphQL servers, a CLI, and MCP integrations. The main workflow is a caller request entering one of those interfaces, being dispatched to NSE data operations, and returning market results. It also supports AI-assisted natural-language queries with optional session memory and context summarization. The graph preserves the documented data domains and interfaces; unsampled resolver and endpoint internals are represented only where their wiring is supported by the available evidence.

Main entry points: [`src/index.ts`](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/index.ts) (NSE client library), [`src/routes.ts`](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/routes.ts) (REST routes), [`src/mcp/client/mcp-client.ts`](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/client/mcp-client.ts) (Natural-language client), [`src/server.ts`](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/server.ts) (GraphQL server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_cli_entry["CLI commands<br/>[index.ts]"]
  node_cli_api["CLI data views<br/>[api.ts]"]
end

subgraph group_market["Market Data"]
  node_library["NSE client library<br/>[index.ts]"]
  node_equity_mapping["Equity mapping<br/>[equity-mappers.ts]"]
  node_market_helpers["Market analysis helpers<br/>[helpers.ts]"]
end

subgraph group_mcp["MCP and AI"]
  node_mcp_stdio["MCP stdio server<br/>[mcp-server.ts]"]
  node_mcp_tools["MCP tool handlers<br/>[mcp-tools.ts]"]
  node_mcp_client["Natural-language client<br/>[mcp-client.ts]"]
  node_memory["Conversation memory<br/>[memory-manager.ts]"]
  node_summarizer["Context summarizer"]
end

subgraph group_server["API Server"]
  node_rest_routes["REST routes<br/>[routes.ts]"]
  node_graphql_server["GraphQL server<br/>[server.ts]"]
  node_graphql_resolver["GraphQL resolver<br/>[root.resolver.ts]"]
  node_rest_errors["Route error handling<br/>[route-errors.ts]"]
end

node_caller(("Package / API caller"))
node_ai_user(("AI assistant user"))
node_mcp_host(("MCP host"))
node_nse{{"NSE India services"}}
node_openai{{"OpenAI API"}}

node_caller -->|"calls data methods"| node_library
node_library -->|"fetches market data"| node_nse
node_library -->|"maps equity data"| node_equity_mapping
node_caller -->|"sends GraphQL query"| node_graphql_server
node_graphql_server -->|"dispatches queries"| node_graphql_resolver
node_caller -->|"sends REST request"| node_rest_routes
node_graphql_server -->|"mounts routes"| node_rest_routes
node_rest_routes -->|"calls data methods"| node_library
node_rest_routes -->|"requests analysis"| node_market_helpers
node_rest_routes -->|"processes AI query"| node_mcp_client
node_rest_routes -->|"formats failures"| node_rest_errors
node_cli_entry -->|"dispatches commands"| node_cli_api
node_cli_api -->|"calls data methods"| node_library
node_cli_entry -->|"starts server"| node_mcp_stdio
node_mcp_host -->|"sends MCP messages"| node_mcp_stdio
node_mcp_stdio -->|"dispatches tool calls"| node_mcp_tools
node_mcp_tools -->|"calls data methods"| node_library
node_ai_user -->|"submits query"| node_mcp_client
node_mcp_client -->|"requests tool selection"| node_openai
node_mcp_client -->|"executes tool calls"| node_mcp_tools
node_mcp_client -->|"reads and updates context"| node_memory
node_memory -->|"summarizes conversations"| node_summarizer
node_graphql_resolver -.->|"queries market data"| node_library

click node_library "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/index.ts"
click node_equity_mapping "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/equity-mappers.ts"
click node_market_helpers "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/helpers.ts"
click node_rest_routes "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/routes.ts"
click node_graphql_server "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/server.ts"
click node_graphql_resolver "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/root.resolver.ts"
click node_rest_errors "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/route-errors.ts"
click node_cli_entry "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/cli/index.ts"
click node_cli_api "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/cli/api.ts"
click node_mcp_stdio "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/server/mcp-server.ts"
click node_mcp_tools "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/mcp-tools.ts"
click node_mcp_client "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/client/mcp-client.ts"
click node_memory "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/memory-manager.ts"
click node_summarizer "https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/context-summarizer.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_entry,node_cli_api,node_ai_user toneBlue
class node_library,node_equity_mapping,node_market_helpers toneAmber
class node_mcp_stdio,node_mcp_tools,node_mcp_client,node_memory,node_summarizer,node_caller,node_openai toneMint
class node_rest_routes,node_graphql_server,node_graphql_resolver,node_rest_errors toneRose
class node_mcp_host,node_nse toneIndigo
```

## Components

### User Interfaces

- [CLI commands](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/cli/index.ts): `src/cli/index.ts`
- [CLI data views](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/cli/api.ts): `src/cli/api.ts`

### Market Data

- [NSE client library](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/index.ts): `src/index.ts`
- [Equity mapping](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/equity-mappers.ts): `src/equity-mappers.ts`
- [Market analysis helpers](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/helpers.ts): `src/helpers.ts`

### MCP and AI

- [MCP stdio server](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/server/mcp-server.ts): `src/mcp/server/mcp-server.ts`
- [MCP tool handlers](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/mcp-tools.ts): `src/mcp/mcp-tools.ts`
- [Natural-language client](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/client/mcp-client.ts): `src/mcp/client/mcp-client.ts`
- [Conversation memory](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/memory-manager.ts): `src/mcp/memory-manager.ts`
- [Context summarizer](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/mcp/context-summarizer.ts): `src/mcp/context-summarizer.ts`

### API Server

- [REST routes](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/routes.ts): `src/routes.ts`
- [GraphQL server](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/server.ts): `src/server.ts`
- [GraphQL resolver](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/root.resolver.ts): `src/root.resolver.ts`
- [Route error handling](https://github.com/hi-imcodeman/stock-nse-india/blob/master/src/route-errors.ts): `src/route-errors.ts`

### Other components

- **Package / API caller**
- **AI assistant user**
- **MCP host**
- **NSE India services**
- **OpenAI API**

## Connections

- Package / API caller → NSE client library: calls data methods
- NSE client library → NSE India services: fetches market data
- NSE client library → Equity mapping: maps equity data
- Package / API caller → GraphQL server: sends GraphQL query
- GraphQL server → GraphQL resolver: dispatches queries
- Package / API caller → REST routes: sends REST request
- GraphQL server → REST routes: mounts routes
- REST routes → NSE client library: calls data methods
- REST routes → Market analysis helpers: requests analysis
- REST routes → Natural-language client: processes AI query
- REST routes → Route error handling: formats failures
- CLI commands → CLI data views: dispatches commands
- CLI data views → NSE client library: calls data methods
- CLI commands → MCP stdio server: starts server
- MCP host → MCP stdio server: sends MCP messages
- MCP stdio server → MCP tool handlers: dispatches tool calls
- MCP tool handlers → NSE client library: calls data methods
- AI assistant user → Natural-language client: submits query
- Natural-language client → OpenAI API: requests tool selection
- Natural-language client → MCP tool handlers: executes tool calls
- Natural-language client → Conversation memory: reads and updates context
- Conversation memory → Context summarizer: summarizes conversations
- GraphQL resolver → NSE client library: queries market data
