{"id":15548590,"url":"https://github.com/mongodben/erb-realm-notes","last_synced_at":"2025-11-12T02:22:37.285Z","repository":{"id":132733603,"uuid":"419436726","full_name":"mongodben/erb-realm-notes","owner":"mongodben","description":null,"archived":false,"fork":false,"pushed_at":"2021-11-03T14:07:45.000Z","size":3384,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-24T18:13:51.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mongodben.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["electron-react-boilerplate","amilajack"],"patreon":"amilajack","open_collective":"electron-react-boilerplate-594"}},"created_at":"2021-10-20T18:00:08.000Z","updated_at":"2021-11-03T14:07:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"31ae87d4-fb1a-4fb1-bf0b-31d0115f4640","html_url":"https://github.com/mongodben/erb-realm-notes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mongodben/erb-realm-notes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodben%2Ferb-realm-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodben%2Ferb-realm-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodben%2Ferb-realm-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodben%2Ferb-realm-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodben","download_url":"https://codeload.github.com/mongodben/erb-realm-notes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodben%2Ferb-realm-notes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283962104,"owners_count":26923739,"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","status":"online","status_checked_at":"2025-11-12T02:00:06.336Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-02T13:22:09.073Z","updated_at":"2025-11-12T02:22:37.268Z","avatar_url":"https://github.com/mongodben.png","language":"TypeScript","funding_links":["https://github.com/sponsors/electron-react-boilerplate","https://github.com/sponsors/amilajack","https://patreon.com/amilajack","https://opencollective.com/electron-react-boilerplate-594"],"categories":[],"sub_categories":[],"readme":"# MD Notes\n\nThis application lets you take notes in [Markdown](https://www.markdownguide.org/) and preview them.\n\nNotes are saved to the local device and backed up to the cloud.\n\nThe application is available on Mac, Linux, and Windows.\n\n## Technologies Used\n\nMD Notes is an [Electron](https://www.electronjs.org/) and [React](https://reactjs.org/) application, bootstrapped with [Electron React Boilerplate](https://electron-react-boilerplate.js.org/). It also uses MongoDB Realm as a local database and auth provider. All code is written in [TypeScript](https://www.typescriptlang.org/).\n\n## Development\n\n### Getting Started\n\nTo get started, run:\n\n```shell\ngit clone https://github.com/mongodben/erb-realm-notes.git\ncd erb-realm-notes\nyarn install\ncd release/app\nyarn install # installs native dependencies not transpiled by webpack, including realm\ncd ../..\nyarn start \n```\n\nNotes:\n\n* The renderer process has hot refresh, but the main process requires killing and restarting the process for code updates\n\n### Application Architecture\n\nMD Notes roughly follows a model-view-controller design pattern. The component parts are:\n\n* **Model**: Realm database\n* **View**: React frontend in the Electron Renderer Process\n* **Controller**: NodeJS with the Realm JS SDK in the Electron Main Process\n\nCommunication between the View and Controller is performed using [Electron's inter-process communication (IPC)](https://www.electronjs.org/docs/latest/glossary#ipc) functionality. Communication between the renderer and Realm is *stateless*, initiated by IPC calls from the renderer (similar to a client making HTTP calls to a server).\n\n#### Design Considerations\n\nThe application's use of IPC for stateless communication between the renderer and main is fairly different from standard Electron application design, in which most of the data is handled in the renderer process. It's also fairly different from standard Realm apps, where data is handled in the client (in this case the client would be the renderer).\n\nThe reason that the IPC approach was chosen was to accelerate development. Weird errors occurred when using Realm in the renderer process, and rather than debugging said errors, it was decided to forego the debugging by calling Realm from the main process. This decision was made largely because the primary goal of the project was for the developer to practice with the Realm JS SDK, rather than build the optimal application.\n\nIn the future, the application may be refactored to use Realm from the Renderer process.\n\n### Using Realm\n\n**Note:** Before reading this section, you should be familiar with the basic architecture of an Electron application, including the **Renderer** and **Main** processes. MD Notes makes heavy use of Electron's IPC functionality, and having a basic understanding of it is important to a productive developer experience. With this being said, most of the underlying logic is abstracted away by helper functions.\n\nTo communicate between the renderer and Realm, you must do the following:\n1. Create a function in the Main process for handling Realm data\n2. Add the function to known IPC call list\n3. Call the function from the Renderer\n\n#### 1. Create a function in the Main process for handling Realm data\n\nCreate a function to handle Realm data in the Main process folder `src/main/realm`.\n\nThe function should have the arguments:\n\n```ts\nfunction myRealmFunction(app: Realm.App, realm: RealmWrapper, args: any[]): any {\n// ...my code\n}\n```\n\nNotes:\n\n* If the function doesn't have this shape, TypeScript throws an error.\n* If you're not using any of the arguments, replace them with `_`, `__` ...\n* The `app` and `realm` arguments are invoked by `ipcMain.handle('realmEvent', ...)`. \n\n#### 2. Add function to known IPC call list\n\nAfter creating the realm Function, add it to the list of known IPC calls. This list is found in the file `src/main/realm/ipcCalls.ts`. Only Realm IPC calls added to this list can be invoked from the Renderer process without writing additional handler code.\n\nIn `src/main/realm/ipcCalls.ts`:\n\n```ts\nimport myRealmFunction from './path/to/file'\n\nconst realmIpcCalls: Map = {\n  // other Realm functions\n  myRealmFunction,\n  // other Realm functions\n};\n\nexport default realmIpcCalls;\n```\n\n#### 3. Call the function from the Renderer\n\nFrom within the Renderer process, call the Realm function in the main process using the helper method `ipcRendererHandler` defined in `src/renderer/ipc/index/ts`. \n\nThe function has the following shape:\n\n```ts\nasync function ipcRendererHandler(event: string, ...args: any[]): Promise\u003cany\u003e {\n\n```\n\nTo call the function:\n\n```ts\nconst res = await ipcRendererHandler('myRealmFunction', foo, bar);\n```\n\nNotes:\n\n* The function is async, and should be used with await/Promises\n* The event parameter should match the name of the Realm function defined in the main process and included in ipcCalls.ts.\n\n## Contributors\n\nHacked together by [Ben Perlmutter](https://github.com/mongodben) in an attempt to learn how to use the MongoDB Realm JS SDK.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodben%2Ferb-realm-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodben%2Ferb-realm-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodben%2Ferb-realm-notes/lists"}