{"id":23391458,"url":"https://github.com/ahrefs/atdgen-workshop-starter","last_synced_at":"2025-04-11T09:59:27.252Z","repository":{"id":48650010,"uuid":"176553700","full_name":"ahrefs/atdgen-workshop-starter","owner":"ahrefs","description":"Starter project for ReasonConf atdgen workshop","archived":false,"fork":false,"pushed_at":"2021-07-15T20:58:41.000Z","size":156,"stargazers_count":16,"open_issues_count":3,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-06T06:36:32.791Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ahrefs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-19T16:21:13.000Z","updated_at":"2022-02-07T08:47:07.000Z","dependencies_parsed_at":"2022-09-11T01:01:36.923Z","dependency_job_id":null,"html_url":"https://github.com/ahrefs/atdgen-workshop-starter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fatdgen-workshop-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fatdgen-workshop-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fatdgen-workshop-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fatdgen-workshop-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahrefs","download_url":"https://codeload.github.com/ahrefs/atdgen-workshop-starter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248371965,"owners_count":21093132,"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":[],"created_at":"2024-12-22T04:17:36.771Z","updated_at":"2025-04-11T09:59:27.234Z","avatar_url":"https://github.com/ahrefs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Atdgen Workshop Starter Project\n\n## Goal\n\nLearn about `atdgen` and how it automates the generation of encoders / decoders to make sure different parts of an application stay type safe. To do so, a small server-client app created with Node.js (via `bs-express`) and ReasonReact is updated through a series of milestones.\n\n## Repo overview\n\n- `bin`: contains the `atdgen` executable, compiled to JavaScript\n- `shared`: contains the shared types between client and server\n- `src_client`: a ReasonReact app that will be used to visualize the obtained data in the browser\n- `src_server`: a server that uses `bs-express` . It exposes an API endpoint (`/refdomains`) that the ReasonReact app in `src_client` will use to fetch data. It includes a file `refdomains.json` with some demo data that represents [referring domains](https://ahrefs.com/api/documentation/refdomains).\n\n## Getting started\n\n    cd atdgen-workshop-starter\n\n    # Can use npm too\n    yarn install\n\n    # Runs the bsb watcher to compile the code on change\n    yarn start\n\n    # In a separate terminal, start the API and static server\n    yarn server\n\nNow, open your browser in [`http://localhost:8000/`](http://localhost:8000/), you should see a table rendered.\n\n## Suggested approach\n\n### Milestone 1: Use bs-json to encode/decode data\n\n1. Start the server by running `yarn server` (or `npm run server`)\n2. Write encoders and decoders for `Refdomain.t` in `shared/Refdomain.re`\n3. In `src_client/RefdomainsTable.re` show the data fetched on the UI\n\n### Milestone 2: Automate encoders \u0026 decoders generation with atdgen\n\nBefore starting, read the [\"2-minutes intro to atdgen\"](https://github.com/ahrefs/atdgen-workshop-starter/blob/master/INTRO.md) documentation.\n\n1. Remove `bs-json` from the package and `bsconfig.json`\n2. Add the atdgen runtime as dependency: `yarn add @ahrefs/bs-atdgen-codec-runtime`. This runtime is what will allow later to call functions like `Atdgen_codec_runtime.Decode.decode` from the server and client.\n3. Replace [RefDomains.re](https://github.com/ahrefs/atdgen-workshop-starter/blob/master/shared/Refdomains.re) with a new `refdomains.atd` file, based on the types in `Refdomain.re` from milestone 1 (you can see the `examples` folder for a reference).\n4. Use atdgen to generate the encoders and decoders automatically\n   1. `node bin/atdgen.js -t shared/refdomains.atd` to generate the types\n   2. `node bin/atdgen.js -bs shared/refdomains.atd` to generate the functions\n5. Use the generated `Refdomains_bs` module to replace the calls to `Refdomains.decodeMain` and `Refdomains.encodeMain`\n\n### Milestone 3: Keep code in sync through ATD generated types\n\n1. Change `lastVisited` from `string` to `date`. You will have to use the [\"custom wrappers\"](https://atd.readthedocs.io/en/latest/atdgen.html?highlight=wrap#using-a-custom-wrapper) feature from atdgen.\n\n2. Change `domain_rating` to be a variant, with three values:\n  - `Poor`: if domain rating is \u003c 33\n  - `Average`: if domain rating is \u003e 33 and \u003c 66\n  - `Good`: if domain rating is \u003e 66\n\n**### Stretch goals**\n\n- Use atdgen to encode / decode the `stats` field\n- Wrap the decoding operations on the server with `Belt.Result` types and use atdgen to pass that information to the client\n- Show colors for each of the three values of the variant `DomainRating`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Fatdgen-workshop-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahrefs%2Fatdgen-workshop-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Fatdgen-workshop-starter/lists"}