TITLE: Is it useful to view magmas as diagrams?
QUESTION [8 upvotes]: I am new to category theory so please forgive me if this is a silly question.
Classically, a magma is usually defined as an ordered pair $(M,*)$ where

$M$ is a set, and
$*$ is a binary operation on $M$.

Here's another point of view. A magma can be viewed as a diagram in the category $\mathsf{Set}$, whose scheme consists of two objects, $A$ and $B$, and three morphisms, $f,g,h : A \rightarrow B$, as well as the identity morphisms, such that

The two objects $A$ and $B$ are labeled $M^2$ and $M$ respectively, and
Two of the morphisms $f,g,h : A \rightarrow B$, are labeled by the natural projection maps $\pi_0,\pi_1 : M^2 \rightarrow M$, with the remaining morphism labeled by the composition map $* : M^2 \rightarrow M$.

For precision, lets call diagrams of this kind magma diagrams.
My general question: Does this idea go anywhere?
A few specific questions...

Are the natural transformations between magma diagrams precisely the usual magma homomorphisms? I'm sorry if this is a trivial question but my intuition for these sorts of things does not yet exist.
How to define things like "The magma diagram $M$ is a monoid," for example? And would it be better to view a monoid as a particular kind of magma diagram, or would a monoid be a different shape diagram altogether?

REPLY [7 votes]: Yes, it does! In the category-theoretic approach to formal logic, models of theories are usually some sort of functor, and theories themselves are usually made into a category of some sort, possibly together with additional conditions.
An approach that is convenient is using sketches. A sketch is a category together with a selection of cones and cocones that are meant to be limits and colimits; so, a model of a sketch is a functor that takes those cones and cocones and maps them to limits and colimits in the target category. (and the morphisms of models are indeed the natural transformations between such functors)
(note how easily this approach lets you define models in categories other than $\mathbf{Set}$!)
e.g. your suggestion about magmas is exactly this. We take the category of the sketch (see wikipedia or ncatlab) to be the one presented by the graph
$$ M^2 \begin{matrix}\xrightarrow{p_1}\\\xrightarrow{p_2}\\\xrightarrow{\mu}\end{matrix} M$$
and we specify that the cone
$$ M \xleftarrow{p_1} M^2 \xrightarrow{p_2} M $$
should be a limit. A model of this sketch in $\mathbf{Set}$, then, is exactly what you described.
For a monoid, though, we want a different sketch. Also, we should take the more algebraic definition of monoid, where there is a constant $i$ satisfying the axioms of a multiplicative unit, rather than the existential assertion of "there exists a multiplicative unit".
The usual sketch for a monoid needs four objects: $M^0, M^1, M^2, M^3$. We include arrows $M^0 \xrightarrow{i} M^1$ for the identity, and $M^2 \xrightarrow{\mu} M^1$ for the product. But our category also has a commutative diagram
$$\begin{matrix} M^3 & \xrightarrow{\mu \times 1_M}& M^2
\\ \downarrow{1_M \times \mu} & & \downarrow{\mu}
\\ M^2 &\xrightarrow{\mu}& M^1 \end{matrix}$$
and similarly, two other diagrams that express the axioms for the multiplicative unit must also commute.
Recall that we can present a category by specifying a graph and taking the free category on that graph, then specifying a set of equations (in the form of commutative diagrams, if we like!) and modding out by the congruence relation that they generate. So the above data really does let us form a category. (But it's not terribly useful to grind through all of the detail of the exact set of morphisms of the category)
Of course, we also specify the set of cones that insist that $M^0$ is a terminal object and $M^2$ and $M^3$ are appropriate products, and we also need to add in the commutative diagrams that insist $\mu \times 1_M$ really is the morphism that gives you $\mu$ and $1_M$ after composing with the appropriate projections, and so forth.

A less convenient approach (but one that doesn't require developing sketches) that works for essentially algebraic theories is to define a theory to be a Cartesian category (i.e. it has all finite limits). Then a model of the theory is a functor from this category that preserves finite limits. Morphisms of models are still natural transformations.
In this approach, though, the categorical theory of magmas $T$ is the opposite category to the category of finitely presented magmas (as defined in the usual set theoretic way). 
Other than defining the notion of a Cartesian category presented by a limit sketch, I know of no simpler description of the category described above.
To help wrap your head around this, each finitely presented magma can be thought of as expressing a formal "construction" -- much in the same way the free magma on $n$ objects has the interpretation as being the set of all $n$-ary operations -- and so they give a convenient realization of the category of formal "constructions" one can make from a given magma using products and equalizers. (and magma morphisms give realizations of the relationships between them)

REPLY [3 votes]: The natural type of category to do this in is a monoidal category. Then we talk about magma objects and monoid objects in that category.
Does it go anywhere? Yes, you are able to introduce algebraic structures in almost arbitrary categories. In cartiesian cateogries, taking suitable hom functors then recovers the classical set-based structure. One immediate advantage to doing algebra like this is that you have a straightforward dualization procedure. Flipping all the arrows in the diagrams describing a structure will give you the corresponding costructure. In your case, you will get a comagma or a comonoid. Many common structures, like Hopf algebras, exploit this idea in their construction.

Yes, that's correct. The information carried by the natural transformation $\eta$ is precisely that $$m\circ\eta_{M\otimes M}(a,b)=f(a)f(b)=f(ab)=\eta_M\circ m(a,b)$$
A monoid has more structure then a magma, so you need more diagrams, one per axiom. A magma has just about no structure, so its diagram is very simple: $m:M\otimes M\rightarrow M$.
For a monoid you also need a diagram to express associativity and one to express the identity element. For the latter, the unit element is replaced by a unit map $\iota:I\rightarrow M$ where $I$ is the unit object in your monoidal category. See here for the diagrams in question.