SophiChain Architecture
Developer's Guide: System Design & Technical Architecture
📖 Overview
This section contains prescriptive architectural guidelines for building SophiChain modules. All developers and contributors MUST follow these patterns to ensure consistency, quality, and maintainability across the platform.
Target Audience: Module developers, architects, contributors
📚 Core Architecture Guides
✅ Essential Reading
MUST READ before creating any module:
-
Domain-Driven Design - Tactical DDD patterns
- Entities, Value Objects, Aggregates
- Domain Services, Repositories
- Bounded Contexts, Events
-
Event-Driven Architecture - Async processing patterns
- Local vs Distributed Events
- Outbox Pattern implementation
- Event Handler best practices
-
Pluggable Provider Pattern - External integrations
- Provider interface design
- NuGet package structure
- Auto-discovery patterns
-
Extensibility Patterns - Module customization without source modification
- IHasExtraProperties for dynamic properties
- Service override and replacement
- DTO extensions and Object Extensions
- Repository customization patterns
-
Clean Architecture Layers - Layer responsibilities and dependencies
- Domain, Application, Infrastructure, Presentation layers
- Dependency rules and layer boundaries
- Module structure template
-
Multi-Tenancy Patterns - Data isolation and tenant management
- IMultiTenant implementation
- Automatic data filtering
- Tenant context switching
-
API Design Guidelines - RESTful API conventions
- Application Services pattern
- DTOs and Auto API Controllers
- Best practices
-
Security Architecture - Authentication, authorization, data protection
- Permission system
- Authorization patterns
- JWT authentication
-
Performance Optimization - Caching, indexing, query optimization
- IDistributedCache usage
- Caching strategies
- Query optimization
-
Testing Strategy - Unit, integration, and E2E testing
- Test structure and patterns
- Arrange-Act-Assert
- Shouldly assertions
🎯 Quick Start for Developers
Creating a New Module
Follow this sequence:
- Define Bounded Context - Identify domain boundaries
- Design Entities & Aggregates - Follow DDD Guide
- Define Domain Events - Use Event-Driven Guide
- Create Repositories - One per aggregate root
- Implement Domain Services - Multi-entity coordination
- Build Application Services - Use cases and DTOs
- Add Event Handlers - React to domain events
- Create Provider Interfaces - Follow Provider Pattern
- Build UI Components - Blazor pages and components
Checklist for Code Review
Domain Layer
- All entities inherit from ABP base classes
-
IMultiTenantimplemented for tenant isolation -
IHasExtraPropertiesimplemented for extensibility - Business logic in domain layer, not application layer
- Domain events published for state changes
- Repository interfaces defined (one per aggregate root)
Application Layer
- Event handlers are idempotent
- Application services use interface (
IMyAppService) - All methods are
virtualfor extensibility
Extensibility
- Provider interfaces in Domain layer
- All public methods marked
virtual - DTOs support extra properties
- Type providers for extensible enums
Infrastructure
- Repository implementations in Infrastructure layer
- Repository methods are
virtual
Testing & Documentation
- Comprehensive unit tests
- API follows RESTful conventions
- Extension points documented
📦 Module Structure Template
SophiChain.{ModuleName}/
├── src/
│ ├── SophiChain.{ModuleName}.Domain.Shared/
│ │ ├── {Context}/
│ │ │ ├── Enums/
│ │ │ ├── Constants/
│ │ │ └── ValueObjects/
│ │ └── ErrorCodes.cs
│ │
│ ├── SophiChain.{ModuleName}.Domain/
│ │ ├── {Context}/
│ │ │ ├── Entities/
│ │ │ ├── DomainServices/
│ │ │ └── Events/
│ │ └── Repositories/
│ │
│ ├── SophiChain.{ModuleName}.Application.Contracts/
│ │ ├── {Context}/
│ │ │ ├── Dtos/
│ │ │ └── I{Context}AppService.cs
│ │ └── Permissions/
│ │
│ ├── SophiChain.{ModuleName}.Application/
│ │ ├── {Context}/
│ │ │ ├── {Context}AppService.cs
│ │ │ ├── EventHandlers/
│ │ │ └── AutoMapperProfile.cs
│ │
│ ├── SophiChain.{ModuleName}.MongoDB/
│ │ ├── Repositories/
│ │ └── {ModuleName}MongoDbContext.cs
│ │
│ └── SophiChain.{ModuleName}.Blazor/
│ ├── Pages/
│ └── Components/
│
└── test/
├── SophiChain.{ModuleName}.Domain.Tests/
├── SophiChain.{ModuleName}.Application.Tests/
└── SophiChain.{ModuleName}.TestBase/
🔍 Applying These Patterns
When Building New Modules
Follow these architectural patterns:
- Define clear bounded contexts for your domain
- Design aggregates with proper invariants
- Use domain services for complex business logic
- Implement pluggable providers for external services
- Publish domain events for side effects
- Keep entities and value objects in Domain layer
- Apply event-driven architecture consistently
Module Structure Template:
Domain- Entities, value objects, domain services, repository interfacesApplication- Application services, DTOs, mappersHttpApi- Controllers (thin pass-through)MongoDB/EntityFrameworkCore- Repository implementationsBlazor- UI components- Separate provider packages - External integrations
🎓 Learning Resources
ABP Framework Documentation
Domain-Driven Design
Architecture Patterns
🤝 Contributing
See: Contributing Guide
Architecture Review Process:
- Submit architectural design document (ADD)
- Core team review (DDD compliance, ABP patterns)
- Approved → Implementation
- Code review (pattern compliance)
- Merge
📞 Support
- Questions: GitHub Discussions
- Architecture Review: Tag
@architecturein PR - Best Practices: See individual guide documents