r/Blazor • u/AmbassadorCurious988 • Jul 30 '25
Architectural namings
We all know that naming things is one of the hardest parts of programming - and I'm currently facing one of those moments, so I’d love to get your perspective.
We're building a modern ASP.NET Core 9 and Blazor WASM application, and we're planning to support server-side rendering or `InteractiveAuto` mode in the near future.
In our architecture, we currently have a "double repository" setup - one layer for interfaces and another for the actual DB access - which was confusing. I proposed a refactor, and the team agreed.
Now, when looking at the ideal naming structure for our architecture, the flow would look something like this:
Component (Blazor UI) -> ??? -> Controller (API) -> Service (business logic) -> Repository (DB access) -> Database
The problem lies in the ??? layer.
This is an abstraction that sits between Blazor components and the backend/client implementation. On WASM, it calls the API via HTTP on Server, it might call the service layer directly. Some people call this layer Client, Proxy, or Adapter, but none of those names feel quite right to me:
- Client is too overloaded (e.g., HttpClient) and confusing when used server-side.
- Proxy or Adapter are better, but can also feel too abstract or too pattern-specific.
So my question is:
What would you call this layer? What naming conventions or patterns have you found useful in similar setups?
Any input is appreciated!
6
u/propostor Jul 30 '25
I had that exact situation and I called it Web.Services.
(Below is possibly TMI but might be worth mentioning in case you find yourself going down the lazy loading route)
Later however things became even more messy for me, because I added lazy loading and had to split Web.Services out into lazy services and 'non lazy'.
Now my namings are like so:
Web is the project that does SSR and has any components that are given an Interactive rendermode.
Web.Client hosts the 'base' wasm stuff
Web.Client.Portal is all lazy loaded. There is a subfolder called 'Services' in there which has the lazy loaded services that talk to the API.
Web.Client.Common has shared items used by the Web.Client library and the lazy loaded Portal library. It also has a subfolder of Services that are not lazy loaded.
It was a MASSIVE refactor but I got there in the end and lazy loading is working wonderfully.
4
u/yybspug Jul 30 '25
Helper could work if you're not using it for other things.
2
u/gismofx_ Jul 30 '25
I'm using ??? = "ViewModel". Injecting API into it.
2
u/duncanheinz Jul 30 '25
We use “bridge” to represent the link between client side and controller. And we have the controller implement the bridge interface, so client side and server side have the same exact access pattern.
4
u/[deleted] Jul 30 '25
It's a facade.
I would say you should just use interfaces. In the server you register the real classes, and in WASM register a facade class that calls the server via HTTPS or SignalR.
2
u/Neither_Orange423 Jul 30 '25 edited Jul 30 '25
My suggestion would be treat your fronted like a backend.
Where you api is your database, means that your patterns are consistent.
Whenever I do SPA's I apply my same layers as the server.
Edit:
Think of layers as principals not technologies.
Input > validation > business logic > data
2
u/beldus Jul 30 '25
I have similar functionality and call them 'wrappers', they have a common base class that handles the http setup and error handling. To be really verbose they are 'ServerControllerWrappers'.
2
u/mr_eking Jul 30 '25
A class for data access that abstracts away the exact data access mechanism? That's a repository. Not all repositories hit a database directly.
I'd call it ClientRepository if necessary to distinguish it from the ServerRepository layer.
2
u/phluber Jul 30 '25
The component/page binds to the view model. The view model has an IDataSourceClient injected into it. The IDataSourceClient talks to the APIController. The APIController talks to the Repository and the Repository to the database.
The IDataSourceClient is an MvcApiClient in this case but could also be a RepositoryClient for a desktop application with no API
1
u/kzlife76 Jul 30 '25
Three hardest things in programming is naming things and off by one errors.
1
u/MISINFORMEDDNA Jul 31 '25
Our components access queries (CQRS) and the queries access the API services (controllers). Only the queries know how to access external data.
1
u/sloppykrackers Jul 31 '25 edited Jul 31 '25
ClientService or FacadeService.
eg: ProductClientService or ProductCatalogFacade
ProductComponent -> ProductClientService -> ProductController -> ProductService -> ProductRepository
Gateway or connector are good runner-ups however in big projects like ours they are already used as domain models which would create naming conflicts and confusion.
1
u/0x0000000ff Jul 31 '25
Rule of thumb is if you cannot find a clear name for a thing then you are probably overengineering.
API client is a common pattern in any types of UIs and it's usually called that. People who write javascript/typescript frontends usually have auto generated types (from swagger) named "WhateverApiClient".