Skip to content

Functorium Guide

Have you ever experienced business logic and technical code getting tangled together, making changes difficult and testing even harder? Functorium combines DDD tactical design with functional programming to clearly separate concerns, providing comprehensive guides covering architecture, implementation patterns, and observability for your projects.

You have likely encountered these challenges in development:

  • Business rules scattered among infrastructure code — have you struggled to identify where to make changes each time?
  • Unit testing domain logic — have you felt burdened by having to set up databases or external services?
  • As projects grow, layer dependencies become tangled — have you experienced the vicious cycle where fixing one place breaks another?

Functorium solves these problems by separating concerns with DDD tactical design patterns and controlling side effects with functional programming.

  1. Internal Architecture Design Principles — rationale for separation of concerns, layer structure, and dependency direction
  2. DDD Tactical Design Building Blocks — Value Object, Entity, Aggregate, Domain Event, Specification
  3. Application/Adapter Layer Implementation — Use Case, Port, Adapter, Pipeline, DI
  4. Testing Strategy — unit testing, integration testing, test libraries
  5. Observability — logging, metrics, and tracing specifications and implementation

The Functorium Guide is organized in WHY → WHAT → HOW order, so you can understand why each concept is needed before moving to implementation.

Functorium is a framework that combines DDD tactical design patterns with functional programming. The guide documents are arranged in DDD building block order, and each document follows the WHY → WHAT → HOW structure.

[00] 00-writing-guide.md ─── Documentation Writing Guide
Architecture
├── [00] 00-architecture-design-principles.md ─── Internal Architecture Design Principles
├── [01] 01-project-structure.md ─── Project Structure
├── [02] 02-solution-configuration.md ─── Solution Configuration
├── [02b] 02b-ci-cd-and-versioning.md ─── CI/CD Workflow and Versioning
└── [03] 03-dotnet-tools.md ─── .NET Tools
[04] 04-ddd-tactical-overview.md ─── DDD Tactical Design Overview
├── Domain Layer
│ ├── [05a] 05a-value-objects.md ─── Value Objects (Core Concepts, Validation, Implementation Patterns)
│ ├── [05b] 05b-value-objects-validation.md ─── Value Objects (Enumerations, Practical, FAQ)
│ ├── [05c] 05c-union-value-objects.md ─── Value Objects: Union Types
│ │ └── [06a] 06a-aggregate-design.md ─── Aggregate Design (WHY + WHAT)
│ │ ├── [06b] 06b-entity-aggregate-core.md ─── Entity/Aggregate Core Patterns (HOW)
│ │ └── [06c] 06c-entity-aggregate-advanced.md ─── Entity/Aggregate Advanced Patterns
│ │ └── [07] 07-domain-events.md ─── Domain Events
│ ├── [08a] 08a-error-system.md ─── Error System: Fundamentals and Naming
│ ├── [08b] 08b-error-system-domain-app.md ─── Error System: Domain/Application Errors
│ ├── [08c] 08c-error-system-adapter-testing.md ─── Error System: Adapter Errors and Testing
│ ├── [09] 09-domain-services.md ─── Domain Services
│ └── [10] 10-specifications.md ─── Specification Pattern
├── Application Layer
│ └── [11] 11-usecases-and-cqrs.md ─── Use Cases and CQRS
├── Adapter Layer
│ ├── [12] 12-ports.md ─── Port Definitions
│ ├── [13] 13-adapters.md ─── Adapter Implementation
│ ├── [14a] 14a-adapter-pipeline-di.md ─── Pipeline, DI
│ ├── [14b] 14b-adapter-testing.md ─── Unit Testing
│ └── [14c] 14c-repository-query-implementation-guide.md ─── Repository & Query Implementation Guide
├── Testing
│ ├── [15] 15a-unit-testing.md ─── Unit Testing
│ ├── [15b] 15b-integration-testing.md ─── Integration Testing
│ └── [16] 16-testing-library.md ─── Test Library
├── DTO Strategy
│ └── [17] 17-dto-strategy.md ─── DTO Strategy
├── Observability
│ ├── [18a] → spec/08-observability.md ─── Specification (moved to spec)
│ ├── [18b] 18b-observability-naming.md ─── Naming
│ ├── [19] 19-observability-logging.md ─── Logging
│ ├── [20] 20-observability-metrics.md ─── Metrics
│ └── [21] 21-observability-tracing.md ─── Tracing
├── Diagnostics
│ └── [22] 22-crash-diagnostics.md ─── Crash Dumps
└── Appendix
├── [A01] A01-vscode-debugging.md ─── VSCode Debugging
├── [A02] A02-git-reference.md ─── Git Reference
├── [A03] A03-response-type-evolution.md ─── FinResponse Type Evolution
└── [A04] A04-architecture-rules-coverage.md ─── Architecture Rules Validation Coverage

