Skip to content

The ship made of dead men's nails. A bit darker, but represents collection and analysis of threat data.

Notifications You must be signed in to change notification settings

ik-workshop/naglfar-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

56 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Naglfar Analytics

The ship made of dead men's nails - A Norse mythology reference representing collection and analysis of threat data for abuse protection.

Overview

Naglfar Analytics is an abuse protection system built with .NET 10.0 that acts as a defensive layer between your API gateway and backend services. It analyzes incoming requests, detects malicious patterns, and blocks abusive traffic before it reaches your core application.

Current Status: Monorepo structure established. Architecture and design phase with comprehensive documentation and diagrams.

Repository Structure: This is a monorepo containing multiple microservices including the naglfar-validation service (.NET 10.0), with planned additions for worker services, authentication, and protected demo applications.

Features

Core Functionality

  • βœ… RESTful API with .NET 10.0 Minimal APIs
  • βœ… API Versioning (URL, query string, and header-based)
  • βœ… Health check endpoints (/healthz, /readyz) for Kubernetes
  • βœ… Prometheus metrics endpoint (/metrics)
  • βœ… Swagger/OpenAPI documentation

Infrastructure

  • βœ… Traefik API Gateway (v3.6) integration
  • βœ… Docker support with multi-stage Alpine builds
  • βœ… Docker Compose orchestration with custom networking
  • βœ… Makefile automation (17+ commands)

Quality & Documentation

  • βœ… Comprehensive integration tests (10 tests, all passing)
  • βœ… Architecture diagrams (9 diagrams with automated generation)
  • βœ… Detailed system design and architecture documentation
  • βœ… Automated diagram validation and regeneration

Documentation

πŸ“š Comprehensive documentation available:

Prerequisites

Quick Start

Local Development (without Docker)

# Restore dependencies
make restore

# Build the application
make build

# Run the application
make run

The application will be available at http://localhost:5000

Using Docker

# Build Docker image
make docker-build

# Run in Docker container
make docker-run

The application will be available at http://localhost:8080

Using Docker Compose

# Start all services (API + Traefik)
make compose-up

# View logs
make compose-logs

# Stop all services
make compose-down

Testing Endpoints

Direct Access (Port 8000)

# Health check
curl http://localhost:8000/healthz

# Readiness check
curl http://localhost:8000/readyz

# API info (versioned)
curl http://localhost:8000/api/v1/info

# Prometheus metrics
curl http://localhost:8000/metrics

Via Traefik (Port 80)

# Access API through Traefik
curl -H "Host: api.local" http://localhost/healthz
curl -H "Host: api.local" http://localhost/api/v1/info

Makefile Commands

Run make help to see all available commands with descriptions.

Local Development

  • make restore - Restore .NET dependencies
  • make build - Build the application
  • make run - Run the application locally
  • make test - Run all tests
  • make test-watch - Run tests in watch mode
  • make test-coverage - Run tests with code coverage
  • make clean - Clean build artifacts

Docker Compose

  • make compose-up - Start all services with docker-compose
  • make compose-down - Stop and remove all services
  • make compose-logs - Show logs for all services
  • make validation-rebuild - Rebuild only the naglfar-validation service
  • make apigw-restart - Rebuild and restart Traefik API Gateway

Diagram Generation

  • make diagrams - Generate all SVG diagrams from Mermaid sources
  • make diagrams-validate - Validate all diagram syntax
  • make diagrams-clean - Remove generated SVG files
  • make diagrams-check - Check if Docker is available

Service-Specific Commands

The project uses modular helper makefiles for service-specific commands. Each service maintains its own helpers.mk file with build and deployment commands.

Book Store Service:

  • make docker-build-book-store - Build book-store Docker image
  • make docker-run-book-store - Run book-store container (port 8090)
  • make lock-dependencies-book-store - Generate Pipfile.lock using Docker (no local Python/pipenv needed)
  • make compose-rebuild-book-store - Rebuild book-store via docker-compose

Naglfar Validation Service:

  • make docker-build-naglfar - Build naglfar-validation Docker image
  • make docker-run-naglfar - Run naglfar-validation container
  • make docker-stop-naglfar - Stop and remove container
  • make docker-clean-naglfar - Remove Docker image

Benefits of Modular Makefiles:

  • Each service maintains its own build commands in services/<service>/helpers.mk
  • Helper makefiles are automatically included by the root Makefile
  • Services know their own directory location (location-aware)
  • Easy to add new services without modifying the root Makefile
  • Run make help to see all available commands from all services

Testing

The project includes three comprehensive testing frameworks:

End-to-End Testing (Python CLI)

Python-based CLI tool for testing user journeys through the system.

# Run all E2E tests
make e2e-all

# Run individual tests
make e2e-browse        # Browse books journey
make e2e-purchase      # Purchase book journey
make e2e-full-flow     # Complete user flow

# View results
make e2e-results

πŸ“– Documentation: testing/e2e/README.md

Performance Testing (k6)

Load and stress testing using Grafana k6.

# Run all performance tests
make perf-all

# Run individual tests
make perf-browse        # Browse books load test
make perf-full-flow     # Full user flow test
make perf-stress        # Stress test (up to 300 VUs)

# View and compare results
make perf-results
make perf-compare

πŸ“– Documentation: testing/performance/README.md

Capacity Testing (Gatling)

YAML-driven capacity testing with Gatling for defining test scenarios without code.

# Run all capacity tests
make capacity-all

# Run individual tests
make capacity-browse        # Browse capacity test
make capacity-full-flow     # Full flow capacity test
make capacity-stress        # System stress test

