ModernAPI Template Implementation Guide
Deep dive into our production-ready template architecture. Learn how .NET 9, Clean Architecture, JWT authentication, and React 19 work together in this enterprise-grade solution.
ModernAPI is a production-ready full-stack template that combines .NET 9 backend with React 19 frontend. It demonstrates real-world implementation of Clean Architecture, JWT authentication, PostgreSQL integration, and modern frontend patterns with TanStack Start.
The template includes comprehensive testing, error handling, security measures, and deployment configurations. You can see it in action through the live demo - sign in and explore the dashboard that fetches real user data from the .NET API backend.
Below you'll find detailed explanations of each architectural component, implementation decisions, and how they work together to create a scalable, maintainable enterprise application.
Implementation Details
Core architectural components and how they're implemented in the ModernAPI template.
π§ Implementation
- ModernAPI.API: Controllers, Middleware, HTTP concerns only
- ModernAPI.Application: Services, DTOs, Use Cases orchestration
- ModernAPI.Infrastructure: EF Core, Repositories, External services
- ModernAPI.Domain: Entities, Value Objects, Business rules
π‘ Example
π§ Implementation
- AuthController: Login, Register, Refresh token endpoints
- JwtTokenService: Access tokens (15min) + Refresh tokens (7 days)
- RefreshToken entity: Stores refresh tokens with expiry tracking
- ExceptionMiddleware: Global error handling with RFC 7807 Problem Details
π‘ Example
π§ Implementation
- ApplicationDbContext extends IdentityDbContext<User, Role, Guid>
- Configurations in ModernAPI.Infrastructure/Data/Configurations/
- Migrations: Code-first with proper Up/Down methods
- Repository pattern: Generic Repository<T, TId> with specific implementations
π‘ Example
π§ Implementation
- TanStack Router: File-based routing with type-safe navigation
- Server Functions: BFF layer proxying to .NET API with cookie handling
- React 19: Latest features with server components
- Shadcn/ui: Production-ready components with Tailwind CSS
π‘ Example
π§ Implementation
- ModernAPI.Domain.Tests: Entity behavior and business rule validation
- ModernAPI.API.Tests: Controller endpoints and middleware testing
- ModernAPI.Infrastructure.Tests: Repository and database integration tests
- ModernAPI.IntegrationTests: Full API workflow testing
π‘ Example
π§ Implementation
- appsettings.json hierarchy: Base β Environment β User secrets
- JwtSettings with validation: Secret, Issuer, Audience, Expiry times
- Environment variables: POSTGRES_CONNECTION_STRING, ASPNETCORE_ENVIRONMENT
- Frontend environment: VITE_API_URL, VITE_ENABLE_DOCS configuration
π‘ Example
π§ Implementation
- TanStack Start Server Functions: Proxy API calls with authentication
- Cookie Management: Set/extract JWT tokens in HTTP-only cookies
- Type-Safe API Layer: TypeScript types shared between frontend and BFF
- Request/Response Transformation: Handle API contracts and error formatting
π‘ Example
π§ Implementation
- User Entity: Extends IdentityUser<Guid> with domain methods (UpdateProfile, Deactivate)
- Domain Events: UserCreatedEvent, UserEmailChangedEvent using record types
- Business Rules: Validation in domain layer (email format, display name requirements)
- Repository Interfaces: Domain defines contracts, Infrastructure implements
π‘ Example
π§ Implementation
- Multi-stage Dockerfile: Build stage (full SDK) β Runtime stage (minimal ASP.NET)
- Container Security: Non-root user, minimal attack surface, health checks
- Docker Compose: PostgreSQL 16, Redis 7, with persistent volumes and networking
- Production Optimized: Self-contained false, diagnostic disabled, proper logging
π‘ Example
π§ Implementation
- K8s Manifests: Namespace isolation, ConfigMaps for settings, Secrets for credentials
- Persistent Storage: PostgreSQL StatefulSet with persistent volumes
- Service Discovery: Internal DNS, load balancing, health check endpoints
- Deployment Automation: Bash scripts for validation, rollout, and rollback
π‘ Example
π§ Implementation
- ExceptionMiddleware: Catches all exceptions β structured logging β RFC 7807 responses
- Serilog Configuration: Structured JSON logs with correlation IDs and context
- Health Checks: Database connectivity, external services, custom health endpoints
- Monitoring Stack: Prometheus metrics, Grafana dashboards, log aggregation
π‘ Example
π§ Implementation
- Local Development: Docker Compose with hot reload, database migrations, Redis caching
- CI Pipeline: Build β Test β Security Scan β Container Build β Push to Registry
- CD Pipeline: Deploy to staging β run integration tests β promote to production
- Infrastructure as Code: Kubernetes manifests, Terraform for cloud resources
π‘ Example
Technology Stack
Carefully chosen technologies that embody our principles and enable rapid, reliable development.
Container Architecture & Deployment
How our containers interact and the automated deployment pipeline from development to production.
β’ Connects to PostgreSQL on port 5432
β’ Uses Redis for caching on port 6379
β’ Health check: /health endpoint
β’ StatefulSet for ordered deployment
β’ Automated backups and migrations
β’ Connection pooling and monitoring
β’ LRU eviction policy, 256MB memory limit
β’ Persistent storage for session continuity
β’ Password authentication enabled
Start Here
- Write domain tests to understand business requirements
- Model your domain entities with rich behavior
- Create repository interfaces in the domain layer
- Implement infrastructure that adapts to domain needs
As You Scale
- Add comprehensive logging and monitoring
- Implement proper caching and performance optimization
- Set up automated deployment pipelines
- Document architectural decisions with ADRs
Remember: Principles Over Practices
These principles are more important than any specific technology or framework. They should guide your decisions whether you're building with .NET, Node.js, or any other platform. The ModernAPI template is one implementationβthe principles are universal.
The Journey Continues
These twelve principles are not a destinationβthey're a compass for the journey of continuous improvement. Every codebase, every team, and every project will find its own path guided by these fundamental truths.
"The best architectures, requirements, and designs emerge from self-organizing teams that understand and apply sound principles."
β Adapted from the Agile Manifesto