This repository contains an example project for applying the Rails MVC paradigm with server-side Dart.
We use Shelf Router to define our routes.
Edit the lib/config/routes.dart
file to update your routes definitions.
We use Shelf to define our controllers.
Add the new controller file in the lib/app/controllers
folder and update the rollup file to expose it.
Make sure the methods of the controller are static and adhere to the Handler
signature.
eg.
class Resource {
static Future<Response> index(Request request) async {
return Response.ok('Hello World!');
}
}
Note: although it is not necessary, please avoid appending the Controller
suffix to the controller class name.
It will make the code more readable and also when you use it in the routes file, it will look more fluent.
We use Prisma to define our data models and generate the database schema.
Edit the prisma/schema.prisma
file to define your data model.
eg.
model User {
id Int @id @default(autoincrement())
name String
email String @unique
}
$ ./tools/model_gen.sh
$ ./tools/migrate.sh
We use jinja to define our views. This will change in the future.
Add the new view file{s} in the lib/app/views
folder by creating the resource folder and naming it the same as the controller file (eg. posts/
, users
etc).