Philosophy
Archetypy Oprogramowania (Software Archetypes) is a collection of reusable, domain-driven architectural patterns built around universal business concepts. Rather than providing generic frameworks, this project delivers concrete implementations of patterns that recur across different business domains.The project is licensed under CC BY-NC-SA 4.0 - free for learning and non-commercial use. Commercial use requires permission from the authors.
Core Principles
The architecture is built on several foundational principles:Domain-Driven Design
Domain-Driven Design
Each module represents a complete bounded context with its own ubiquitous language. The codebase is organized around business concepts (Accounting, Pricing, Product, Party, Inventory) rather than technical layers.
Functional Error Handling
Functional Error Handling
The
Result<F, S> monad eliminates null checks and exceptions for expected failures. Every operation that can fail returns either Success<S> or Failure<F>, making error paths explicit and composable.Facade Pattern for Encapsulation
Facade Pattern for Encapsulation
Every module exposes a single entry point - a Facade class that hides internal complexity. Clients interact only with:
- Commands (write operations)
- Queries (read operations)
- Views (read models)
Event-Driven Architecture
Event-Driven Architecture
Domain events capture significant business occurrences. The system uses an
EventPublisher interface with in-memory implementation for decoupled communication between modules.Immutability by Default
Immutability by Default
Value objects and entities favor immutability. Java records are used extensively for:
- Value objects (
Money,Quantity,AccountId) - Commands and queries
- View models
Architecture at a Glance
The project consists of 11 modules, each implementing a specific business archetype:Common
Foundation utilities:
Result monad, event infrastructure, preconditions, and collection transformations.Quantity
Type-safe quantity measurements with units (kg, liters, pieces) and
Money implementation with multi-currency support.Accounting
Double-entry bookkeeping system with accounts, transactions, entries, and temporal queries (balance as-of date).
Pricing
Flexible pricing calculations with multiple calculator types, components, versioning, and interpretation patterns (total/unit/marginal).
Product
Product type definitions with features, constraints, and tracking strategies (individually tracked, batch, bulk).
Party
Party/Role pattern for modeling people, organizations, and their relationships with address management.
Inventory
Inventory tracking with product instances, availability management, and resource reservation.
Ordering
Order management with line items, state machines, and order processing workflows.
Graphs
Graph data structures for representing hierarchies and relationships.
Rules
Business rules engine for encoding complex domain logic.
Plan vs Execution
Temporal modeling for comparing planned activities against actual execution.
Module Structure
Each module follows a consistent internal structure:Technology Stack
The project uses:- Java 21 with modern features (records, sealed interfaces, pattern matching)
- Maven for build and dependency management
- In-memory repositories for examples (easily replaced with real persistence)
- JavaMoney for currency handling
- JUnit for testing
The architecture is persistence-agnostic. Repository interfaces can be implemented with JPA, JDBC, MongoDB, or any other storage technology.
Learning Path
We recommend this learning sequence:- Archetypes - Understand the business archetypes and their relationships
- Design Patterns - Deep dive into the technical patterns used
- Module-specific guides - Explore individual modules based on your domain interests
Authors
Archetypy Oprogramowania is created and maintained by:- Bartłomiej Słota
- Jakub Pilimon
- Sławomir Sobótka
