How to create a fully customized and compatible LaTeX environment

I want to create a simple environment in LaTaX that's alike the following figure. If, for example, this environment has some spare comments like references or so, to be added above the environment (like metric projection) and to also fell into the frame; However, I want it to be completely compatible with the page; I mean, when some of it holds in a page and the remaining flows to the next page, the thing doesn't get messed up, analogous to a text which will be placed in the text flow; and when there is some footnotes within the environment, the footnote to be placed in the current page. How may I create such a standard environment which is very compatible to the other environments and to be like the aforementioned? I'm asking the veterans with a great deal of experience that which commands and suitable packages I may use to produce such an environment which if I enter the followings:

\begin{defi}[metric projection]
Hello bla bla bla bla
\end{defi}


I end up with an output like the following figure:

Here's an example use of the mentioned tcolorbox package for you:

Code

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{blindtext}
\usepackage{tcolorbox}

\usepackage{tikz}
\usetikzlibrary{shapes}
\tcbuselibrary{skins,breakable}
\newcounter{example}
\newtcolorbox[use counter=example]{defi}[3][]{%
enhanced,
breakable,
colback=yellow!40, % background color of main box
colframe=black, % frame color of main box
top=4mm, % inserted space on top
arc=4mm, % edge arc
enlarge top by=\baselineskip/2+1mm,
enlarge top at break by=0mm,pad at break=2mm,
fontupper=\normalsize,label={#3},
overlay unbroken and first={%
\node[rectangle,rounded corners=10pt,draw=black,fill=white, % first heading box
inner sep=1.5mm,anchor=west] (def) at ([xshift=3.6mm]frame.north west)
{\textbf{\Large Definition \thetcbcounter.}};
inner sep=1mm,anchor=west] at ([xshift=-11mm]def.east)
{\textbf{\footnotesize\hspace{3mm} #2}};
\node[rectangle,rounded corners=10pt,draw=black,fill=white, % first heading box
inner sep=1.5mm,anchor=west] (def) at ([xshift=3.6mm]frame.north west)
{\textbf{\Large Definition \thetcbcounter.}};},
#1}%

\begin{document}
\begin{defi}{Metric Projection}{label:metricprojection}
\blindtext
\end{defi}
\end{document}


This is an adapted version of some code from the tcolorbox manual which additionally gives you the oportunity of labelling the box ("label:metricprojection" in my example). The heading boxes are simple tikz nodes for which you can find numerous examples etc. all over TEX.SE and the web in general, so adjusting them to your exact needs shouldn't be a thing.

The first node is printed two times in order to overlap the second one, which aligns to it. There might be a better way to achieve this, but honestly I don't know how (comments on this are welcome!). It works perfectly well this way though.

Page breaks are not a problem for this, but your requirements regarding footnotes seem to be not possible to match with tcolorbox, see question 124546.