# ixi-enki/se-template architecture

> Architecture diagram of the GitHub repository ixi-enki/se-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ixi-enki/se-template
- Repository: https://github.com/ixi-enki/se-template

## Overview

1. **Repository shape**
   - This is not a single app, but a **solution template platform**.  
   - The repo contains a reusable core architecture (`SETemplate.*`) plus a separate **tooling layer** (`TemplateTools.*`) that can clone, synchronize, and generate code for derived domain solutions.

2. **Core domain boundary: `SETemplate.Common`**
   - `Common` holds the **shared contracts, base models, enums, exceptions, validation helpers, and utility extensions**.
   - It is intentionally domain-agnostic and forms the lowest architectural layer reused by all other `SETemplate` projects.

3. **Business layer: `SETemplate.Logic`**
   - `Logic` is the central runtime library: **entities, data context, business rules, authorization, and account management** live here.
   - It exposes domain abstractions through contracts and partial classes, and it is the layer the rest of the system builds on.

4. **Data access pattern inside Logic**
   - The data layer is organized around **`ProjectDbContext`**, **`EntitySet`**, and **`ViewSet`** abstractions.
   - Entities and views are discovered via **reflection** by the generator, then wired into context and service contracts.
   - This is the main persistence boundary, with EF Core and database-provider selection controlled by compile-time defines.

5. **Authentication and authorization flow**
   - Authentication is an explicit subsystem centered on **accounts, roles, password rules, sessions, and session tokens**.
   - If `ACCOUNT_ON` is enabled, access to context and sets is guarded by custom security attributes and security partials.
   - The flow is: login with email/password → receive `LoginSession` with `SessionToken` → pass token into context/service operations.

6. **REST boundary: `SETemplate.WebApi`**
   - `WebApi` is the network-facing host that exposes the logic layer as **REST endpoints**.
   - It contains generic controllers for entities and views, account endpoints, middleware for exception handling, and DTO models.
   - This is the main boundary for external clients, and it translates HTTP requests into `Logic` operations.

7. **Client-side Angular host: `SETemplate.AngularApp`**
   - The Angular project is a frontend host built with **Angular 19**, **Bootstrap 5.3**, and **ngx-translate**.
   - Its structure shows a clear split between **pages**, **generic base components**, **services/interceptors/guards**, and **models**.
   - It talks to `WebApi` via generated HTTP services and uses interceptors for token/error handling.

8. **Desktop/MVVM host: `SETemplate.MVVMApp`**
   - `MVVMApp` is an **Avalonia-based desktop UI template** using the MVVM pattern.
   - It contains view models, views, dialogs, and template-specific item/list abstractions.
   - Like the Angular app, it is a UI shell over the same shared domain/model concepts.

9. **Initial setup and database bootstrap: `SETemplate.ConApp`**
   - `ConApp` is the **initialization console app** used to create or synchronize the database, seed accounts, and import data.
   - It is mainly a bootstrap and maintenance host rather than a user-facing runtime.
   - The README indicates it is typically used once during project setup or for admin maintenance.

10. **Code generation runtime: `SETemplate.CodeGenApp`**
   - This is a smaller console entry point for **code generation only**.
   - It exists to generate backend/frontend artifacts from the compiled logic assembly without the broader template-management features.

11. **Template management layer: `TemplateTools.ConApp` + `TemplateTools.Logic`**
   - These projects are the **template engineering engine** of the repo.
   - They handle copying a template solution into a domain solution, preprocessing defines, generating code, synchronizing template/code-copy states, cleaning build artifacts, and extra tooling.
   - The tooling works across the solution structure, not inside the runtime app itself.

12. **Generated-code and synchronization model**
   - The repo uses a **marker-based source control strategy**: `@BaseCode`, `@CodeCopy`, `@GeneratedCode`, `@CustomCode`, `@AiCode`.
   - Generators can overwrite generated areas, while custom partials preserve manual code.
   - This is a key architectural boundary: generated infrastructure is separable from handwritten business/UI extensions.

13. **Cross-project data flow**
   - Typical flow is: **domain entities in Logic** → reflection-based generation → **contracts/models/controllers/services/UI artifacts**.
   - Runtime flow is: **UI or API client** → `WebApi` or generated HTTP services → `Logic` → `Common` abstractions + EF Core persistence.
   - Tooling flow is separate: **template solution** → `TemplateTools` → copied/synchronized domain solution.

