# berker00/canli_piyasalar architecture

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

- Interactive diagram: https://gitdiagram.com/berker00/canli_piyasalar
- Repository: https://github.com/berker00/canli_piyasalar

## Overview

Canlı Piyasalar is a Node.js service that collects real-time Turkish gold, foreign-exchange, and commodity prices, merges them into an in-memory snapshot, and serves API, SSE, and dashboard clients while periodically persisting JSON. The main runtime flow is the Harem Altın Socket.IO feed → socket client → rate store → HTTP clients and atomic file output. The README documents SSE, dashboard filtering/favorites, health telemetry, and graceful shutdown; some corresponding app routes are outside the sampled excerpt, so their implementation details are not inferred.

Main entry points: [`src/store.js`](https://github.com/berker00/canli_piyasalar/blob/main/src/store.js) (Rate Store), [`src/socket.js`](https://github.com/berker00/canli_piyasalar/blob/main/src/socket.js) (Socket Client), [`server.js`](https://github.com/berker00/canli_piyasalar/blob/main/server.js) (Runtime Bootstrap), [`src/app.js`](https://github.com/berker00/canli_piyasalar/blob/main/src/app.js) (Web Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Feed Collection"]
  node_server["Runtime Bootstrap<br/>[server.js]"]
  node_config["Runtime Config<br/>[config.js]"]
  node_socket["Socket Client<br/>[socket.js]"]
end

subgraph group_state["Rate State"]
  node_store["Rate Store<br/>[store.js]"]
  node_memory[("Live Rate State<br/>[store.js]")]
end

subgraph group_delivery["HTTP Delivery"]
  node_http["HTTP App<br/>[app.js]"]
  node_api["Price API<br/>[app.js]"]
  node_sse["SSE Stream<br/>[app.js]"]
  node_dashboard["Web Dashboard<br/>[app.js]"]
  node_health["Health Telemetry<br/>[app.js]"]
end

subgraph group_persistence["Persistence"]
  node_writer["Atomic File Flush<br/>[store.js]"]
  node_jsonfile["JSON Snapshot<br/>[altin.json]"]
end

node_feed(("Harem Altın Feed"))
node_clients(("API Consumers"))
node_browser(("Dashboard Users"))
node_favorites[("Browser LocalStorage")]
node_diskclients(("Static File Readers"))

node_server -->|"reads settings"| node_config
node_server -->|"creates"| node_store
node_server -->|"creates and connects"| node_socket
node_server -->|"starts"| node_http
node_config -->|"supplies connection config"| node_socket
node_socket -->|"connects and receives"| node_feed
node_socket -->|"forwards payloads"| node_store
node_store -->|"merges rates"| node_memory
node_store -->|"flushes on interval"| node_writer
node_writer -->|"writes then renames"| node_jsonfile
node_clients -->|"requests prices"| node_api
node_api -->|"reads snapshot"| node_store
node_store -->|"returns snapshot"| node_api
node_browser -->|"opens dashboard"| node_dashboard
node_dashboard -->|"reads initial state"| node_store
node_store -->|"pushes rate updates"| node_sse
node_sse -->|"streams events"| node_browser
node_dashboard -->|"saves favorites"| node_favorites
node_clients -->|"subscribes"| node_sse
node_clients -->|"requests telemetry"| node_health
node_health -->|"reads metrics"| node_store
node_health -->|"reads status"| node_socket
node_diskclients -->|"requests static JSON"| node_http
node_http -->|"serves file fallback"| node_jsonfile

click node_server "https://github.com/berker00/canli_piyasalar/blob/main/server.js"
click node_config "https://github.com/berker00/canli_piyasalar/blob/main/src/config.js"
click node_socket "https://github.com/berker00/canli_piyasalar/blob/main/src/socket.js"
click node_store "https://github.com/berker00/canli_piyasalar/blob/main/src/store.js"
click node_memory "https://github.com/berker00/canli_piyasalar/blob/main/src/store.js"
click node_http "https://github.com/berker00/canli_piyasalar/blob/main/src/app.js"
click node_api "https://github.com/berker00/canli_piyasalar/blob/main/src/app.js"
click node_sse "https://github.com/berker00/canli_piyasalar/blob/main/src/app.js"
click node_dashboard "https://github.com/berker00/canli_piyasalar/blob/main/src/app.js"
click node_health "https://github.com/berker00/canli_piyasalar/blob/main/src/app.js"
click node_writer "https://github.com/berker00/canli_piyasalar/blob/main/src/store.js"
click node_jsonfile "https://github.com/berker00/canli_piyasalar/blob/main/public/tmp/altin.json"

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_server,node_config,node_socket,node_browser toneBlue
class node_store,node_memory,node_favorites toneAmber
class node_http,node_api,node_sse,node_dashboard,node_health,node_clients toneMint
class node_writer,node_jsonfile toneRose
class node_feed,node_diskclients toneIndigo
```

## Components

### Feed Collection

- [Runtime Bootstrap](https://github.com/berker00/canli_piyasalar/blob/main/server.js): `server.js`
- [Runtime Config](https://github.com/berker00/canli_piyasalar/blob/main/src/config.js): `src/config.js`
- [Socket Client](https://github.com/berker00/canli_piyasalar/blob/main/src/socket.js): `src/socket.js`

### Rate State

- [Rate Store](https://github.com/berker00/canli_piyasalar/blob/main/src/store.js): `src/store.js`
- [Live Rate State](https://github.com/berker00/canli_piyasalar/blob/main/src/store.js): `src/store.js`

### HTTP Delivery

- [HTTP App](https://github.com/berker00/canli_piyasalar/blob/main/src/app.js): `src/app.js`
- [Price API](https://github.com/berker00/canli_piyasalar/blob/main/src/app.js): `src/app.js`
- [SSE Stream](https://github.com/berker00/canli_piyasalar/blob/main/src/app.js): `src/app.js`
- [Web Dashboard](https://github.com/berker00/canli_piyasalar/blob/main/src/app.js): `src/app.js`
- [Health Telemetry](https://github.com/berker00/canli_piyasalar/blob/main/src/app.js): `src/app.js`

### Persistence

- [Atomic File Flush](https://github.com/berker00/canli_piyasalar/blob/main/src/store.js): `src/store.js`
- [JSON Snapshot](https://github.com/berker00/canli_piyasalar/blob/main/public/tmp/altin.json): `public/tmp/altin.json`

### Other components

- **Harem Altın Feed**
- **API Consumers**
- **Dashboard Users**
- **Browser LocalStorage**
- **Static File Readers**

## Connections

- Runtime Bootstrap → Runtime Config: reads settings
- Runtime Bootstrap → Rate Store: creates
- Runtime Bootstrap → Socket Client: creates and connects
- Runtime Bootstrap → HTTP App: starts
- Runtime Config → Socket Client: supplies connection config
- Socket Client → Harem Altın Feed: connects and receives
- Socket Client → Rate Store: forwards payloads
- Rate Store → Live Rate State: merges rates
- Rate Store → Atomic File Flush: flushes on interval
- Atomic File Flush → JSON Snapshot: writes then renames
- API Consumers → Price API: requests prices
- Price API → Rate Store: reads snapshot
- Rate Store → Price API: returns snapshot
- Dashboard Users → Web Dashboard: opens dashboard
- Web Dashboard → Rate Store: reads initial state
- Rate Store → SSE Stream: pushes rate updates
- SSE Stream → Dashboard Users: streams events
- Web Dashboard → Browser LocalStorage: saves favorites
- API Consumers → SSE Stream: subscribes
- API Consumers → Health Telemetry: requests telemetry
- Health Telemetry → Rate Store: reads metrics
- Health Telemetry → Socket Client: reads status
- Static File Readers → HTTP App: requests static JSON
- HTTP App → JSON Snapshot: serves file fallback