Guidance on how to set up project structure, build configuration, and CI/CD when starting a new service.

TaskReference Document
Understand architecture design principles00-architecture-design-principles.md
Project structure/folder layout01-project-structure.md
Solution config files/build scripts02-solution-configuration.md
CI/CD workflow and versioning02b-ci-cd-and-versioning.md
Tool usage (coverage/snapshot/ER diagrams)03-dotnet-tools.md

Translating business concepts into code — start with Value Objects, group them into Aggregates, and express interactions through events and errors.

TaskReference Document
DDD building blocks overview/naming/glossary04-ddd-tactical-overview.md
Creating Value Objects (validation, equality)05a-value-objects.md
Smart Enum patterns05b-value-objects-validation.md
Union Value Objects (Discriminated Union)05c-union-value-objects.md
Designing Aggregate boundaries06a-aggregate-design.md
Entity/Aggregate implementation (creation patterns)06b-entity-aggregate-core.md
Cross-Aggregate relationships, supplementary interfaces06c-entity-aggregate-advanced.md
Domain Event definition/publishing/handlers07-domain-events.md
Error type definitions and testing08a08b08c
Creating Domain Services09-domain-services.md
Creating Specifications10-specifications.md

Define use cases that expose the domain model to the outside, and separate Command/Query responsibilities.

TaskReference Document
Creating Use Cases (CQRS)11-usecases-and-cqrs.md
DTO strategy/reuse rules17-dto-strategy.md

The boundary where the domain meets the external world — define contracts with Ports and implement them with Adapters.

TaskReference Document
Defining Port interfaces12-ports.md
Adapter implementation (Repository, API, Messaging)13-adapters.md
Pipeline/DI registration, Options pattern, caching14a-adapter-pipeline-di.md
Adapter unit testing14b-adapter-testing.md
Repository & Query implementation (pagination, Dapper)14c-repository-query-implementation-guide.md

Domain purity makes testing simple. Strategy from unit testing to integration testing.

TaskReference Document
Unit testing (naming, AAA, MTP)15a-unit-testing.md
Integration testing (HostTestFixture)15b-integration-testing.md
Test library (logging/architecture/source generator/Job)16-testing-library.md
Architecture rules coverage matrixA04-architecture-rules-coverage.md

Unify the language of development and operations. Structured logging, metrics, and tracing specifications with crash diagnostics.

TaskReference Document
Observability specification08-observability.md
Crash dump setup/analysis22-crash-diagnostics.md
CategoryFormatDescription
Rule implementation codeActual C# codeCompilable-level code (types, methods, pattern examples)
Architecture flow explanationpseudo-code allowedMust label with pseudo-code or conceptual code before the code block
Code block language tagAlways specified```csharp, ```xml, ```bash, ```promql, etc.

Understand the rationale for separation of concerns, layer structure, and dependency direction first, then concretize with project folder structure and build configuration. This is the first area to reference when creating a new service.

DocumentDescription
00-architecture-design-principles.mdInternal architecture design principles (separation of concerns, layer structure, dependency direction)
01-project-structure.mdService project structure (folders, naming, dependencies)
02-solution-configuration.mdSolution root configuration files and build scripts
02b-ci-cd-and-versioning.mdCI/CD workflow and versioning (GitHub Actions, NuGet packages, MinVer, version suggestion commands)
03-dotnet-tools.md.NET tools guide (CLI tools, source generators, file-based scripts)

DDD Tactical Design (Sequential Learning Path)

Section titled “DDD Tactical Design (Sequential Learning Path)”

