tikz add tag
Anonymous 1535
How can I start off drawing the following diagram using Tikz or any other suitable package?![Screenshot 2020-12-20 at 13.18.28.png](/image?hash=9e4ee284d254688dcb4ae862b599bd4593c8e01ea4551c724d65aeb6b6341ac9)
Top Answer
marmot
Well, this is a start. I think a matrix is a good choice, but then usually the problem is that the nodes are not the same size unless one guesses the right one. Yet `eqparbox` can be used to solve this issue. The rest is positioning and using a few more tricks. I think the only remaining task is to add a few edges.
```
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,calc,fit,matrix,positioning,shapes.arrows}
\usepackage{eqparbox}
\newbox\eqnodebox
\tikzset{eq/.style={execute at begin
    node={\setbox\eqnodebox=\hbox\bgroup},
    execute at end node={\egroup\eqmakebox[#1][c]{\copy\eqnodebox}}},
    eq/.default=A}
\begin{document}
\begin{tikzpicture}[font=\sffamily,nodes={align=center},>=latex]
 \matrix[matrix of nodes,column sep=1ex,inner sep=0pt,
 	cells={nodes={eq=A,inner sep=2pt,inner xsep=1ex,
	minimum height=12em,fill=violet,text=white}}] (P){
	{$<$your code$>$}
	 & {\begin{tabular}{@{}c@{}}
	Single\\ Java Script\\ Thread
	\end{tabular}}\\
	};
 %
 \path[nodes={inner sep=0pt}] let \p1=($(P.east)-(P.west)$) in
	 node[above=1em of P,fill=violet!20,draw,dashed,minimum height=1.5em,minimum
	 width=\x1] (Q){}
	 node[above=3em of Q,fill=violet,draw,text=white,minimum height=2em,minimum
	 width=\x1] (R){Incoming Requests};  
 %
 \path ([xshift=8em]P.south east) 
   node[matrix of nodes,anchor=south west,row sep=1ex,inner sep=0pt,
 	cells={nodes={eq=B,inner sep=2pt,inner xsep=1ex,minimum height=2.8em}},
	every even row/.style={nodes={fill=orange!20,text=orange,draw=orange}},
	every odd row/.style={nodes={fill=orange,text=white,draw=orange}},
	] (M){
	Event loop\\
	Handle Event Callbacks\\[2em]
	Worker Pool\\ 
	Do The Heavy Lifting\\
	};
  %
  \node[single arrow,fill=orange,minimum width=2em,
  	minimum height=2em,single arrow head extend=1ex,right=1ex of M-3-1] (ar){};
  \node[fill=yellow,draw=orange,inner xsep=1em,right=1ex of ar] {Different\\ Threads!};
  % 
  \begin{scope}[semithick,->]
   \path (P) -- node[draw,fill=orange!80!gray,text=white,inner sep=1ex](fs){``fs''} (M);
   \draw[orange] (P-1-2.east) -- ++ (1ex,0) |- 
  	 node[pos=0.75,above] {Start}(M-1-1);
   \draw[orange] (P-1-2.east) -| ++ (0.8ex,-2em) -| (fs);
   \draw[orange] (M-3-1.north) -- ++ (0,1em) coordinate(aux)
    -- (ar|-aux) |- node[pos=0.25,right] {Trigger Callback} (M-1-1.east);
   \draw[orange!80!gray] (fs) -- node[pos=0.2,above right]{Send To} (M-3-1); 
   \foreach \X in {-170,-90,-10}
   {\draw[violet!20] (R.\X) -- (Q.north); }
  \end{scope}
\end{tikzpicture}
\end{document}
```
![Screen Shot 2020-12-20 at 12.40.36 PM.png](/image?hash=dc1964a601a0dbc0621f0a891b36d26c804977c3f5846c862f45a108dc1003fa)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.