Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing weird things with D2 #1841

Open
zekenie opened this issue Feb 16, 2024 · 3 comments
Open

Doing weird things with D2 #1841

zekenie opened this issue Feb 16, 2024 · 3 comments

Comments

@zekenie
Copy link

zekenie commented Feb 16, 2024

I have some ideas for slightly unconventional use cases for D2 and I'm looking for feedback. For example, I think D2 could make a quite AI-enabled prototyping environment for a sort of single-file http server.

Imagine the following D2 example
image

http: {
  users: {
    sign_up
  }

  tasks: {
    create
    assign
    complete
    defer
  }
}

# creates a user
http.users.sign_up -> users

# ...
http.tasks.* -> tasks

tasks: {
  shape: sql_table
  id: int {constraint: primary_key}
  last_updated: timestamp with time zone
  assignee_id: int {constraint: foreign_key}
  state: string
}

users: {
  shape: sql_table
  id: int {constraint: primary_key}
  name: timestamp with time zone
  email: int {constraint: foreign_key}
}

tasks -> users

Now imagine you could run

$ some-magic ./this-file.d2 --port 8080

and have a fully running HTTP server, backed by sqlite or something, that would do more or less what your diagram described. If you add in the possibility that you could make comments processed by gen-ai, it could get pretty interesting.

I'm interested in hacking on this on a weekend project some time in the next few months. What's getting in the way for me is understanding how I can parse D2. I don't want to write my own parser. I'm not a go expert. I'd love some help understanding the prior art and how feasible this idea is.

@cyborg-ts cyborg-ts added this to D2 Feb 16, 2024
@andrewh
Copy link

andrewh commented Feb 21, 2024

I'm not on this project but a prerequisite is probably understanding a bit more about the D2 parser :) If that means learning a bit more Go, that's an entry point.

Disregarding gen-ai for now, maybe a good short term goal is to compile D2 into a target that runs the services you want? You can do that by any quick and dirty means you like, you don't necessarily need to use the Go parser.

I like the idea, it just needs a bit more legwork.

@zekenie
Copy link
Author

zekenie commented Feb 21, 2024

I've been thinking about it and i think if i can understand a json structure I could get out of the parser, then, i could do a lot of the work and treat the go/parser part as a solvable problem.

I also was thinking about it and the d2 spec doesn't quite have enough information. It's so close, though. For example with the database tables, i can't tell which column points to which table. I know that two tables are related, and I know that a column is a foreign key, but i don't know which col points to which table. i might be able to derive it from the name in some cases....

I almost wonder if I should treat D2 as an inspiration for a diagrammable prototype DSL, instead of thinking of it as the literal DSL i want. Like maybe i make a new DSL that can compile to D2 but that I have more control over.

@andrewh
Copy link

andrewh commented Feb 21, 2024

Which spec are you looking at? I had a quick search and couldn't find it.

Since this project has goals around extensibility, a JSON representation from the parser doesn't seem too far-fetched.

Happy to help as I'm keen to learn more about D2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants