I am looking for a better way to create images like the following:

I want to make diagram with blocks and ports (the things with Greek letters) so that I can do the following:
- Not have to space blocks manually (automatically take account of the ports and their width in spacing the blocks).
- Automatically change the width and height of blocks so that they're wide enough to hold all their ports.
- Change the shape/color of ports in a way that's aware of their location. (i.e. make the color of the side of a port that opposite the block red with a style, or a NOT circle that an arrow goes into.)
- Not have nested
tikzpictureenvironments constantly (it's annoying and there's got to be a better way. This will become particularly salient when I get to stuff where ports will have ports of their own. (ports can have modifiers and the like which change their meaning)).
Right now my code for creating diagrams like the above is very hacky and manual and as the diagrams I need grow larger, it's become progressively harder. I'm mainly looking for examples or advice on making more modular and composable structures out of TikZ, as well as advice on code style.
\documentclass[tikz,crop]{standalone} \usepackage{amssymb,amsmath} \usepackage{tikz} \usetikzlibrary{ calc, positioning, shapes.arrows% } \begin{document} \begin{tikzpicture}[remember picture] \tikzstyle{component}=[rectangle ,draw ,node distance =1.5cm ,minimum height = 0.8cm] \tikzstyle{port side}=[node distance=0 cm ,outer sep=-0.2 pt ,inner sep=0pt] \tikzstyle{port}=[rectangle ,draw ,node distance=0.1 cm, ,outer sep=0 pt ,minimum height = 0.6cm ,minimum width = 0.6cm ,inner sep = 3pt] \node[component] (blk1) {Block 1}; \node[port side,right=of blk1] (blk1.right) { \begin{tikzpicture} \node[port] (alp) {$\alpha$}; \end{tikzpicture} }; \node[port side,above=of blk1] (blk1.above) { \begin{tikzpicture} \node[port] (bet1) {$\beta$}; \end{tikzpicture} }; \node[component,right=of blk1] (blk2) {Block 2}; \node[port side,left=of blk2] (blk2.left) { \begin{tikzpicture} \node[port] (del) {$\delta$}; \end{tikzpicture} }; \node[port side,above=of blk2] (blk2.above) { \begin{tikzpicture} \node[port] (bet2) {$\beta$}; \end{tikzpicture} }; \node[port side,right=of blk2] (blk2.right) { \begin{tikzpicture} \node[port] (gam) {$\gamma$}; \end{tikzpicture} }; \node[component,right=of blk2] (blk3) {Block 3}; \node[port side,left=of blk3] (blk3.left) { \begin{tikzpicture} \node[port] (eps) {$\epsilon$}; \end{tikzpicture} }; \node[port side,above=of blk3] (blk3.above) { \begin{tikzpicture} \node[port] (bet3) {$\beta$}; \node[port,right=of bet3] (eta) {$\eta$}; \end{tikzpicture} }; \node[port side,right=of blk3] (blk3.right) { \begin{tikzpicture} \node[port] (thet) {$\theta$}; \end{tikzpicture} }; \node[component,right=of blk3] (blk4) {Block 4}; \node[port side,left=of blk4] (blk4.left) { \begin{tikzpicture} \node[port] (iota) {$\iota$}; \end{tikzpicture} }; \node[port side,above=of blk4] (blk4.above) { \begin{tikzpicture} \node[port] (kap) {$\kappa$}; \end{tikzpicture} }; \draw[<-] (alp.east) -- (del.west); \draw[<-] (gam.east) -- (eps.west); \draw[<-] (thet.east) -- (iota.west); \draw[rounded corners,solid,<-] (bet1.north) |- +(-1cm,0.2cm); \draw[rounded corners,solid,<-] (bet2.north) |- +(-4cm,0.2cm); \draw[rounded corners,solid,<-] (bet3.north) |- +(-4.5cm,0.2cm); \draw[dashed] ($(bet1.north)+(-1,0.2cm)$) -- +(-.5cm,0cm); \draw[rounded corners,solid,<-] (eta.north) |- +(-8.55cm,0.4cm); \draw[dashed] ($(eta.north)+(-8.55cm,0.4cm)$) -- +(-.5cm,0cm); \draw[rounded corners,solid,<-] (kap.north) |- +(1cm,0.2cm); \draw[dashed] ($(kap.north)+(1cm,0.2cm)$) -- +(.5cm,0cm); \end{tikzpicture} \end{document}