Skip to content

Support sharing logic between client and server for models #3339

Closed

Description

@vanlooverenkoen

Describe the bug

Right now all models are generated in server & client. This results in having duplicated classes if you want to use a shared package that can be used by server & frontend. (like extensions)

Why is server just no using client for all the models?

To reproduce

Just any serverpod project

Expected behavior

I would assume that server depends on client

Library version

2.4.0

Platform information

all platforms

Additional context

No response

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this

Activity

  1. added
    bug
    on Mar 22, 2025
  2. SandPod commented on Mar 24, 2025

    @SandPod
    Contributor

    This is discussed in part here with a possible workaround (quite advanced): #1256

    The client versions of the models can't be used directly because there might be ServerOnly fields.

    With the introduction of interfaces, #2842, it would be possible to use the same definition if we were to exclude that feature.

  3. SandPod commented on Mar 24, 2025

    @SandPod
    Contributor

    Is it OK if I change the title of this issue to "Support sharing logic for server and client classes"?

    Then we could track this specific usecase there.

  4. added
    enhancement
    area: models
    and removed
    bug
    on Mar 24, 2025
  5. vanlooverenkoen commented on Mar 24, 2025

    @vanlooverenkoen
    ContributorAuthor

    @SandPod perfect!

    Indeed the ServerOnly fields will still only be generated in the server package. but everything else should be the exact same class between server & frontend

  6. changed the title [-]server should depend on client to fix duplicate classes[/-] [+]Support sharing logic between client and server for models[/+] on Mar 24, 2025
  7. moved this from Backlog 🗂️ to Done 🚀 in Serverpod Frameworkson Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: modelsenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions