# leoggehrer/setemplate architecture

> Architecture diagram of the GitHub repository leoggehrer/setemplate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leoggehrer/setemplate
- Repository: https://github.com/leoggehrer/setemplate

## Overview

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`](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic) (Tools Logic), [`SETemplate.Logic`](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic) (Logic), [`SETemplate.WebApi`](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.WebApi) (Web API), [`TemplateTools.ConApp`](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.ConApp) (Tools ConApp)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core runtime"]
  node_common["Common<br/>shared kernel<br/>[SETemplate.Common]"]
  node_logic["Logic<br/>domain core<br/>[SETemplate.Logic]"]
  node_webapi["Web API<br/>http host<br/>[SETemplate.WebApi]"]
  node_conapp["ConApp<br/>bootstrap console<br/>[SETemplate.ConApp]"]
  node_entities["Entities<br/>domain models<br/>[Entities]"]
  node_datacontext[("Data Context<br/>ef core boundary<br/>[DataContext]")]
  node_security{{"Security<br/>auth subsystem<br/>[Security]"}}
  node_account["Account<br/>[Account]"]
  node_webcontrollers["Controllers<br/>[Controllers]"]
  node_middleware["Middleware<br/>error pipeline<br/>[Middleware]"]
end

subgraph group_tools["Template factory"]
  node_toolconapp["Tools ConApp<br/>tool host"]
  node_toollogic["Tools Logic<br/>generation engine"]
  node_commongen["Common Gen<br/>generator stage<br/>[CommonGenerator.cs]"]
  node_logicgen["Logic Gen<br/>generator stage<br/>[LogicGenerator.cs]"]
  node_webapigen["WebAPI Gen<br/>generator stage<br/>[WebApiGenerator.cs]"]
  node_mvvmgen["MVVM Gen<br/>generator stage<br/>[MVVMGenerator.cs]"]
  node_angulargen["Angular Gen<br/>generator stage"]
end

subgraph group_clients["Clients"]
  node_angapp["Angular App<br/>browser client"]
  node_mvvmapp["MVVM App<br/>desktop client<br/>[SETemplate.MVVMApp]"]
end

subgraph group_support["Support tools"]
  node_codegenapp["CodeGen App<br/>utility console"]
  node_mcpsrv["MCP Server<br/>ai helper<br/>[SETemplate.McpSrv]"]
end

node_common -->|"contracts/base types"| node_logic
node_logic -->|"REST exposure"| node_webapi
node_logic -->|"bootstrap access"| node_conapp
node_entities -->|"tracked by"| node_datacontext
node_security -->|"auth rules"| node_logic
node_security -->|"request auth"| node_webapi
node_account -->|"identity flow"| node_security
node_datacontext -->|"context access"| node_webapi
node_webcontrollers -->|"errors"| node_middleware
node_toollogic -->|"shared output"| node_commongen
node_toollogic -->|"domain output"| node_logicgen
node_toollogic -->|"api output"| node_webapigen
node_toollogic -->|"desktop output"| node_mvvmgen
node_toollogic -->|"web output"| node_angulargen
node_toolconapp -->|"orchestrates"| node_toollogic
node_toolconapp -->|"entry mode"| node_codegenapp
node_toolconapp -->|"ai mode"| node_mcpsrv
node_toolconapp -->|"reads template"| node_logic
node_toollogic -->|"generates"| node_webapi
node_toollogic -->|"generates"| node_mvvmapp
node_toollogic -->|"generates"| node_angapp
node_logic -->|"defines"| node_entities
node_webapi -->|"consumed by"| node_angapp
node_logic -->|"mirrors"| node_mvvmapp

click node_common "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Common"
click node_logic "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic"
click node_webapi "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.WebApi"
click node_conapp "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.ConApp"
click node_entities "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/Entities"
click node_datacontext "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/DataContext"
click node_security "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/Modules/Security"
click node_account "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/Modules/Account"
click node_webcontrollers "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.WebApi/Controllers"
click node_middleware "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.WebApi/Middleware"
click node_angapp "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.AngularApp"
click node_mvvmapp "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.MVVMApp"
click node_toolconapp "https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.ConApp"
click node_toollogic "https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic"
click node_commongen "https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/CommonGenerator.cs"
click node_logicgen "https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/LogicGenerator.cs"
click node_webapigen "https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/WebApiGenerator.cs"
click node_mvvmgen "https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/MVVMGenerator.cs"
click node_angulargen "https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/AngularGenerator.cs"
click node_codegenapp "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.CodeGenApp"
click node_mcpsrv "https://github.com/leoggehrer/setemplate/blob/main/SETemplate.McpSrv"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_common,node_logic,node_webapi,node_conapp,node_entities,node_datacontext,node_security,node_account,node_webcontrollers,node_middleware toneBlue
class node_toolconapp,node_toollogic,node_commongen,node_logicgen,node_webapigen,node_mvvmgen,node_angulargen toneAmber
class node_angapp,node_mvvmapp toneMint
class node_codegenapp,node_mcpsrv toneRose
```

