docs: Added page "How it works"#496
Conversation
developerjamiu
left a comment
There was a problem hiding this comment.
Document flows well top to bottom. Most of my line-level comments come from the doc templates and Viktor's feedback on the Introduction PR (#495).
| title: How Serverpod works | ||
| sidebar_label: How it works | ||
| sidebar_class_name: sidebar-icon-overview | ||
| description: Serverpod's architecture, how project structure, code generation, and request lifecycle provide full-stack type safety |
There was a problem hiding this comment.
Description should be a complete sentence per the doc templates.
| description: Serverpod's architecture, how project structure, code generation, and request lifecycle provide full-stack type safety | |
| description: Understand Serverpod's architecture: the three-package layout, the code generator, and the request lifecycle that gives you full-stack type safety. |
|
|
||
| # How Serverpod works | ||
|
|
||
| This page explains Serverpod's architecture: how the project structure, code generation, and request lifecycle work together to provide full-stack type safety. |
There was a problem hiding this comment.
Most templates says intro should drop the meta-statement like "This page explains"
| This page explains Serverpod's architecture: how the project structure, code generation, and request lifecycle work together to provide full-stack type safety. | |
| Serverpod is built around three Dart packages, a code generator, and a typed request lifecycle. Together they give you full-stack type safety from your database to your Flutter app. |
|
|
||
| The `_server` package holds your backend code, while the `_client` package acts as a bridge, providing the Flutter app with a typed API to call the server. | ||
|
|
||
| Because the `_client` package is auto-generated from the `_server` code, it stays in sync by construction. You do not write serialization code, HTTP calls, or API contracts by hand. |
There was a problem hiding this comment.
In previous review by Viktor, he suggested to not frame benefit as removing manual code i.e. "write serialization code, HTTP calls, or API contracts by hand" and also keep statements very simple
| Because the `_client` package is auto-generated from the `_server` code, it stays in sync by construction. You do not write serialization code, HTTP calls, or API contracts by hand. | |
| Change a model or add an endpoint, and the client follows automatically. The serialization and HTTP code are generated with it. |
|
|
||
| ### Session | ||
|
|
||
| The `Session` parameter that every endpoint method receives is Serverpod's request context. It gives the method access to the database, cache, authenticated user information, and logging, all of which are scoped to the lifetime of that single request. It is not a singleton; each call gets its own `Session` instance. |
There was a problem hiding this comment.
Nit: Trying to avoid "singleton" keyword based on the above comment
| The `Session` parameter that every endpoint method receives is Serverpod's request context. It gives the method access to the database, cache, authenticated user information, and logging, all of which are scoped to the lifetime of that single request. It is not a singleton; each call gets its own `Session` instance. | |
| The `Session` parameter that every endpoint method receives is the context for that single request. It gives access to the database, cache, signed-in user, and logging, all available only while the request runs. Each call gets its own `Session`. |
|
|
||
| ## Type safety across the stack | ||
|
|
||
| Type safety across the entire stack, from the database to your Flutter app, is guaranteed because Serverpod's model files (`.spy.yaml`) are the single source of truth. When code is generated, the same Dart class is used for database queries, server-side logic, and the client-side app. |
There was a problem hiding this comment.
| Type safety across the entire stack, from the database to your Flutter app, is guaranteed because Serverpod's model files (`.spy.yaml`) are the single source of truth. When code is generated, the same Dart class is used for database queries, server-side logic, and the client-side app. | |
| Type safety across the entire stack, from the database to your Flutter app, is guaranteed because Serverpod's model files (`.spy.yaml`) are the single source of truth. When code is generated, the same Dart class is used in database queries, server logic, and your Flutter app. |
|
|
||
| ## Code generation | ||
|
|
||
| The purpose of code generation is to eliminate boilerplate and provide type-safety. Serverpod continuously watches for changes in your `_server` package and the generator automatically creates the necessary code. |
There was a problem hiding this comment.
Removed the filler words; The purpose and continously
| The purpose of code generation is to eliminate boilerplate and provide type-safety. Serverpod continuously watches for changes in your `_server` package and the generator automatically creates the necessary code. | |
| Code generation cuts boilerplate and keeps types in sync between server and app. Serverpod watches your `_server` package as you edit and runs the generator automatically. |
| Thanks to the generated client, calling a server endpoint from your Flutter app feels like a local method call. You do not need to write any networking or serialization code. | ||
|
|
||
| ```dart | ||
| var result = await client.greeting.hello('World'); |
There was a problem hiding this comment.
Nit: Dart convention: var should be final for non-reassigned locals.
| var result = await client.greeting.hello('World'); | |
| final result = await client.greeting.hello('World'); |
Summary
The documentation currently lacks a dedicated page explaining Serverpod's architecture. This makes it harder for new users to understand how the different parts of the framework fit together.
This PR adds a new "How Serverpod works" page that provides a concise architectural overview, covering:
The focus for this page is on how full-stack type safety is achieved through generating the client project and ORM classes.
Images
Notes for reviewer
Test plan