{"id":17148437,"url":"https://github.com/aholstenson/ataraxia","last_synced_at":"2025-08-20T04:32:20.200Z","repository":{"id":38375082,"uuid":"110948824","full_name":"aholstenson/ataraxia","owner":"aholstenson","description":"P2P messaging over mesh networks for NodeJS and browsers","archived":false,"fork":false,"pushed_at":"2023-03-06T03:36:29.000Z","size":4249,"stargazers_count":76,"open_issues_count":15,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-09T17:50:15.360Z","etag":null,"topics":["mesh-networks","messaging","p2p","p2p-network","peer-to-peer","services"],"latest_commit_sha":null,"homepage":"https://aholstenson.github.io/ataraxia/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aholstenson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-16T09:07:23.000Z","updated_at":"2024-11-25T05:28:09.000Z","dependencies_parsed_at":"2024-06-18T20:08:02.835Z","dependency_job_id":"f8e87da9-bed7-44c9-aede-d18702a1646f","html_url":"https://github.com/aholstenson/ataraxia","commit_stats":{"total_commits":322,"total_committers":4,"mean_commits":80.5,"dds":"0.021739130434782594","last_synced_commit":"12c3fe9a789c2fe8b825c1e866d3504d0af7437e"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fataraxia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fataraxia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fataraxia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fataraxia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aholstenson","download_url":"https://codeload.github.com/aholstenson/ataraxia/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230394228,"owners_count":18218707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mesh-networks","messaging","p2p","p2p-network","peer-to-peer","services"],"created_at":"2024-10-14T21:28:35.089Z","updated_at":"2024-12-19T07:06:28.506Z","avatar_url":"https://github.com/aholstenson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"460\" src=\"https://raw.githubusercontent.com/aholstenson/ataraxia/master/docs/mesh-example.svg\"\u003e\n\u003c/p\u003e\n\n\u003c/p\u003e\n\n# Ataraxia\n\n[![npm version](https://img.shields.io/npm/v/ataraxia)](https://www.npmjs.com/package/ataraxia)\n[![Build Status](https://github.com/aholstenson/ataraxia/actions/workflows/ci.yml/badge.svg)](https://github.com/aholstenson/ataraxia/actions/workflows/ci.yml)\n[![Typedoc](https://img.shields.io/badge/typedoc-available-%23fff)](https://aholstenson.github.io/ataraxia)\n\nConnect nodes, such as NodeJS-apps or browsers, together and send messages \nbetween them. Provides a mesh network with peer-to-peer messaging, allowing\nmessages to be routed between nodes that are not directly connected with each\nother.\n\n* Instances can **send and receive messages** from other instances\n* Partially connected **mesh network**, messages will be routed to their target if needed\n* **Authentication support**, anonymous and shared secret authentication available in core\n* **Encryption**, most transports establish an encrypted connection by default\n* **RPC**,  register and consume services anywhere in the network, supports method call and events, via [ataraxia-services](https://github.com/aholstenson/ataraxia/tree/master/packages/services)\n* Support for **different transports**\n  * [Machine-local transport](https://github.com/aholstenson/ataraxia/tree/master/packages/local), connect to NodeJS-instances on the local machine \n  * [TCP-based transport](https://github.com/aholstenson/ataraxia/tree/master/packages/tcp) with customizable discovery of peers, [mDNS](https://aholstenson.github.io/ataraxia/classes/ataraxia_tcp.tcppeermdnsdiscovery.html) included for discovery on the local network\n  * Websockets, both [server-side](https://github.com/aholstenson/ataraxia/tree/master/packages/ws-server) \n    and [client-side](https://github.com/aholstenson/ataraxia/tree/master/packages/ws-client) variants \n  * [Hyperswarm](https://github.com/aholstenson/ataraxia/tree/master/packages/hyperswarm)\n    to find and connect to peers over the public Internet\n\n## Getting started\n\nTo setup your own network install the `ataraxia` package and at least one\ntransport such as `ataraxia-tcp`:\n\n```\n$ npm install ataraxia ataraxia-tcp\n```\n\nA network can then be created and joined:\n\n```javascript\nimport { Network, AnonymousAuth } from 'ataraxia';\nimport { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';\n\nconst net = new Network({\n  name: 'ataraxia-example',\n  transports: [\n    new TCPTransport({\n      discovery: new TCPPeerMDNSDiscovery(),\n      authentication: [\n        new AnonymousAuth()\n      ]\n    })\n  ]\n});\n\nnet.onNodeAvailable(node =\u003e {\n  console.log('A new node is available:', node.id);\n  node.send('hello')\n    .catch(err =\u003e console.log('Unable to send hello', err));\n});\n\nnet.onMessage(msg =\u003e {\n  console.log('A message was received', msg.type, 'with data', msg.data, 'from', msg.source.id);\n});\n\n// Join the network\nawait net.join();\n```\n\n## Usage\n\nThe package [ataraxia](https://github.com/aholstenson/ataraxia/tree/master/packages/core) \ncontains the main code used to setup and join a [network](https://aholstenson.github.io/ataraxia/classes/ataraxia.network.html).\n\nWhen a network is joined [nodes](https://aholstenson.github.io/ataraxia/interfaces/ataraxia.node.html)\nwill become available and unavailable, opening up for the ability to send and\nreceive messages from them.\n\n### Machine-local transport with TCP transport\n\nThis example creates a network where instances on the same machine connect to\neach other locally first and then elects one instance to handle connections\nto other machines on the same physical network.\n\n```javascript\nimport { Network, AnonymousAuth } from 'ataraxia';\nimport { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';\nimport { MachineLocalTransport } from 'ataraxia-local';\n\n// Setup a network\nconst net = new Network({\n  name: 'name-of-your-app-or-network'\n});\n\nnet.addTransport(new MachineLocalTransport([\n  onLeader: () =\u003e {\n    /*\n    * The leader event is emitted when this instance becomes the leader\n    * of the machine-local network. This instance will now handle\n    * connections to other machines in the network.\n    */\n    net.addTransport(new TCPTransport({\n      discovery: new TCPPeerMDNSDiscovery(),\n\n      authentication: [\n        new AnonymousAuth()\n      ]\n    }));\n  }\n]);\n\nawait net.join();\n```\n\n### Support for services\n\nServices are supported via `ataraxia-services`, where objects can be registered\nand functions on them called remotely:\n\n```javascript\nimport { Services, ServiceContract, stringType } from 'ataraxia-services';\n\nconst net = ... // setup network with at least one transport\n\nconst services = new Services(net);\n\nservices.onAvailable(service =\u003e console.log(service.id, 'is now available'));\nservices.onUnavailable(service =\u003e console.log(service.id, 'is no longer available'));\n\n// Join the network\nawait net.join();\n\n// Join the services on top of the network\nawait services.join();\n\n// Use contracts to describe services\nconst EchoService = new ServiceContract()\n  .defineMethod('echo', {\n    returnType: stringType,\n    parameters: [\n      {\n        name: 'message',\n        type: stringType\n      }\n    ]\n  });\n\n// Easily register and expose services to other nodes\nservices.register('echo', EchoService.implement({\n  echo(message) {\n    return Promise.resolve(message);\n  }\n}));\n\n// Consume a service registered anywhere, local or remote\nconst echoService = services.get('echo');\nif(echoService.available) {\n  // Call methods\n  await echoService.call('echo', 'Hello world');\n  \n  // Or create a proxy for a cleaner API\n  const proxied = echoService.as(EchoService);\n  await proxied.echo('Hello world');\n}\n```\n\n## Contributing\n\nThink this project is useful? Reporting issues, asking for clarification and\nPRs are greatly appreciated.\n\n### PRs\n\nIf you want to contribute code changes the way to do so is via PRs. For new\nfeatures open an issue first that the PR can be tied to.\n\n1. Fork the project\n2. Create a feature branch (`git checkout -b feature/cool-feature`)\n3. Work on your changes\n4. Push your changes (`git push origin feature/cool-feature`)\n5. Open a pull request\n\n### Working with the code\n\nThis project uses [Lerna](https://lerna.js.org/) together with\n[Yarn](https://yarnpkg.com/) to manage several packages. You'll need to install\nat least Yarn 1.x to work with the code.\n\nWhen checking out the code run `yarn install` and `npx lerna boostrap` to get\nstarted.\n\nCommit messages should follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)\nspecification.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faholstenson%2Fataraxia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faholstenson%2Fataraxia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faholstenson%2Fataraxia/lists"}