ocsigen-start
ocsigen-start copied to clipboard
Structure the website in folders, like in Django Apps
Hello,
I really think that Ocsigen could be really nice to be used in website development. However, there are, I think, two problems for it to became more popular. The first one is databases (see my other issue for more details), but it's not the subject of this part. The other problem is that it's not easy to "separate" a website, by making it easy to modify, and easy to distribute.
In every famous framework, you can do this : apps for Django, bundle for Symphony... But there are no ways to easily separate a website with ocsigen-start. The idea is to be able to separate the website in several folders. For example a folder "blog", a folder "admin", a folder "game", a folder "wiki"... Then, it would be possible to put in each folder the content relevant for this folder:
- the folder "blog" would contain only the pictures/static files used in the blog, and no pictures used in the game folder.
- In the same idea the SQL model would be described in each folder: the blog database structure does not mind to know the wiki database...
- You can also put a system of template, and put each template in the good folder...
And moreover it's very nice because you can re-use this app in another website, and one can imagine a way to centralize them, install them...
Would it be possible to structure a website using an "app-like" idea ?
Thank you,
tobiasBora.
@tobiasBora Thanks for the idea. I also agree to say it's a very good idea.
I think the project structure must be reviewed to have something like the Play framework does: https://www.playframework.com/documentation/2.5.x/Anatomy.
I like the idea to have as top directories:
-
app
for all source codes in. -
conf
for configurations. -
logs
for logs. -
public
for all public files.
First we focus on the last functionalities for the real release. After that, we will focus on this.
Ocsigen Start will continue to evolve, it's just ~~the beginning~~ the start.
Do we really want separate folders? If you're happy with some components that have a well defined functionality, they could be released as separate projects. With folders, reusability would require copy/pasting, but better to properly depend on a library.
@agarwal I think yes. To take the Ocsigen Start as example, we can have:
- a directory called
app/database
withOs_db
module splitted in different files likeOs_user_db
,Os_group_db
, etc. - a directory called
app/services
withOs_action_link_services
,Os_user_services
, etc. - a directory called
app/handlers
withOs_action_link_handlers
,Os_user_handlers
(sign_up, sign_in, etc). - a directory called
app/notifications
withOs_notif
andOs_fcm_notif
. - ...
@agarwal : I think that there are lot's of reason to explain why this scheme is present in every popular library/framework. And it's not only for reusability (even if it's an important part), but also to structure your website clearly, actually there are no reason to put in the same place files that have nothing to do together. By the way if you have a tempory solution that involves library, I would be curious to see how you would use it. What is the exact process to create a library containing client & server side code, and static data ? And how would you load everything of this into the website ?
You can note that I tried a few years ago to do this, I manage to have it working using pure Makefile, the bricks (equivalent of app) could be dependent each others... and I even program something to deal with automatic update of SQL tables depending on an Ocaml description (it was more a proof of concept however). However I tried later to make it working using ocamlbuild... And I became crazy when I tried to do inclusion of subfolders... If you want to have a look, you may be interested in it: https://github.com/tobiasBora/phluor_tools, with a youtube presentation (french): https://www.youtube.com/watch?v=kcnikpOa8ng.
I didn't mean to say don't create folders. Certainly that can make the code within this repo more organized. However, that's not the way to support reusability, which should be done by releasing libraries.
What is the exact process to create a library containing client & server side code, and static data ?
I don't think it requires anything special. The Eliom project is already an example of this.
However I tried later to make it working using ocamlbuild
That's a different issue. You might be interested in solvuu-build's Eliom support.
Well Eliom doesn't pack static files I think, so I'm not sure to see how I would do that. And the documentation about that is pretty poor... And by the way it would be nice to have a way to automatically convert a folder of app into an opam package.
Solvuu-build is not the solution: "Files for a single library cannot be spread across multiple directories.". Directories seems to be the problem of ocamlbuild.
Solvuu-build is not the solution: "Files for a single library cannot be spread across multiple directories.". Directories seems to be the problem of ocamlbuild.
This restriction would be pretty easy to lift. I probably over-emphasized this by putting it in the README.
Well if you manage to make it working with several directories, I would be very happy !
Okay, I created solvuu/solvuu-build#49 to remind myself.
I agree with @agarwal, we should work on making it easy to export static assets in libraries and encourage reusable eliom libraries.
Compared to everything you cited, we have a decisive advantage: we already have something to structure our code: the module system. If we could manage to use namespaces for eliom, it would provide a much better solution.
solvuu/solvuu-build#49 has been resolved. Source files for a single lib can now be split into multiple sub-directories.