## Components

### Core runtime

Reusable backend kernel shared by generated solutions.

- [Common](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Common): shared kernel · Contracts, base models, enums, exceptions, validation, and utility extensions. · `SETemplate.Common`
- [Logic](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic): domain core · Entities, data context, authorization, validation, and account management. · `SETemplate.Logic`
- [Web API](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.WebApi): http host · REST boundary exposing logic via controllers, middleware, and context accessors. · `SETemplate.WebApi`
- [ConApp](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.ConApp): bootstrap console · Database creation, initialization, and account setup entry point. · `SETemplate.ConApp`
- [Entities](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/Entities): domain models · Entity and view object hierarchy, including account-related entities. · `SETemplate.Logic/Entities`
- [Data Context](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/DataContext): ef core boundary · ProjectDbContext, EntitySet, ViewSet, factories, and provider-specific persistence wiring. · `SETemplate.Logic/DataContext`
- [Security](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/Modules/Security): auth subsystem · Authorization attributes, identities, roles, sessions, and access checks across logic and API. · `SETemplate.Logic/Modules/Security`
- [Account](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.Logic/Modules/Account): account service · AccountManager and account initialization flow for optional authenticated solutions. · `SETemplate.Logic/Modules/Account`
- [Controllers](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.WebApi/Controllers): api controllers · Generic entity and view controllers, system endpoints, and security-aware API base classes. · `SETemplate.WebApi/Controllers`
- [Middleware](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.WebApi/Middleware): error pipeline · API exception handling and request-level cross-cutting behavior. · `SETemplate.WebApi/Middleware`

### Template factory

Generation, copy, and synchronization toolchain for new solutions.

- [Tools ConApp](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.ConApp): tool host · Command-line orchestration for copy, generation, synchronization, and cleanup workflows. · `TemplateTools.ConApp`
- [Tools Logic](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic): generation engine · Generators, preprocessors, file handling, and solution/project modeling for template output. · `TemplateTools.Logic`
- [Common Gen](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/CommonGenerator.cs): generator stage · Shared contract/model generation used by all output targets. · `TemplateTools.Logic/Generation/CommonGenerator.cs`
- [Logic Gen](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/LogicGenerator.cs): generator stage · Produces logic-layer entities, sets, and domain-facing code. · `TemplateTools.Logic/Generation/LogicGenerator.cs`
- [WebAPI Gen](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/WebApiGenerator.cs): generator stage · Produces API models, controllers, and host scaffolding. · `TemplateTools.Logic/Generation/WebApiGenerator.cs`
- [MVVM Gen](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/MVVMGenerator.cs): generator stage · Produces desktop client models, viewmodels, and views. · `TemplateTools.Logic/Generation/MVVMGenerator.cs`
- [Angular Gen](https://github.com/leoggehrer/setemplate/blob/main/TemplateTools.Logic/Generation/AngularGenerator.cs): generator stage · 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](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.AngularApp): browser client · Angular 19 frontend template with pages, interceptors, guards, services, and reusable components. · `SETemplate.AngularApp`
- [MVVM App](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.MVVMApp): desktop client · Avalonia MVVM desktop template with generated viewmodels, views, and dialogs. · `SETemplate.MVVMApp`

### Support tools

Auxiliary executables and AI integration helpers.

- [CodeGen App](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.CodeGenApp): utility console · Simplified code-generation entry point. · `SETemplate.CodeGenApp`
- [MCP Server](https://github.com/leoggehrer/setemplate/blob/main/SETemplate.McpSrv): ai helper · Server exposing template and architecture knowledge to assistants. · `SETemplate.McpSrv`

## Connections

- 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.