Build a pure domain model so that business rules do not depend on infrastructure. Guarantee immutable validation with Value Objects, set transaction boundaries with Aggregates, and achieve loose coupling with Domain Events.

#DocumentDescription
0404-ddd-tactical-overview.mdDDD tactical design overview, building block map, Functorium type mapping
05a05a-value-objects.mdValue Objects (core concepts, base classes, validation system, implementation patterns)
05b05b-value-objects-validation.mdValue Objects (enumeration patterns, practical examples, Application validation, FAQ)
05c05c-union-value-objects.mdValue Objects: Union types (Discriminated Union, state transitions, Match/Switch)
06a06a-aggregate-design.mdAggregate design (WHY + WHAT: design rules, boundary setting, anti-patterns)
06b06b-entity-aggregate-core.mdEntity/Aggregate core patterns (HOW: class hierarchy, ID, creation patterns, events)
06c06c-entity-aggregate-advanced.mdEntity/Aggregate advanced patterns (Cross-Aggregate relationships, supplementary interfaces, practical examples)
0707-domain-events.mdDomain Event definition, publishing, handler implementation
08a08a-error-system.mdError system: fundamentals and naming (WHY, Fin pattern, naming rules)
08b08b-error-system-domain-app.mdError system: Domain/Application errors (Domain/Application/Event error definition and testing)
08c08c-error-system-adapter-testing.mdError system: Adapter errors and testing (Adapter errors, Custom errors, testing best practices, checklist)
0909-domain-services.mdDomain Services (cross-Aggregate pure logic, IDomainService)
1010-specifications.mdSpecification pattern (business rule encapsulation, composition, Repository integration)

Define use cases that expose the domain model at the application boundary. Separate write and read responsibilities with CQRS, and clarify data transfer rules between layers with DTOs.

#DocumentDescription
1111-usecases-and-cqrs.mdUse Case implementation (CQRS Command/Query)
1717-dto-strategy.mdDTO strategy (layer ownership, reuse rules, conversion patterns)

The boundary where the domain meets the external world. Define contracts with Ports, implement with Adapters, and assemble with Pipeline and DI. Concrete infrastructure implementations such as Repository, external API, and messaging are located in this area.

#DocumentDescription
1212-ports.mdPort architecture, IObservablePort hierarchy, Port definition rules
1313-adapters.mdAdapter implementation (Repository, External API, Messaging, Query)
14a14a-adapter-pipeline-di.mdPipeline creation, DI registration, Options pattern
14b14b-adapter-testing.mdAdapter unit testing, E2E Walkthrough
14c14c-repository-query-implementation-guide.mdRepository & Query implementation guide

The purity of the Domain Layer makes unit testing simple, and Adapter separation makes integration test boundaries clear. The Functorium.Testing library provides tools for architecture rule validation, structured log testing, and source generator testing.

DocumentDescription
15a-unit-testing.mdUnit testing rules (naming, AAA pattern, MTP setup)
15b-integration-testing.mdIntegration testing (HostTestFixture, environment setup)
16-testing-library.mdFunctorium.Testing library (log/architecture/source generator/Job testing)

Define observability specifications so that development and operations can communicate in the same language. Build a consistent observability system from Field/Tag naming to structured logging, metrics, and distributed tracing.

DocumentDescription
08-observability.mdObservability specification (Field/Tag, Meter, message template)
18b-observability-naming.mdObservability naming guide (code, Logger methods)
19-observability-logging.mdObservability logging details
20-observability-metrics.mdObservability metrics details
21-observability-tracing.mdObservability tracing details

Guide for collecting and analyzing crash dumps for post-mortem analysis of abnormal terminations in production environments.

DocumentDescription
22-crash-diagnostics.mdCrash dump handler setup and analysis guide
DocumentDescription
A01-vscode-debugging.mdVSCode debugging and development environment setup
A02-git-reference.mdGit command reference and Git Hooks
A03-response-type-evolution.mdFinResponse type evolution history
A04-architecture-rules-coverage.mdArchitecture rules validation coverage matrix
DocumentDescription
dto-strategy-review.mdDTO mapping strategy review (DDD & Hexagonal Architecture perspective)
DocumentDescription
book-writing-guide.mdBook writing guide
00-writing-guide.mdDocumentation writing guide (guide document authoring rules)