\section{Spicey: An ER-based Web Framework}
\label{sec-spicey}

Spicey\index{Spicey} is a framework to support the implementation of
web-based systems in Curry. Spicey generates an initial implementation
from an entity-relationship (ER) description of the underlying
data. The generated implementation contains operations to create and
manipulate entities of the data model, supports authentication,
authorization, session handling, and the composition of individual
operations to user processes. Furthermore, the implementation ensures
the consistency of the database w.r.t. the data dependencies specified
in the ER model, i.e., updates initiated by the user cannot lead to an
inconsistent state of the database.

\subsection{Installation}

The actual implementation of Spicey is a package
managed by the Curry Package Manager CPM.
Thus, to install the newest version of Spicey, use the following commands:
%
\begin{curry}
> cypm update
> cypm install spicey
\end{curry}
%
This downloads the newest package, compiles it, and places
the executable \code{spiceup} into the directory \code{\$HOME/.cpm/bin}.
Hence it is recommended to add this directory to your path
in order to execute Spicey as described below.

\subsection{Basic usage}

The idea of this tool, which is part of the distribution of \CYS,
is described in detail in \cite{HanusKoschnicke14TPLP}.
Thus, we summarize only the basic steps to use this tool
in order to generate a web application.

First, one has to create a textual description of the
entity-relationship model
in a Curry program file as an (exported!) top-level operation type \code{ERD}
(w.r.t.\ the type definitions defined in the module \code{Database.ERD}
of the package \code{cdbi})
and store it in some program file, e.g., \ccode{MyERD.curry}.
The directory \code{examples} in the package \code{spicey}\footnote{%
If you installed Spicey as described above,
the downloaded \code{spicey} package is located in the directory
\code{\$HOME/.cpm/app\us{}packages/spicey}.}
contains two examples for such ERD program files:
\begin{description}
\item[\code{BlogERD.curry}:]
This is a simple ER model for a blog with entries, comments,
and tags, as presented in the paper \cite{HanusKoschnicke14TPLP}.
\item[\code{UniERD.curry}:]
This is an ER model for university lectures as
presented in the paper \cite{BrasselHanusMueller08PADL}.
\end{description}
%
Then you can generate the sources of your web application
by the command\pindex{spiceup}
\begin{curry}
> spiceup MyERD.curry
\end{curry}
with the ERD program as a parameter.
You can also provide a file name for the SQLite3 database used
by the application generated by Spicey, e.g.,
\begin{curry}
> spiceup --db MyData.db MyERD.curry
\end{curry}
If the parameter \ccode{--db DBFILE} is not provided,
then \code{DBDFILE} is set to the default name \ccode{$ERD$.db}
(where \code{$ERD$} is the name of the specified ER model).
Since this specification will be used in the \emph{generated} web programs,
a relative database file name will be relative to the place where
the web programs are stored.
In order to avoid such confusion, it might be better to specify
an absolute path name for the database file.
This path could also be set in the definition of the constant
\code{sqliteDBFile} in the generated Curry program
\code{Model/$ERD$.curry}.

Spicey generates the web application as a Curry package in a new
directory. Thus, change into this directory (e.g., \code{cd $ERD$})
and install all required packages by the command
\begin{curry}
> make install
\end{curry}
%
The generated file \code{README.txt} contains some information
about the generated project structure.
One can compile the generated programs by
\begin{curry}
> make compile
\end{curry}
In order to generate the executable web application,
configure the generated \code{Makefile}
by adapting the variable \code{WEBSERVERDIR} to the location
where the compiled cgi programs should be stored, and run
\begin{curry}
> make deploy
\end{curry}
After the successful compilation and deployment of all files,
the application is executable
in a web browser by selecting the URL \code{<URL of web dir>/spicey.cgi}.


\subsection{Further remarks}

The application generated by Spicey is a schematic initial implementation.
It provides an appropriate basic programming structure but
it can be extended in various ways.
In particular, one can also use embedded SQL statements
(see \cite{HanusKrone17EPTCS} for details)
when further developing the Curry code, since the underlying database
access operations are generated with the \code{cdbi} package.
The syntax and use of such embedded SQL statements
is sketched in \cite{HanusKrone17EPTCS} and
described in the Curry preprocessor.
