Ocsigen Start

Ocsigen Start is a ready-to-use application skeleton for building client-server web and mobile applications with Eliom and Ocsigen Toolkit. It ships with user management, notifications, a database schema and many code examples, so you can focus on your own features from day one.

Use it to learn Ocsigen or to quickly create your own Minimum Viable Product. The application is cross-platform: it works as a Web app or as a mobile app for iOS or Android (via Cordova).

Ocsigen Start is part of the Ocsigen project.

Demo

If you want to test the demo application before installing Ocsigen Start, a live version is running here.

You can also download the mobile app on Google Play store (for Android) or download the APK for Android or the iOS version (to be installed using XCode).

Ocsigen Start is composed of two main parts:

Getting started

Read this page to learn how to build your first Ocsigen Start app in 5 minutes.

Implementation overview

Template

The library portion of Ocsigen Start contains core functionality that is common across Ocsigen Start applications, while the template can be customized for the specific application at hand.

The template additionally contains a demonstration of relevant Ocsigen Toolkit widgets. The demo portion can easily be removed.

Database

For implementing users, a database is needed. Specifically, we use PostgreSQL via the PGOCaml library. The template and the library make common assumptions about the database schema. The tables of Ocsigen Start are defined in the file ocsigen_start.sql of the template, and the tables of the application in PROJECT_NAME.sql. make db-update applies both: it creates the tables on a new database, and brings them up to date on an existing one. ocsigen_start.sql can be applied again and again, and PROJECT_NAME.sql must stay so (see its header). After an upgrade of Ocsigen Start, back up the database, replace ocsigen_start.sql with the one of the new template ($(opam var lib)/eliom/templates/os/ocsigen_start.sql), and run make db-update again.

The same database can be used for the specific needs of the application at hand. For that, add new tables to PROJECT_NAME.sql, keeping it replayable. The tables of Ocsigen Start should remain in place for it to work correctly.

Internationalization (i18n)

The template is available in multiple languages (English and French) using ocsigen-i18n. The translations used in the template are defined in the files assets/PROJECT_NAME_i18n.tsv and, for the demo, assets/PROJECT_NAME_Demo_i18n.tsv. Dune rules in lib/dune generate the Eliom modules PROJECT_NAME_i18n and PROJECT_NAME_Demo_i18n, and generate them again whenever a TSV file changes.

To add a language, add it to --languages in both rules, and add a column for it to each TSV file. --default-language sets the default language.

Managing e-mails

The template application keeps track of users' e-mails and implements e-mail validation. For that, sendmail (or another mail transfer agent compatible with it) needs to be installed on the host.

Style

The application provides a standard style matching contemporary aesthetics. For this, we use SASS. The style can be customized by modifying the SASS files that are part of the template.

Installation

Ocsigen Start can be installed via OPAM. The package name is ocsigen-start. The template application can be instantiated via eliom-distillery:

eliom-distillery -name $APP_NAME -template os

(Replace $APP_NAME by the name of your application).

Then install the opam packages that the generated project depends on, from its directory:

opam install --deps-only .

For details on creating the database and launching the application, refer to the template's README.

Migrating from version 8

Since version 9, the modules of Ocsigen Start are submodules of Os: write Os.Session, Os.User or Os.Email instead of Os_session, Os_user or Os_email. Ocsigen Start 9 also requires Eliom 13, Ocsigen Server 8 and Ocsigen Toolkit 5, which rename their modules the same way (Eliom.Content.Html instead of Eliom_content.Html, Ocsigen.Server instead of Ocsigen_server, Ot.Popup instead of Ot_popup).

To migrate progressively, install the ocsigen-start-compat package and add the libraries ocsigen-start-compat.server and ocsigen-start-compat.client to the server and client parts of your application, respectively. They define the old Os_xxx modules, each of which includes the new module, so that existing code keeps compiling while you rename the references. Other packages do the same for the rest of the stack: eliom-compat (libraries eliom-compat.server and eliom-compat.client), ocsigenserver-compat (library ocsigenserver-compat) and ocsigen-toolkit-compat (libraries ocsigen-toolkit-compat.server and ocsigen-toolkit-compat.client).

The tables of Ocsigen Start are now in ocsigen_start.sql, separate from those of the application (see the Database section above). To move an existing project to this layout:

The dune rules of the template are now generated by ocsigen-dune-rules (instead of tools/gen_dune.ml), with the code of the application in lib/ and its entry point in app/. Generating a new project with eliom-distillery and comparing it with yours is the simplest way to see what changed.

Library overview

We provide a tour of the Ocsigen Start library. Most modules have server- and client-side versions. (In the API documentation, there are links near the top of each module page for selecting the side.)

The template uses all these modules, and can thus act as a good starting guide. Look around!

User interface

Various modules for producing icons, messages, custom pages, tips, connection forms, etc.

Users and groups

Communication

Services, handlers, sessions

Other utilities

The template also uses ocsigen-ppx-rpc, a ppx syntax extension to call server-side functions from the client (let%rpc).