A comprehensive medication management system built with .NET Aspire that enables users to track medications, schedules, dosing logs, and potential drug interactions.
MedicineTrack follows a microservices architecture built on .NET Aspire, providing a scalable and cloud-native solution for medication management.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β API Gateway (Port 5000) β
β Route: /medicines/* /configs/* β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
β β
βββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββ
β MedicineTrack.Api β β MedicineTrack.Configuration β
β (Port 5001) β β (Port 5002) β
β β β β
β β’ Medication Management β β β’ Organization Management β
β β’ Medication Logging β β β’ User Management β
β β’ Drug Interaction Checking β β β’ System Configuration β
β β’ Medication Database Lookup β β β
βββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββ
β β
βββββββββββββββββ¬ββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Infrastructure β
β β
β β’ PostgreSQL (Medication & Configuration DBs) β
β β’ Redis/Valkey (Caching) β
β β’ Entity Framework Core (Data Access) β
β β’ Migrations (Database Schema Management) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Telemetry & Observability β
β β
β β’ OpenTelemetry Collector (OTLP: 4317/4318) β
β β’ ClickHouse (Telemetry Storage) β
β - otel_traces β
β - otel_logs β
β - otel_metrics_* β
β β’ Aspire Dashboard (Structured logs, traces, metrics) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
medicine_track/
βββ src/
β βββ MedicineTrack.AppHost/ # .NET Aspire App Host
β βββ MedicineTrack.Api/ # Main API service
β βββ MedicineTrack.Configuration/ # Configuration service
β βββ MedicineTrack.Gateway/ # API Gateway (YARP)
β βββ MedicineTrack.Medication.Data/ # Medication domain models
β βββ MedicineTrack.Configuration.Data/ # Configuration domain models
β βββ MedicineTrack.Medication.Migrations/ # Database migrations
β βββ MedicineTrack.Configuration.Migrations/ # Database migrations
β βββ MedicineTrack.Tests/ # Unit tests
β βββ MedicineTrack.End2EndTests/ # End-to-end tests
βββ scripts/
β βββ validate-clickhouse-ingestion.sh # ClickHouse telemetry validation
β βββ clickhouse-test-queries.sql # Example ClickHouse queries
βββ clickhouse-init/ # ClickHouse schema initialization
βββ clickhouse-config/ # ClickHouse user/network config
βββ otel-collector-config.yaml # OpenTelemetry Collector config
βββ deploy-aspire.sh # Kubernetes deployment script
βββ README.md
- Medication Management: Create, read, update, and delete medications with detailed information
- Flexible Scheduling: Support for complex medication regimens with multiple frequency types
- Medication Logging: Track when medications are taken, skipped, or taken as needed
- Drug Interaction Checking: Identify potential dangerous medication combinations
- Medication Database: Search and lookup medications with NDC codes and detailed information
- User Management: Multi-tenant system with organization and user management
- Health Monitoring: Built-in health checks and observability
Supports various frequency types:
- Daily: Once or multiple times per day
- Weekly: Specific days of the week
- Monthly: Specific days of the month
- As Needed: PRN medications
- Custom Intervals: Every X days, weeks, or months
- Basic information (name, generic name, brand name, strength, form)
- Physical properties (shape, color)
- Lifecycle management (start date, end date, archival)
- Multiple independent schedules
- Flexible frequency patterns
- Multiple daily dosing times
- Quantity and unit tracking
- Day-of-week specifications
- Timestamp tracking (taken vs. logged)
- Status tracking (taken, skipped, as-needed)
- Actual quantity taken
- Schedule association
- Notes and additional context
- Framework: .NET 9.0 with ASP.NET Core Minimal APIs
- Orchestration: .NET Aspire
- Database: PostgreSQL with Entity Framework Core
- Caching: Redis/Valkey
- API Gateway: YARP (Yet Another Reverse Proxy)
- Documentation: OpenAPI/Swagger
- Testing: xUnit, End-to-end testing framework
- Deployment: Kubernetes with Aspire integration
- .NET 9.0 SDK
- Docker Desktop
- Kubernetes cluster (for production deployment)
- PostgreSQL (or use Docker container)
- Redis (or use Docker container)
-
Clone the repository
git clone <repository-url> cd medicine_track
-
Install .NET Aspire workload
dotnet workload install aspire
-
Run the application
cd src dotnet run --project MedicineTrack.AppHost -
Access the services
- Aspire Dashboard:
http://localhost:15888 - API Gateway:
http://localhost:5000 - Medicine API:
http://localhost:5001 - Configuration API:
http://localhost:5002 - ClickHouse HTTP:
http://localhost:8123 - Aspire Dashboard:
https://localhost:17217(or the URL printed byaspire run)
- Aspire Dashboard:
Once running, access the OpenAPI documentation:
- Gateway API:
http://localhost:5000/openapi - Medicine API:
http://localhost:5001/openapi - Configuration API:
http://localhost:5002/openapi
POST /- Create new medicationGET /- List user medications (with filtering)GET /{medicationId}- Get specific medicationPUT /{medicationId}- Update medicationDELETE /{medicationId}- Archive medication
POST /medications/{medicationId}/logs- Log medication doseGET /medication-logs- Get all user logsGET /medications/{medicationId}/logs- Get logs for specific medicationPUT /medication-logs/{logId}- Update log entryDELETE /medication-logs/{logId}- Delete log entry
GET /search- Search medication database
POST /check- Check for drug interactions
POST /- Create organizationGET /- List organizationsGET /{organizationId}- Get specific organizationPUT /{organizationId}- Update organizationDELETE /{organizationId}- Delete organization
POST /- Create userGET /- List usersGET /{userId}- Get specific userPUT /{userId}- Update userDELETE /{userId}- Delete user
cd src
dotnet test MedicineTrack.Testscd src
dotnet test MedicineTrack.End2EndTestsUse the provided .http files in VS Code with the REST Client extension:
src/MedicineTrack.Api/Medicines.httpsrc/MedicineTrack.Api/Health.httpsrc/MedicineTrack.Configuration/MedicineTrack.Configuration.httpsrc/MedicineTrack.Gateway/MedicineTrack.Gateway.http
Use the provided deployment script:
./deploy-aspire.shThis script will:
- Check prerequisites (kubectl, Docker, .NET SDK)
- Create Kubernetes namespace
- Build the application
- Generate Aspire manifest
- Convert to Kubernetes manifests using aspirate
- Deploy to local cluster
- Set up port forwarding
-
Build the application
cd src dotnet build -
Generate Aspire manifest
dotnet run --project MedicineTrack.AppHost --publisher manifest --output-path ../infra/aspire-manifest.json
-
Install aspirate tool
dotnet tool install -g aspirate
-
Generate Kubernetes manifests
cd infra aspirate generate \ --input-path aspire-manifest.json \ --output-path k8s-manifests \ --namespace medicine-track \ --container-registry docker.io \ --container-image-tag latest -
Apply to Kubernetes
kubectl apply -f k8s-manifests -n medicine-track
Configure the following environment variables for production:
ASPNETCORE_ENVIRONMENT=ProductionConnectionStrings__DefaultConnection=<PostgreSQL connection string>ConnectionStrings__Redis=<Redis connection string>
The application uses Entity Framework Core with PostgreSQL. Database migrations are handled by dedicated migration projects:
MedicineTrack.Medication.MigrationsMedicineTrack.Configuration.Migrations
Redis/Valkey is used for caching. Configuration is handled through .NET Aspire's service discovery.
The API Gateway uses YARP for reverse proxy functionality. Routes are configured in appsettings.json:
/medicines/*β Medicine API/configs/*β Configuration API
- Gateway:
GET /health - Medicine API:
GET /health - Configuration API:
GET /health - ClickHouse:
GET http://localhost:8123/ping
The Aspire dashboard provides comprehensive monitoring:
- Service health and metrics
- Distributed tracing
- Log aggregation
- Resource utilization
Access at: http://localhost:15888 (development) or via port forwarding (Kubernetes)
MedicineTrack uses OpenTelemetry and ClickHouse for comprehensive telemetry storage and analysis. The Aspire dashboard is also populated directly by the .NET services for structured logs, traces, and metrics.
Services (Gateway, API, Config, E2E Runner)
β
β OTLP (gRPC) ββββββββββββββββββββββ
β β
OpenTelemetry Collector (4317/4318) β
β β
β clickhouse exporter (HTTP 8123) β
β β
ClickHouse (database: telemetry) β
βββ otel_traces β
βββ otel_logs β
βββ otel_metrics_* β
β
β OTLP (gRPC) via Aspire DCP proxy β
β β
Aspire Dashboard β
βββ Structured logs, traces, metrics
ClickHouse is started automatically by the Aspire AppHost. No manual setup is required. The schema is created automatically by the OpenTelemetry Collector ClickHouse exporter (create_schema: true).
Access the ClickHouse HTTP interface at http://localhost:8123 when the AppHost is running.
otel_traces - Distributed traces and spans
SELECT *
FROM telemetry.otel_traces
WHERE Timestamp > now() - INTERVAL 10 MINUTE
ORDER BY Timestamp DESC
LIMIT 10otel_logs - Structured application logs
SELECT *
FROM telemetry.otel_logs
WHERE SeverityText IN ('Error', 'Fatal')
AND Timestamp > now() - INTERVAL 1 HOUR
ORDER BY Timestamp DESCotel_metrics_* - Metric data points (otel_metrics_sum, otel_metrics_histogram, otel_metrics_gauge, etc.)
Query across services using a TraceId:
SELECT
Timestamp,
ServiceName,
SpanName,
StatusCode,
Duration
FROM telemetry.otel_traces
WHERE TraceId = 'your-trace-id-here'
ORDER BY TimestampThis returns all spans for a single request across all services.
See scripts/clickhouse-test-queries.sql for comprehensive query examples:
- Total traces per service
- Error rate by service
- Slowest spans
- Logs by severity
- Recent error logs
- Metric points by service
Run the validation script to test telemetry ingestion:
bash scripts/validate-clickhouse-ingestion.shThis script:
- Tests ClickHouse connectivity
- Verifies telemetry table existence
- Checks for recent trace data
- Checks for recent log data
- Checks for recent metric data
- Prints a sample of recent traces
The Aspire dashboard receives telemetry directly from each service and provides:
- Structured Logs - Search and filter application logs
- Traces - End-to-end distributed trace visualization
- Metrics - Charts and metric exploration
Access the dashboard URL printed by aspire run (e.g., https://localhost:17217/login?t=<token>).
Connection Issues
# Test ClickHouse connectivity
curl http://localhost:8123/ping
# Test OTEL Collector OTLP HTTP endpoint
curl -X POST http://localhost:4318/v1/traces \
-H "Content-Type: application/x-protobuf" \
-d ''No Data in ClickHouse
- Verify the OTEL Collector container is running (check Aspire dashboard)
- Check the ClickHouse exporter logs for connection errors
- Ensure services are exporting to the collector (
OTEL_COLLECTOR_OTLP_GRPCis set) - Tables are created automatically on first insert
Dashboard Tabs Are Empty
- Confirm each service calls
.WithOtlpExporter()in the AppHost - Confirm services can reach the Aspire dashboard OTLP proxy (
https://localhost:21040by default) - The Aspire dashboard OTLP endpoint requires traffic through the Aspire DCP proxy; external direct connections are rejected
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow C# coding conventions
- Use nullable reference types
- Write unit tests for new features
- Update API documentation
- Ensure all tests pass before submitting
This project is licensed under the MIT License - see the LICENSE file for details.
For questions and support:
- Create an issue in the GitHub repository
- Check the API documentation for endpoint details
- Review the test files for usage examples
- Authentication and authorization
- Real-time notifications
- Mobile app integration
- Advanced analytics and reporting
- Integration with pharmacy systems
- Machine learning for adherence predictions
- Multi-language support
- Offline capability
Built with β€οΈ using .NET Aspire and modern cloud-native technologies.