# View results and reports
make capacity-results
make capacity-report        # Open HTML report

Key Features:

  • Define test scenarios in YAML files (no Scala code needed)
  • Flexible load injection profiles (ramp, constant, spike)
  • Built-in authentication flow support (E-TOKEN/AUTH-TOKEN)
  • Rich HTML reports with charts and metrics
  • Performance thresholds and assertions

πŸ“– Documentation: testing/capacity/README.md

Example YAML Scenario:

name: "Browse Books Test"
injection:
  - type: rampUsers
    users: 10
    duration: 30s
scenarios:
  - name: "Browse Journey"
    steps:
      - http:
          method: GET
          path: "/api/books"
          checks:
            - status: 200

Project Structure

naglfar-analytics/                          # Monorepo root
β”œβ”€β”€ services/                               # Microservices directory
β”‚   β”œβ”€β”€ book-store/                         # Book store service (Python FastAPI)
β”‚   β”‚   β”œβ”€β”€ src/                            # Source code
β”‚   β”‚   β”œβ”€β”€ Pipfile                         # Python dependencies
β”‚   β”‚   β”œβ”€β”€ Pipfile.lock                    # Locked dependencies
β”‚   β”‚   β”œβ”€β”€ Dockerfile                      # Multi-stage Docker build
β”‚   β”‚   └── helpers.mk                      # Service-specific Makefile commands
β”‚   β”‚
β”‚   └── naglfar-validation/                 # Validation service (.NET 10.0)
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   └── NaglfartAnalytics/
β”‚       β”‚       β”œβ”€β”€ Program.cs              # Application entry point
β”‚       β”‚       β”œβ”€β”€ NaglfartAnalytics.csproj # .NET 10.0 project file
β”‚       β”‚       β”œβ”€β”€ appsettings.json        # Production configuration
β”‚       β”‚       └── appsettings.Development.json # Development configuration
β”‚       β”œβ”€β”€ tests/
β”‚       β”‚   └── NaglfartAnalytics.Tests/
β”‚       β”‚       β”œβ”€β”€ IntegrationTests.cs     # Integration tests (9 tests)
β”‚       β”‚       β”œβ”€β”€ MetricsTests.cs         # Metrics endpoint tests (1 test)
β”‚       β”‚       └── NaglfartAnalytics.Tests.csproj # Test project file
β”‚       β”œβ”€β”€ Dockerfile                      # Multi-stage Docker build (Alpine)
β”‚       └── helpers.mk                      # Service-specific Makefile commands
β”‚
β”œβ”€β”€ infrastructure/                         # Infrastructure configuration
β”‚   β”œβ”€β”€ docker-compose.yml                  # Service orchestration (API + Traefik)
β”‚   β”œβ”€β”€ helpers.mk                          # Infrastructure Makefile commands
β”‚   β”œβ”€β”€ traefik/                            # API Gateway configuration (future)
β”‚   β”œβ”€β”€ kafka/                              # Message broker configuration (future)
β”‚   β”œβ”€β”€ neo4j/                              # Graph database configuration (future)
β”‚   └── prometheus/                         # Monitoring configuration (future)
β”‚
β”œβ”€β”€ shared/                                 # Shared libraries (future)
β”‚   β”œβ”€β”€ dotnet/                             # Shared .NET libraries
β”‚   └── python/                             # Shared Python libraries
β”‚
β”œβ”€β”€ testing/                                # Testing frameworks
β”‚   β”œβ”€β”€ e2e/                                # End-to-end tests (Python CLI)
β”‚   β”œβ”€β”€ performance/                        # Performance tests (k6)
β”‚   └── capacity/                           # Capacity tests (Gatling + YAML)
β”‚
β”œβ”€β”€ scripts/                                # Automation scripts (future)
β”‚   └── ...
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ system-design.md                    # High-level system architecture
β”‚   β”œβ”€β”€ naglfar-layer-architecture.md       # Detailed component architecture
β”‚   β”œβ”€β”€ endpoints.md                        # API endpoint reference
β”‚   └── assets/
β”‚       └── diagrams/
β”‚           β”œβ”€β”€ README.md                   # Diagram workflow documentation
β”‚           β”œβ”€β”€ *.mmd                       # Mermaid source files (9 diagrams)
β”‚           └── *.svg                       # Generated SVG diagrams
β”‚
β”œβ”€β”€ Makefile                                # Build automation (17+ commands)
β”œβ”€β”€ CHANGELOG.md                            # Complete version history
└── README.md                               # This file

Development

The application uses .NET 10.0 Minimal APIs for a lightweight and performant web service with API versioning.

Adding New Endpoints

Edit services/naglfar-validation/src/NaglfartAnalytics/Program.cs to add new versioned endpoints:

// Add to v1 API group
v1Group.MapGet("/your-endpoint", () => Results.Ok(new { message = "Hello" }))
    .WithName("YourEndpoint")
    .WithDescription("Your endpoint description");

Configuration

Application settings can be configured in:

  • appsettings.json - Production settings
  • appsettings.Development.json - Development settings
  • Environment variables (prefixed with ASPNETCORE_)

Health Checks

The application provides two types of health checks:

  1. Health Check (/healthz): Indicates if the application is running and healthy
  2. Readiness Check (/readyz): Indicates if the application is ready to accept traffic

These endpoints are commonly used by:

  • Kubernetes liveness and readiness probes
  • Load balancers
  • Monitoring systems
  • Container orchestrators

Resources

License

This project is part of the ik-workshop organization.

Contributing

See CHANGELOG.md for version history and changes.

About

The ship made of dead men's nails. A bit darker, but represents collection and analysis of threat data.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •