Rigorous version of field Lagrangian In Classical Mechanics the configuration of a system can be characterized by some point $s\in \mathbb{R}^n$ for some $n$. In particular, if it's a system of $k$ particles then $n = 3k$ and if there are holonomic constraints then in truth $s$ lies in some submanifold of $\mathbb{R}^n$. Even if the constraints are not holonomic,  the configuration of a system can still be given by elements of some finite dimensional smooth manifold.
In that case, the Lagrangian becomes a smooth function $L: TM\to \mathbb{R}$ where $TM$ is the tangent bundle of the configuration manifold. Given coordinates $(q^1,\dots,q^n)$ on $M$ we can therefore make coordinates $(q^1,\dots,q^n,\dot{q}^1,\dots,\dot{q}^n)$ on $TM$ such that $q^i$ on $TM$ is really $q^i\circ \pi$ and $\dot{q}^i$ is characterized by the fact that if $v \in T_aM$ is
$$v = \sum_{i=1}^n v^i\dfrac{\partial}{\partial q^i}\bigg|_a$$
Then $\dot{q}^i(v) = v^i$. In that way, differentiating with respect to $q^i$ and $\dot{q}^i$ is perfectly well defined and Lagrange's Equation is totally meaningfull
$$\dfrac{d}{dt} \dfrac{\partial L}{\partial \dot{q}^i}(c(t),c'(t)) = \dfrac{\partial L}{\partial q^i}(c(t),c'(t))$$
When it comes then to studying fields like electromagnetic fields and so on, things get a little messy. Now, the system is the field and a configuration of the field is not anymore a certain list of numbers but a function like $\mathbf{E}: \mathbb{R}^3\to T\mathbb{R}^3$ or $\phi : \mathbb{R}^3\to \mathbb{R}$.
If we insist in building a configuration space $M$ it will be infinite dimensional and locally modeled on Banach Spaces. If we try to mimic Lagrangian formalism here, it'll end up in some infinite dimensional bundle, and this is not something nice to work with.
Now, most books work formally. For example, they let $\mathcal{L} = \dfrac{1}{2}g_{\mu\nu}(\partial^\nu \phi)(\partial^\mu\phi)- \dfrac{1}{2}m^2\phi^2$. Then they compute formally:
$$\dfrac{\partial \mathcal{L}}{\partial \phi} = -m^2\phi \\ \dfrac{\partial \mathcal{L}}{\partial (\partial_\mu \phi)} = \partial^\mu \phi$$
And then Lagrange's Equations becomes
$$\dfrac{\partial \mathcal{L}}{\partial \phi} = \partial_\mu \dfrac{\partial \mathcal{L}}{\partial (\partial_\mu\phi)}\Longrightarrow \partial_\mu\partial^\mu\phi + m^2\phi = 0$$
Now this brings some questions:


*

*First of them it is not clear on which space this $\mathcal{L}$ is defined and where it takes values. Some people say it is just a $3$-form on spacetime, but it doesn't seem like that, it looks like a scalar to me.

*Second, we take derivatives of $\mathcal{L}$ with respect to functions. This is much confusing to me. It even conflicts the first point of view, if $\mathcal{L}$ is a $3$-form it can only be differentiated with respect to the coordinates of the manifold on which it is defined.
So how can we make all of this rigorous? I mean, in which space is $\mathcal{L}$ defined? What these derivatives really mean and why they make any sense at all? How to make a connection between this and the Classical Mechanics Lagrangian formalism?
 A: Let us start from Minkowski spacetime $M$ and construct the trivial bundle $\Phi=\mathbb R \times M \to M$ whose sections $\phi : M \ni p  \mapsto (p,\phi(p))$ are the scalar fields you want to discuss their dynamics.
Since you correctly wish to see the partial derivatives of $\phi$ as variables independent from $\phi$ itself (this is your second raised issue), the convenient space is the so called first jet bundle $j^1 \Phi$.
I will not enter here into the details of the mathematical notion of jet bundle, I will simply illustrate how it can be used to clarify your issues.
$j^1 \Phi$ is a fiber bundle over $M$ such that each fiber at $p\in M$ has the structure (is diffeomorphic to) $\mathbb R \times \mathbb R^4$. The first factor $\mathbb R$, on shell,
embodies the information of $\phi(p)$ and the second $\mathbb R^4$ on shell  refers to the derivatives  $\partial_\mu \phi(p)$ at the same point of the basis $p$. 
However, in general these components must be viewed as independent variables: They are related  just when the equations of motion are imposed, i.e.,  on shell.  
Coming back to your first issue, in this picture, the Lagrangian is a map $${\cal L} : j^1\Phi \to \mathbb R$$
so that, ${\cal L}= {\cal L}(p, \phi(p), d_\mu(p))$. Euler-Lagrange equations 
determine  sections $$M \ni p \mapsto (p, \phi(p), d_\mu(p)) \in j^1\Phi$$ and read
$$\partial_\mu \left(\frac{\partial {\cal L}}{\partial d_\mu}\right) - \frac{\partial {\cal L}}{\partial \phi} = 0\:, \quad \partial_\mu \phi = d_\mu\:.$$
You see that  the field equations themselves establish that $d_\mu =  \partial_\mu \phi$, otherwise $\phi(p)$ and $d_\mu(p)$ would be independent variables.
Also in classical mechanics the convenient picture is that of a jet bundle (more natural than the one based on a tangent bundle). In that case, $M$ is replaced by the line of time $\mathbb R$ and each fiber $Q_t$ of the fiber bundle $\Phi \cong \mathbb R \times Q$ is the configuration space at time $t$ covered by coordinates $q^1,\ldots, q^n$. In this sense $\Phi$ is the spacetime of configurations. All Lagrangian mechanics is next constructed in $j^1\Phi$. Here the fiber $A_t$ at $t\in \mathbb R$ admits natural local coordinates $q^1,\ldots,q^n, \dot{q}^1,\ldots, \dot{q}^n$. The Lagrangian function is nothing but  a map 
$$j^1\Phi \ni (t,q^1,\ldots,q^n, \dot{q}^1,\ldots, \dot{q}^n) \mapsto L(t, q^1,\ldots,q^n, \dot{q}^1,\ldots, \dot{q}^n)\in \mathbb R$$
and Euler-Lagrange equations now read
$$\frac{d}{dt} \left(\frac{\partial L}{\partial \dot{q}^k}\right) - \frac{\partial L}{\partial q^k} = 0\:, \quad \frac{dq^k}{dt} = \dot{q}^k\:.$$