14. **Compile-time feature switching**
   - Several architecture decisions are controlled by **preprocessor defines** rather than runtime config: authentication, key type selection, database provider, rowversion support, generated-code mode, and developer-only operations.
   - This means the solution can produce different runtime variants from the same source tree, which is important when drawing the architecture as a configurable template rather than a fixed app.

15. **External/runtime technologies that materially matter**
   - Backend/runtime: **.NET 8, ASP.NET Core, EF Core**, with support for **SQLite/PostgreSQL/SQL Server**.
   - Frontend/runtime: **Angular 19**, **TypeScript**, **Bootstrap**.
   - Desktop runtime: **Avalonia**.
   - Tooling: **reflection-based code generation**, console hosts, and an **MCP server** (`SETemplate.McpSrv`) for AI assistant integration and template guidance.

Main entry points: [`SETemplate.Logic`](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic) (SETemplate.Logic), [`SETemplate.WebApi`](https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi) (SETemplate.WebApi), [`TemplateTools.Logic/Generation`](https://github.com/ixi-enki/se-template/blob/main/TemplateTools.Logic/Generation) (Generators), [`SETemplate.Logic/DataContext/ProjectDbContext.cs`](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/DataContext/ProjectDbContext.cs) (ProjectDbContext)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core template"]
  node_common["SETemplate.Common<br/>shared core<br/>[SETemplate.Common]"]
end

subgraph group_runtime["Runtime layers"]
  node_logic["SETemplate.Logic<br/>business runtime<br/>[SETemplate.Logic]"]
  node_dbcontext[("ProjectDbContext<br/>persistence boundary")]
  node_entityset["EntitySet<br/>entity access<br/>[EntitySet.cs]"]
  node_viewset["ViewSet<br/>read model access<br/>[ViewSet.cs]"]
  node_account["Account access<br/>auth subsystem<br/>[AccountManager.cs]"]
  node_webapi["SETemplate.WebApi<br/>REST host<br/>[SETemplate.WebApi]"]
  node_api_generic_entity["Entity API<br/>entity controllers"]
  node_api_generic_view["View API<br/>view controllers"]
  node_api_accounts["Accounts API<br/>auth endpoints"]
  node_angular["SETemplate.AngularApp<br/>web client"]
  node_conapp["SETemplate.ConApp<br/>bootstrap console<br/>[SETemplate.ConApp]"]
  node_codegenapp["SETemplate.CodeGenApp<br/>generator console"]
end

subgraph group_tooling["Tooling layer"]
  node_tools_logic["TemplateTools.Logic<br/>template engine"]
  node_tools_conapp["TemplateTools.ConApp<br/>tool host"]
  node_generator_pipeline["Generators<br/>code generation<br/>[Generation]"]
end

subgraph group_desktop["Desktop/AI"]
  node_mvvm["SETemplate.MVVMApp<br/>desktop client<br/>[SETemplate.MVVMApp]"]
  node_mcp["SETemplate.McpSrv<br/>mcp service<br/>[SETemplate.McpSrv]"]
end

node_common -->|"contracts/models"| node_logic
node_logic -->|"defines"| node_dbcontext
node_logic -->|"exposes"| node_entityset
node_logic -->|"exposes"| node_viewset
node_logic -->|"auth"| node_account
node_dbcontext -->|"wires"| node_entityset
node_dbcontext -->|"wires"| node_viewset
node_account -->|"guards"| node_dbcontext
node_webapi -->|"calls"| node_logic
node_webapi -->|"contains"| node_api_generic_entity
node_webapi -->|"contains"| node_api_generic_view
node_webapi -->|"contains"| node_api_accounts
node_angular -->|"consumes"| node_webapi
node_mvvm -->|"consumes"| node_logic
node_conapp -->|"boots"| node_logic
node_codegenapp -->|"inspects"| node_logic
node_tools_conapp -->|"hosts"| node_tools_logic
node_tools_logic -->|"drives"| node_generator_pipeline
node_generator_pipeline -->|"emits"| node_logic
node_generator_pipeline -->|"emits"| node_webapi
node_generator_pipeline -->|"emits"| node_angular
node_generator_pipeline -->|"emits"| node_mvvm
node_tools_logic -->|"runs under"| node_tools_conapp
node_mcp -->|"integrates"| node_tools_logic

click node_common "https://github.com/ixi-enki/se-template/blob/main/SETemplate.Common"
click node_logic "https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic"
click node_dbcontext "https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/DataContext/ProjectDbContext.cs"
click node_entityset "https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/DataContext/EntitySet.cs"
click node_viewset "https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/DataContext/ViewSet.cs"
click node_account "https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/Modules/Account/AccountManager.cs"
click node_webapi "https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi"
click node_api_generic_entity "https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi/Controllers/GenericEntityController.cs"
click node_api_generic_view "https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi/Controllers/GenericViewController.cs"
click node_api_accounts "https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi/Controllers/AccountsController.cs"
click node_angular "https://github.com/ixi-enki/se-template/blob/main/SETemplate.AngularApp"
click node_mvvm "https://github.com/ixi-enki/se-template/blob/main/SETemplate.MVVMApp"
click node_conapp "https://github.com/ixi-enki/se-template/blob/main/SETemplate.ConApp"
click node_codegenapp "https://github.com/ixi-enki/se-template/blob/main/SETemplate.CodeGenApp"
click node_tools_logic "https://github.com/ixi-enki/se-template/blob/main/TemplateTools.Logic"
click node_tools_conapp "https://github.com/ixi-enki/se-template/blob/main/TemplateTools.ConApp"
click node_generator_pipeline "https://github.com/ixi-enki/se-template/blob/main/TemplateTools.Logic/Generation"
click node_mcp "https://github.com/ixi-enki/se-template/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 toneBlue
class node_logic,node_dbcontext,node_entityset,node_viewset,node_account,node_webapi,node_api_generic_entity,node_api_generic_view,node_api_accounts,node_angular,node_conapp,node_codegenapp toneAmber
class node_tools_logic,node_tools_conapp,node_generator_pipeline toneMint
class node_mvvm,node_mcp toneRose
```

## Components

### Core template

Shared contracts and reusable domain primitives.

- [SETemplate.Common](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Common): shared core · Domain-agnostic contracts, models, enums, validations, and utilities reused across the solution. · `SETemplate.Common`

### Runtime layers

Backend business, persistence, API, and client hosts.

- [SETemplate.Logic](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic): business runtime · Central business layer with entities, context, security, and account management. · `SETemplate.Logic`
- [ProjectDbContext](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/DataContext/ProjectDbContext.cs): persistence boundary · Main data context that wires entities, views, and security-aware access. · `SETemplate.Logic/DataContext/ProjectDbContext.cs`
- [EntitySet](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/DataContext/EntitySet.cs): entity access · Generic entity collection abstraction with internal and security variants. · `SETemplate.Logic/DataContext/EntitySet.cs`
- [ViewSet](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/DataContext/ViewSet.cs): read model access · Generic view/query abstraction for projecting data through the logic layer. · `SETemplate.Logic/DataContext/ViewSet.cs`
- [Account access](https://github.com/ixi-enki/se-template/blob/main/SETemplate.Logic/Modules/Account/AccountManager.cs): auth subsystem · Accounts, roles, sessions, password rules, and authorization helpers. · `SETemplate.Logic/Modules/Account/AccountManager.cs`
- [SETemplate.WebApi](https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi): REST host · HTTP boundary exposing logic operations through controllers, middleware, and DTOs. · `SETemplate.WebApi`
- [Entity API](https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi/Controllers/GenericEntityController.cs): entity controllers · Generic REST controllers for entity CRUD and security-gated operations. · `SETemplate.WebApi/Controllers/GenericEntityController.cs`
- [View API](https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi/Controllers/GenericViewController.cs): view controllers · Generic REST controllers for read-only view access. · `SETemplate.WebApi/Controllers/GenericViewController.cs`
- [Accounts API](https://github.com/ixi-enki/se-template/blob/main/SETemplate.WebApi/Controllers/AccountsController.cs): auth endpoints · Login/session endpoints and account-facing HTTP operations. · `SETemplate.WebApi/Controllers/AccountsController.cs`
- [SETemplate.AngularApp](https://github.com/ixi-enki/se-template/blob/main/SETemplate.AngularApp): web client · Angular frontend shell with pages, base components, services, guards, and interceptors. · `SETemplate.AngularApp`
- [SETemplate.ConApp](https://github.com/ixi-enki/se-template/blob/main/SETemplate.ConApp): bootstrap console · Initialization console for database setup, seeding, and maintenance tasks. · `SETemplate.ConApp`
- [SETemplate.CodeGenApp](https://github.com/ixi-enki/se-template/blob/main/SETemplate.CodeGenApp): generator console · Console entry point focused on code generation from the compiled logic assembly. · `SETemplate.CodeGenApp`

### Tooling layer

Template management, code generation, and synchronization.

- [TemplateTools.Logic](https://github.com/ixi-enki/se-template/blob/main/TemplateTools.Logic): template engine · Core tooling logic for copying, preprocessing, generating, and synchronizing template solutions. · `TemplateTools.Logic`
- [TemplateTools.ConApp](https://github.com/ixi-enki/se-template/blob/main/TemplateTools.ConApp): tool host · Console host that orchestrates template management commands and automation flows. · `TemplateTools.ConApp`
- [Generators](https://github.com/ixi-enki/se-template/blob/main/TemplateTools.Logic/Generation): code generation · Backend/frontend generators for common, logic, Web API, Angular, MVVM, and diagrams. · `TemplateTools.Logic/Generation`

### Desktop/AI

Avalonia shell and MCP service integration.

- [SETemplate.MVVMApp](https://github.com/ixi-enki/se-template/blob/main/SETemplate.MVVMApp): desktop client · Avalonia MVVM desktop template with views, view models, and dialogs. · `SETemplate.MVVMApp`
- [SETemplate.McpSrv](https://github.com/ixi-enki/se-template/blob/main/SETemplate.McpSrv): mcp service · MCP server for AI assistant integration and template guidance utilities. · `SETemplate.McpSrv`

## Connections

- SETemplate.Common → SETemplate.Logic: contracts/models · Logic builds on common abstractions and reusable base models.
- SETemplate.Logic → ProjectDbContext: defines · Business layer centers on the main persistence context.
- SETemplate.Logic → EntitySet: exposes · Entities are accessed through generic entity set abstractions.
- SETemplate.Logic → ViewSet: exposes · Read models are accessed through generic view set abstractions.
- SETemplate.Logic → Account access: auth · Account management and authorization live inside Logic.
- ProjectDbContext → EntitySet: wires · Context composes entity sets for persistence operations.
- ProjectDbContext → ViewSet: wires · Context composes view sets for query operations.
- Account access → ProjectDbContext: guards · Security partials and session tokens gate access to context and sets.
- SETemplate.WebApi → SETemplate.Logic: calls · REST controllers translate HTTP requests into logic operations.
- SETemplate.WebApi → Entity API: contains · Generic entity controllers form the CRUD API surface.
- SETemplate.WebApi → View API: contains · Generic view controllers form the query API surface.
- SETemplate.WebApi → Accounts API: contains · Account endpoints handle logon and session flows.
- SETemplate.AngularApp → SETemplate.WebApi: consumes · Frontend talks to the REST host through generated HTTP services.
- SETemplate.MVVMApp → SETemplate.Logic: consumes · Desktop UI binds to the shared domain and model concepts.
- SETemplate.ConApp → SETemplate.Logic: boots · Initialization console uses Logic for setup, seeding, and synchronization.
- SETemplate.CodeGenApp → SETemplate.Logic: inspects · Code generation entry point reads compiled logic metadata.
- TemplateTools.ConApp → TemplateTools.Logic: hosts · Console host orchestrates the template tooling engine.
- TemplateTools.Logic → Generators: drives · Tooling logic coordinates generators, copy/sync, and preprocessing.
- Generators → SETemplate.Logic: emits · Generators produce logic-side artifacts from discovered entities and views.
- Generators → SETemplate.WebApi: emits · Generators produce controllers, DTOs, and API glue.
- Generators → SETemplate.AngularApp: emits · Generators produce frontend models and service scaffolding.
- Generators → SETemplate.MVVMApp: emits · Generators produce desktop models and MVVM scaffolding.
- TemplateTools.Logic → TemplateTools.ConApp: runs under · Template management workflows are executed through the console host.
- SETemplate.McpSrv → TemplateTools.Logic: integrates · AI-facing server hooks into tooling and guidance workflows.
