# t0b1as/fnd architecture

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

- Interactive diagram: https://gitdiagram.com/t0b1as/fnd
- Repository: https://github.com/t0b1as/fnd

## Overview

Fundus is a decentralized marketplace node for goods, services, certificates, energy tokens, and jobs. A browser request reaches the Go REST API through OpenResty; API handlers serve marketplace operations and publish some records to the peer network. The node also supports replicated file hosting, messaging, wallet identity, blockchain-backed swaps, topology, local LLM analysis, and optional smart-meter input. The README documents the main runtime layout; sampled excerpts confirm API routes, listing persistence and publication, and meter-token publication. Several subsystem links are left out because their callers were not shown.

Main entry points: [`go/internal/api/server.go`](https://github.com/t0b1as/fnd/blob/main/go/internal/api/server.go) (REST API), [`go/internal/meter/reader.go`](https://github.com/t0b1as/fnd/blob/main/go/internal/meter/reader.go) (Smart-meter reader), [`go/internal/p2p/node.go`](https://github.com/t0b1as/fnd/blob/main/go/internal/p2p/node.go) (P2P network), [`go/internal/storage/store.go`](https://github.com/t0b1as/fnd/blob/main/go/internal/storage/store.go) (Marketplace records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["User interface"]
  node_openresty["OpenResty"]
  node_lua_messenger["Messenger UI<br/>[messenger.js]"]
  node_lua_partner["Partner UI<br/>[partner.js]"]
  node_lua_upload["Upload UI<br/>[upload.js]"]
  node_lua_wallet["Wallet UI<br/>[walletauth.js]"]
end

subgraph group_market["Marketplace services"]
  node_api["REST API<br/>[server.go]"]
  node_listings["Listings and orders<br/>[server.go]"]
  node_search["Marketplace search<br/>[search.go]"]
  node_identity["Wallet identity<br/>[identity.go]"]
  node_messenger["Messaging<br/>[messenger.go]"]
  node_partner["Partner profiles<br/>[search.go]"]
  node_swap["FND–SOL swaps"]
end

subgraph group_network["Peer network"]
  node_p2p["P2P network<br/>[node.go]"]
  node_topology["Grid topology<br/>[manager.go]"]
end

subgraph group_ledger["Storage and ledger"]
  node_chain["Blockchain<br/>[blockchain.go]"]
  node_recordstore[("Marketplace records<br/>[store.go]")]
  node_filestore[("Replicated file hosting<br/>[filestore.go]")]
end

subgraph group_nodeops["Node capabilities"]
  node_meter["Smart-meter reader<br/>[reader.go]"]
  node_llm["LLM analysis<br/>[analyzer.go]"]
  node_helper["Privileged helper<br/>[main.go]"]
  node_updater["Node updater<br/>[updater.go]"]
end

node_browser(("Browser"))
node_ollama["Ollama"]

node_browser -->|"requests pages"| node_openresty
node_openresty -->|"proxies requests"| node_api
node_api -->|"routes requests"| node_listings
node_api -->|"writes records"| node_recordstore
node_api -->|"publishes records"| node_p2p
node_meter -->|"stores tokens"| node_recordstore
node_meter -->|"publishes tokens"| node_p2p
node_llm -.->|"analyzes locally"| node_ollama
node_lua_messenger -.->|"runs in"| node_browser
node_lua_partner -.->|"runs in"| node_browser
node_lua_upload -.->|"runs in"| node_browser
node_lua_wallet -.->|"runs in"| node_browser

click node_api "https://github.com/t0b1as/fnd/blob/main/go/internal/api/server.go"
click node_listings "https://github.com/t0b1as/fnd/blob/main/go/internal/api/server.go"
click node_search "https://github.com/t0b1as/fnd/blob/main/go/internal/api/search.go"
click node_identity "https://github.com/t0b1as/fnd/blob/main/go/internal/identity/identity.go"
click node_messenger "https://github.com/t0b1as/fnd/blob/main/go/internal/messenger/messenger.go"
click node_partner "https://github.com/t0b1as/fnd/blob/main/go/internal/partner/search.go"
click node_swap "https://github.com/t0b1as/fnd/blob/main/go/internal/api/swap_orchestrator.go"
click node_p2p "https://github.com/t0b1as/fnd/blob/main/go/internal/p2p/node.go"
click node_topology "https://github.com/t0b1as/fnd/blob/main/go/internal/topology/manager.go"
click node_chain "https://github.com/t0b1as/fnd/blob/main/go/internal/chain/blockchain.go"
click node_recordstore "https://github.com/t0b1as/fnd/blob/main/go/internal/storage/store.go"
click node_filestore "https://github.com/t0b1as/fnd/blob/main/go/internal/filestore/filestore.go"
click node_meter "https://github.com/t0b1as/fnd/blob/main/go/internal/meter/reader.go"
click node_llm "https://github.com/t0b1as/fnd/blob/main/go/internal/llm/analyzer.go"
click node_helper "https://github.com/t0b1as/fnd/blob/main/go/cmd/fundus-helper/main.go"
click node_updater "https://github.com/t0b1as/fnd/blob/main/go/internal/update/updater.go"
click node_lua_messenger "https://github.com/t0b1as/fnd/blob/main/lua/static/messenger.js"
click node_lua_partner "https://github.com/t0b1as/fnd/blob/main/lua/static/partner.js"
click node_lua_upload "https://github.com/t0b1as/fnd/blob/main/lua/static/upload.js"
click node_lua_wallet "https://github.com/t0b1as/fnd/blob/main/lua/static/walletauth.js"

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_openresty,node_lua_messenger,node_lua_partner,node_lua_upload,node_lua_wallet,node_browser toneBlue
class node_api,node_listings,node_search,node_identity,node_messenger,node_partner,node_swap toneAmber
class node_p2p,node_topology toneMint
class node_chain,node_recordstore,node_filestore toneRose
class node_meter,node_llm,node_helper,node_updater,node_ollama toneIndigo
```

## Components

### User interface

- **OpenResty**
- [Messenger UI](https://github.com/t0b1as/fnd/blob/main/lua/static/messenger.js): `lua/static/messenger.js`
- [Partner UI](https://github.com/t0b1as/fnd/blob/main/lua/static/partner.js): `lua/static/partner.js`
- [Upload UI](https://github.com/t0b1as/fnd/blob/main/lua/static/upload.js): `lua/static/upload.js`
- [Wallet UI](https://github.com/t0b1as/fnd/blob/main/lua/static/walletauth.js): `lua/static/walletauth.js`

### Marketplace services

- [REST API](https://github.com/t0b1as/fnd/blob/main/go/internal/api/server.go): `go/internal/api/server.go`
- [Listings and orders](https://github.com/t0b1as/fnd/blob/main/go/internal/api/server.go): `go/internal/api/server.go`
- [Marketplace search](https://github.com/t0b1as/fnd/blob/main/go/internal/api/search.go): `go/internal/api/search.go`
- [Wallet identity](https://github.com/t0b1as/fnd/blob/main/go/internal/identity/identity.go): `go/internal/identity/identity.go`
- [Messaging](https://github.com/t0b1as/fnd/blob/main/go/internal/messenger/messenger.go): `go/internal/messenger/messenger.go`
- [Partner profiles](https://github.com/t0b1as/fnd/blob/main/go/internal/partner/search.go): `go/internal/partner/search.go`
- [FND–SOL swaps](https://github.com/t0b1as/fnd/blob/main/go/internal/api/swap_orchestrator.go): `go/internal/api/swap_orchestrator.go`

### Peer network

- [P2P network](https://github.com/t0b1as/fnd/blob/main/go/internal/p2p/node.go): `go/internal/p2p/node.go`
- [Grid topology](https://github.com/t0b1as/fnd/blob/main/go/internal/topology/manager.go): `go/internal/topology/manager.go`

### Storage and ledger

- [Blockchain](https://github.com/t0b1as/fnd/blob/main/go/internal/chain/blockchain.go): `go/internal/chain/blockchain.go`
- [Marketplace records](https://github.com/t0b1as/fnd/blob/main/go/internal/storage/store.go): `go/internal/storage/store.go`
- [Replicated file hosting](https://github.com/t0b1as/fnd/blob/main/go/internal/filestore/filestore.go): `go/internal/filestore/filestore.go`

### Node capabilities

- [Smart-meter reader](https://github.com/t0b1as/fnd/blob/main/go/internal/meter/reader.go): `go/internal/meter/reader.go`
- [LLM analysis](https://github.com/t0b1as/fnd/blob/main/go/internal/llm/analyzer.go): `go/internal/llm/analyzer.go`
- [Privileged helper](https://github.com/t0b1as/fnd/blob/main/go/cmd/fundus-helper/main.go): `go/cmd/fundus-helper/main.go`
- [Node updater](https://github.com/t0b1as/fnd/blob/main/go/internal/update/updater.go): `go/internal/update/updater.go`

### Other components

- **Browser**
- **Ollama**

## Connections

- Browser → OpenResty: requests pages
- OpenResty → REST API: proxies requests
- REST API → Listings and orders: routes requests (evidence: `go/internal/api/server.go`)
- REST API → Marketplace records: writes records (evidence: `go/internal/api/server.go`)
- REST API → P2P network: publishes records (evidence: `go/internal/api/server.go`)
- Smart-meter reader → Marketplace records: stores tokens
- Smart-meter reader → P2P network: publishes tokens
- LLM analysis → Ollama: analyzes locally
- Messenger UI → Browser: runs in
- Partner UI → Browser: runs in
- Upload UI → Browser: runs in
- Wallet UI → Browser: runs in
