How leoggehrer/setemplate works
1. What this repository is
This is not a single product app; it is a solution template for building domain-specific systems. The repo contains a reusable core architecture plus generators and helper tools that can clone, synchronize, and regenerate code for new projects such as a custom “SEBookStore”-style solution.
2. Primary architectural layers
The core backend is split into:
- SETemplate.Common: shared contracts, base models, enums, exceptions, and utility extensions.
- SETemplate.Logic: domain/business layer with entities, data context, authorization, validation, and account management.
- SETemplate.WebApi: REST host that exposes the logic layer over HTTP.
- SETemplate.ConApp: console initializer/admin tool for database creation, bootstrapping, and account setup.
These are the main boundaries an architecture diagram should show as stacked layers.
3. Cross-cutting template-generation toolchain
The repo also includes a second subsystem: TemplateTools.ConApp + TemplateTools.Logic. This is the meta-engine that copies template projects into domain projects, applies name replacement, toggles build defines, generates code, synchronizes template updates, and cleans output folders. This tooling is central to the repo’s purpose and should be shown as a separate pipeline beside the runtime application stack.
4. Generated-code boundary
A major design constraint is the separation between:
- Base/template code marked with @BaseCode
- Generated code marked with @GeneratedCode
- Copied/synchronized code marked with @CodeCopy
- Custom extensions in partial classes or custom files
The architecture depends on this marker system so regeneration does not overwrite user code. Partial classes are the main extension boundary across Logic, WebApi, MVVM, and Angular outputs.
5. Data and domain model flow
Domain entities live in SETemplate.Logic/Entities and inherit common base types such as EntityObject, ViewObject, and versioned variants. The generator reflects over those types to produce:
- Common contracts/interfaces
- Logic EntitySet / ViewSet abstractions
- Web API DTO models and controllers
- MVVM models/viewmodels
- Angular TypeScript models and services
This is the core left-to-right flow from domain model to presentation clients.
6. Persistence and data-access boundary
The logic layer owns persistence via ProjectDbContext, EntitySet, and ViewSet. EF Core is the persistence abstraction, with support for multiple database providers configured by preprocessor defines: SQLite, PostgreSQL, SQL Server. Database creation and initialization are explicitly handled by the console app, not by the API. The architecture therefore separates operational bootstrap from request serving.
7. Security and authentication as a cross-cutting subsystem
Authentication is optional and compile-time/runtime driven by the ACCOUNT_* define family. When enabled, the account subsystem centers on:
- Identity, SecureIdentity, Role, IdentityXRole, LoginSession
- AccountAccess and account initialization flows
- authorization attributes applied to DbContext, sets, and controllers
The SessionToken travels through backend operations, so security is not just an API concern; it is embedded in the logic/data-context boundary.
8. Web API host responsibilities
SETemplate.WebApi is the network-facing host. It exposes generated and partial controllers for CRUD entities and query views, plus account/system endpoints. It includes exception handling middleware and a context accessor abstraction that routes requests to the correct entity/view set handlers. This host should be drawn as the external API boundary between clients and the logic layer.
9. Frontend client template
SETemplate.AngularApp is a separate Angular 19 frontend template with Bootstrap 5.3, ngx-translate, and standalone components. It consumes generated REST models and services from the Web API layer. Its internal structure is organized around:
- pages for landing, dashboard, auth/login
- reusable base components for generic lists, editors, and message boxes
- interceptors for auth tokens and HTTP error handling
- guards for route protection
This is a client-side presentation layer, not tightly coupled to the backend codebase at build time.
10. Desktop/MVVM client template
SETemplate.MVVMApp is an Avalonia-based desktop host. It follows MVVM with generated viewmodels, views, and dialog/message infrastructure. It mirrors the same domain concepts as the Web/Angular stack, but through local UI bindings instead of HTTP. In a diagram, it belongs on the presentation side as an alternate client channel.
11. Utility executables
Two additional console-style subsystems exist:
- SETemplate.CodeGenApp: a simplified code-generation entry point
- SETemplate.McpSrv: an MCP server that exposes template/architecture knowledge to AI assistants
These are supporting tools, not domain runtime components, but they matter because they enable automation and AI-assisted development around the template.
12. Development workflow as an architectural process
The intended flow is: define entities in Logic → run the generator → produce shared contracts, EF/data-context code, API contracts/controllers, MVVM types, Angular models/services → extend generated code only through partial/custom files. The template tools can also copy an entire solution to a new domain name, synchronize later changes, and clean generated build artifacts. That workflow is a key part of the architecture, not just a build detail.
13. What to emphasize in an architecture diagram
A good diagram should show:
- multiple hosts: Web API, Angular, MVVM, console initializer, code-gen tools, MCP server
- a shared kernel: Common
- a domain/data core: Logic
- generation/synchronization pipeline feeding all hosts
- security/authentication as cross-cutting across logic and API
- partial/generated code boundaries as extension points
This repo is best understood as a solution factory with one reusable backend core and several generated or consuming frontends/tools.
Main entry points: TemplateTools.Logic Tools Logic · SETemplate.Logic Logic · SETemplate.WebApi Web API · TemplateTools.ConApp Tools ConApp
Components 21
Core runtime
Reusable backend kernel shared by generated solutions.
- Common · Contracts, base models, enums, exceptions, validation, and utility extensions.
SETemplate.Common - Logic · Entities, data context, authorization, validation, and account management.
SETemplate.Logic - Web API · REST boundary exposing logic via controllers, middleware, and context accessors.
SETemplate.WebApi - ConApp · Database creation, initialization, and account setup entry point.
SETemplate.ConApp - Entities · Entity and view object hierarchy, including account-related entities.
SETemplate.Logic/Entities - Data Context · ProjectDbContext, EntitySet, ViewSet, factories, and provider-specific persistence wiring.
SETemplate.Logic/DataContext - Security · Authorization attributes, identities, roles, sessions, and access checks across logic and API.
SETemplate.Logic/Modules/Security - Account · AccountManager and account initialization flow for optional authenticated solutions.
SETemplate.Logic/Modules/Account - Controllers · Generic entity and view controllers, system endpoints, and security-aware API base classes.
SETemplate.WebApi/Controllers - Middleware · API exception handling and request-level cross-cutting behavior.
SETemplate.WebApi/Middleware
Template factory
Generation, copy, and synchronization toolchain for new solutions.
- Tools ConApp · Command-line orchestration for copy, generation, synchronization, and cleanup workflows.
TemplateTools.ConApp - Tools Logic · Generators, preprocessors, file handling, and solution/project modeling for template output.
TemplateTools.Logic - Common Gen · Shared contract/model generation used by all output targets.
TemplateTools.Logic/Generation/CommonGenerator.cs - Logic Gen · Produces logic-layer entities, sets, and domain-facing code.
TemplateTools.Logic/Generation/LogicGenerator.cs - WebAPI Gen · Produces API models, controllers, and host scaffolding.
TemplateTools.Logic/Generation/WebApiGenerator.cs - MVVM Gen · Produces desktop client models, viewmodels, and views.
TemplateTools.Logic/Generation/MVVMGenerator.cs - Angular Gen · Produces Angular models, services, and UI scaffolding.
TemplateTools.Logic/Generation/AngularGenerator.cs
Clients
Presentation hosts that consume the core backend or mirrored models.
- Angular App · Angular 19 frontend template with pages, interceptors, guards, services, and reusable components.
SETemplate.AngularApp - MVVM App · Avalonia MVVM desktop template with generated viewmodels, views, and dialogs.
SETemplate.MVVMApp
Support tools
Auxiliary executables and AI integration helpers.
- CodeGen App · Simplified code-generation entry point.
SETemplate.CodeGenApp - MCP Server · Server exposing template and architecture knowledge to assistants.
SETemplate.McpSrv
Connections 24
- Common → Logic: contracts/base types · Logic builds on shared contracts, models, enums, and utilities.
- Logic → Web API: REST exposure · API host serves logic through generated and partial controllers.
- Logic → ConApp: bootstrap access · Console initializer uses the logic layer for database and account setup.
- Entities → Data Context: tracked by · Entity and view types are organized into sets and persistence context.
- Security → Logic: auth rules · Authorization and session handling are embedded in the logic boundary.
- Security → Web API: request auth · API controllers and filters enforce security at the HTTP boundary.
- Account → Security: identity flow · Account management depends on identity, role, and session primitives.
- Data Context → Web API: context access · API context accessor routes requests to the correct entity/view set handlers.
- Controllers → Middleware: errors · Controllers run behind exception handling middleware.
- Tools Logic → Common Gen: shared output · Common generation seeds all other target-specific generators.
- Tools Logic → Logic Gen: domain output · Generates logic-layer code from entity and solution metadata.
- Tools Logic → WebAPI Gen: api output · Generates API contracts, controllers, and host files.
- Tools Logic → MVVM Gen: desktop output · Generates MVVM models, viewmodels, and views.
- Tools Logic → Angular Gen: web output · Generates Angular models, services, and client scaffolding.
- Tools ConApp → Tools Logic: orchestrates · Console apps invoke generation, copy, synchronization, and cleanup modules.
- Tools ConApp → CodeGen App: entry mode · One console path focuses on simplified code generation.
- Tools ConApp → MCP Server: ai mode · One console path exposes tooling through an MCP server.
- Tools ConApp → Logic: reads template · Tools inspect domain entities and project structure to generate outputs.
- Tools Logic → Web API: generates · Generation pipeline emits API-side code from the template core.
- Tools Logic → MVVM App: generates · Generation pipeline emits desktop client artifacts.
- Tools Logic → Angular App: generates · Generation pipeline emits browser client artifacts.
- Logic → Entities: defines · The domain layer defines the entity and view object model.
- Web API → Angular App: consumed by · Angular client consumes the REST API and generated client models.
- Logic → MVVM App: mirrors · Desktop client mirrors domain concepts through generated viewmodels.