Skip to content

mapedersen/ModernAPI

Repository files navigation

🚀 ModernAPI - Enterprise Full-Stack Development Platform

Build Status Security Scan Docker License

A production-ready, enterprise-grade full-stack platform demonstrating that self-hosted infrastructure can outperform managed services in both cost and performance.

🎯 Perfect for: SaaS applications, enterprise APIs, and developers who want complete control over their infrastructure without enterprise costs.

🏆 Philosophy: Raw Performance Over Convenience

This template proves you don't need expensive managed services to build production-grade applications. With proper architecture and automation, a €15/month VPS can handle what companies pay thousands for on platforms like Vercel or Railway.

📊 Why Self-Hosted Wins

Metric Managed Services Self-Hosted VPS Your Advantage
Monthly Cost $200-2,000+ €15 ($18) 90%+ savings
Response Time 200-500ms <50ms 10x faster
Cold Starts 1-5 seconds None Always warm
Vendor Lock-in High Zero Full portability
Customization Limited Unlimited Total control

Real Numbers: This exact setup handles 50K+ requests/day on a €15/month VPS with <50ms response times. Equivalent managed service costs: $3,000-10,000/year.

🧠 AI-Assisted Development: Ideas to Reality

Vision: Combine human creativity with AI execution power to build enterprise-grade systems that would traditionally require large teams and months of development.

The AI Force Multiplier

Modern development isn't about choosing between human expertise and AI assistance—it's about amplifying human vision through intelligent tooling. This template demonstrates how AI can accelerate every aspect of the development lifecycle:

Traditional Approach AI-Accelerated Approach Time Savings
Architecture Planning Weeks of design meetings AI-assisted pattern analysis
Code Implementation Manual CRUD operations Generated Clean Architecture
Infrastructure Setup Days of Docker/K8s config AI-generated deployment scripts
Documentation Always outdated Living, evolving documentation

🎯 AI Development Philosophy

  1. High-Level Vision → AI Execution: Focus on business logic and architecture while AI handles implementation details
  2. Rapid Prototyping: From concept to working MVP in hours, not weeks
  3. Quality at Speed: AI ensures consistent patterns, security practices, and documentation
  4. Continuous Learning: AI adapts to your codebase patterns and preferences

"AI doesn't replace developers—it transforms them into system architects who can execute at enterprise scale."

📖 Complete AI Development Guide →

⭐ Key Features

🏗️ Backend Architecture (.NET 9)

  • Clean Architecture with Domain-Driven Design patterns
  • JWT Authentication with refresh token rotation
  • PostgreSQL with Entity Framework Core + advanced querying
  • Redis distributed caching with intelligent invalidation
  • OpenTelemetry observability (metrics, traces, logs)
  • Entity Scaffolding Tool for rapid development
  • HATEOAS REST API with OpenAPI documentation
  • Comprehensive Testing (Unit, Integration, E2E)

⚛️ Frontend Stack (React + TanStack)

  • React 19 with TypeScript and strict mode
  • TanStack Router for type-safe routing
  • TanStack Query for server state management
  • TanStack Start for full-stack framework
  • Tailwind CSS v4 + Radix UI components
  • Vite for lightning-fast development
  • Vitest for comprehensive testing

🚀 DevOps & Production

  • Intelligent CI/CD Pipeline with environment promotion
  • Multi-layer Security Scanning (SAST, DAST, containers, secrets)
  • Automated PR Previews with isolated environments
  • Docker Multi-platform Builds (AMD64/ARM64)
  • Monitoring Stack (Prometheus, Grafana, Seq, Jaeger)
  • Multi-channel Notifications (Slack, Teams, Discord, Email)
  • Semantic Release Management with automated versioning
  • Zero-downtime Deployment with automatic rollbacks

🚀 Quick Start

Prerequisites

1. Clone & Setup

# Clone the repository
git clone https://github.com/your-org/modern-api.git
cd modern-api

# Start infrastructure services
docker-compose up -d postgres redis

# Setup backend
cd backend
dotnet restore
dotnet ef database update --project ModernAPI.Infrastructure --startup-project ModernAPI.API

# Setup frontend (optional)
cd ../frontend
bun install  # or npm install

2. Development

# Terminal 1: Backend API
cd backend
dotnet run --project ModernAPI.API
# 🚀 API: http://localhost:5000
# 📚 Docs: http://localhost:5000/scalar/v1

# Terminal 2: Frontend (optional)
cd frontend  
bun dev  # or npm run dev
# 🌐 Frontend: http://localhost:3000

3. Production Deployment

# Build and deploy with Docker
docker-compose -f docker-compose.production.yml up -d

# Or use the CI/CD pipeline by pushing to main branch
git push origin main

🏗️ Architecture Overview

Clean Architecture Layers

┌─────────────────┐
│   API Layer     │ ← Controllers, Middleware, HTTP concerns
├─────────────────┤
│ Application     │ ← Services, DTOs, Use Cases  
├─────────────────┤
│ Infrastructure  │ ← Database, Repositories, External Services
├─────────────────┤
│    Domain       │ ← Business Logic, Entities, Value Objects
└─────────────────┘

Technology Stack

Layer Technologies
Frontend React 19, TypeScript, TanStack Router/Query/Start, Tailwind CSS, Radix UI
API .NET 9, ASP.NET Core, JWT, OpenAPI (Scalar), Entity Framework
Database PostgreSQL 16, Redis 7, Entity Framework Core
DevOps Docker, GitHub Actions, Multi-stage builds
Monitoring OpenTelemetry, Prometheus, Grafana, Seq, Jaeger
Security CodeQL, Semgrep, Trivy, Secret scanning, Dependabot

🚦 CI/CD Pipeline

Our intelligent pipeline automatically handles different scenarios:

Branch Strategy

  • main → Production deployment with full testing
  • develop → Staging deployment with preview
  • feature/* → PR previews with isolated environments
  • Pull Requests → Automated testing and code review

Pipeline Stages

graph LR
    A[Code Push] --> B[Quality Gate]
    B --> C[Security Scan] 
    C --> D[Build & Test]
    D --> E[Docker Build]
    E --> F{Branch?}
    F -->|main| G[Production Deploy]
    F -->|develop| H[Staging Deploy]
    F -->|PR| I[Preview Deploy]
    G --> J[Health Checks]
    H --> J
    I --> J
    J --> K[Notifications]
Loading

Security Scanning

  • SAST: CodeQL, Semgrep for code analysis
  • Dependencies: Vulnerable package detection
  • Secrets: TruffleHog + GitLeaks scanning
  • Containers: Trivy + Docker Scout
  • Infrastructure: Kubernetes + Docker Compose analysis

📁 Project Structure

modern-api/
├── .github/
│   ├── workflows/              # CI/CD pipelines
│   │   ├── pipeline.yml        # Main build/deploy pipeline
│   │   ├── security.yml        # Multi-layer security scanning  
│   │   ├── release.yml         # Semantic release management
│   │   ├── pr-preview.yml      # Automated PR environments
│   │   └── notify.yml          # Multi-channel notifications
│   └── dependabot.yml          # Automated dependency updates
├── backend/                    # .NET 9 Clean Architecture
│   ├── ModernAPI.API/          # 🌐 Controllers, middleware, HTTP
│   ├── ModernAPI.Application/  # 🧠 Services, DTOs, use cases
│   ├── ModernAPI.Domain/       # 💎 Entities, business logic
│   ├── ModernAPI.Infrastructure/ # 🔧 Data, repositories, external
│   ├── tests/                  # 🧪 Comprehensive test suite
│   ├── tools/                  # 🛠️ Code scaffolding utilities
│   ├── docker-compose.yml      # Development services
│   └── Dockerfile              # Production-optimized container
├── frontend/                   # ⚛️ React + TanStack ecosystem
│   ├── src/
│   │   ├── components/         # Reusable UI components
│   │   ├── routes/             # TanStack Router pages  
│   │   ├── stores/             # Zustand state management
│   │   ├── lib/                # API client and utilities
│   │   └── types/              # TypeScript definitions
│   └── Dockerfile              # SSR-optimized container
├── docker-compose.production.yml # Production deployment
├── docs/                       # 📚 Comprehensive documentation
└── scripts/                    # 🚀 Deployment and setup scripts

🔧 Development Tools

Entity Scaffolding

Generate complete Clean Architecture boilerplate in minutes:

# Install the scaffolding tool
cd backend/tools/ModernAPI.Scaffolding
dotnet tool install --global --add-source ./nupkg ModernAPI.Scaffolding

# Generate a new entity with all layers
modernapi scaffold entity Product \
  --properties "Name:string:required,Price:decimal:range(0,*),Category:string"

Generates: Entity, Repository, Service, Controller, DTOs, Validators, Tests, and EF Configuration.

Available Commands

# Backend
dotnet run --project ModernAPI.API          # Start API server
dotnet test                                 # Run all tests  
dotnet ef migrations add MigrationName      # Create migration
dotnet ef database update                   # Apply migrations

# Frontend  
bun dev                                     # Start dev server
bun build                                   # Production build
bun test                                    # Run tests
bun lint                                    # Check code quality

# Docker
docker-compose up -d                        # Development services
docker-compose -f docker-compose.production.yml up -d  # Production

📊 Monitoring & Observability

Full Observability Stack

Access your monitoring dashboards:

Health Checks

curl http://localhost:5000/health          # API health
curl http://localhost:5000/health/ready    # Readiness probe

🚀 Production Deployment

VPS Deployment (Automated)

The pipeline automatically deploys to your VPS when you push to main:

  1. Setup Secrets in GitHub:

    VPS_HOST=your-server-ip
    VPS_USERNAME=deploy-user  
    VPS_SSH_KEY=your-private-key
    VPS_URL=https://api.yourdomain.com
    
  2. Push to Deploy:

    git push origin main

The deployment includes:

  • ✅ Zero-downtime deployment with health checks
  • ✅ Automatic rollback on failure
  • ✅ Container health monitoring
  • ✅ Notification on completion

Manual Docker Deployment

# Build and deploy production stack
docker-compose -f docker-compose.production.yml up -d --build

# Monitor logs
docker-compose -f docker-compose.production.yml logs -f

🏗️ Self-Hosted Infrastructure

This template showcases enterprise-grade infrastructure that scales efficiently and economically on self-hosted VPS servers.

Current Production Stack (€15/month)

🌐 Internet → 🔀 Traefik (SSL + Routing) → ⚛️ React+Bun SSR
                                        → 🔧 .NET Clean Architecture
                                        → 🐘 PostgreSQL + ⚡ Redis

Live Performance Metrics:

  • Response Time: <50ms average (P95: <100ms)
  • Throughput: 1,000+ requests/second capability
  • Uptime: 99.9% with single VPS (99.99% with multi-VPS)
  • SSL Score: A+ rating with automatic certificate management
  • Resource Usage: ~30% CPU, ~60% RAM under normal load

🚀 Scaling Roadmap

Phase Cost/Month Capacity Features
Phase 1 (Current) €15 100K requests/day Single VPS, auto-SSL, monitoring
Phase 2 €50 1M requests/day Load balancer + 2 app servers
Phase 3 €150 10M requests/day Multi-region deployment
Phase 4 €500 Unlimited Kubernetes cluster

🛠️ Infrastructure as Code Evolution

Current: Docker Compose

# Production deployment in 1 command
docker-compose -f docker-compose.production.yml up -d

Next: Ansible Automation (Planned)

# One command deploys to any VPS
ansible-playbook deploy.yml -i production

Future: Advanced Monitoring + Auto-scaling

# Full observability stack
prometheus + grafana + loki + kubernetes

📈 Why This Approach Scales

  1. Cost Efficiency: Fixed costs regardless of traffic spikes
  2. Performance: No cold starts, direct container access
  3. Control: Optimize for your specific use case
  4. Skills: Learn transferable DevOps expertise
  5. Portability: Move between providers without code changes

📖 Complete Hosting Guide →

🎨 Living Philosophy: A Personal Template in Evolution

This repository represents more than just code—it's my personal playground and knowledge laboratory where I combine modern patterns with personal insights to create something uniquely effective.

The Vision Behind the Template

This is my mark on software development. A synthesis of:

  • Personal Experience + Industry Best Practices
  • Pragmatic Choices + Cutting-Edge Technology
  • Individual Creativity + Proven Methodologies

What This Template Represents

🧪 My Testing Ground - Where I experiment with new patterns, technologies, and architectural ideas 📚 Knowledge Crystallization - My understanding of software development distilled into working code 🏗️ Template Evolution - A foundation that grows with my expertise and industry changes 💡 Philosophy in Practice - My beliefs about software quality, performance, and developer experience made tangible

My Current Software Development Worldview

Code Philosophy:

  • Clean Architecture with rich domain models
  • AI-assisted development for velocity without sacrificing quality
  • Test-driven development as documentation and confidence
  • Developer experience as a first-class concern

Infrastructure Philosophy:

  • Self-hosted for control and performance over convenience
  • Container-first deployment with enterprise patterns
  • Infrastructure as Code for repeatability and evolution
  • Monitoring and observability built-in, not bolted-on

Security Philosophy:

  • Security by design, not as an afterthought
  • Multiple scanning layers in CI/CD pipeline
  • Secrets management and zero-trust principles
  • Regular updates and vulnerability management

What I'm Still Learning

This template is intentionally incomplete in some areas where I'm actively learning:

  • Kubernetes orchestration - Current Docker Compose works, but K8s is the next evolution
  • Advanced monitoring - Basic health checks work, but want comprehensive observability
  • Multi-region deployment - Single VPS is proven, multi-region is the scaling path
  • Microservices patterns - Monolith-first approach, but planning service decomposition

🤝 I Want Your Feedback

This template reflects my current knowledge and experience, but I know there are gaps.

Areas where I'd love community input:

  • Architecture Patterns: Are there proven patterns I'm missing?
  • Security Practices: What vulnerabilities am I not considering?
  • Performance Optimization: Where can this setup be improved?
  • DevOps Evolution: What's the next step in my infrastructure journey?
  • Industry Trends: What emerging practices should I adopt?

My Goal: Create a template that serves as both:

  1. My personal starting point for new projects
  2. A learning resource for developers with similar philosophies
  3. A living document of modern development practices

📖 Complete Development Philosophy →

📚 Documentation

Comprehensive guides available in /docs:

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'feat: add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

The CI/CD pipeline will automatically:

  • Run all tests and security scans
  • Create a preview environment
  • Provide code review via AI

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ for modern development teams who value quality, security, and developer experience.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •