A comprehensive running and fitness platform with AI-powered coaching, social features, and high-performance caching. Built with modern containerized architecture for scalability and developer productivity.
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Web App β β PostgreSQL β β Redis β
β Container βββββΆβ Container β β Container β
β β β β β β
β Next.js + AI β β Primary DB β β Cache Layer β
β Port: 3000 β β Port: 5432 β β Port: 6379 β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β
βββββββββββββββββββ
β Docker Network β
β (maratron_network)β
βββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Maratron Platform β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Frontend (Next.js 15) β AI Server (Python + MCP) β
β ββ React Components β ββ Claude 3.5 Integration β
β ββ TypeScript β ββ User Context Management β
β ββ Tailwind CSS β ββ Smart Data Tools β
β ββ shadcn/ui β ββ Real-time Communication β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Caching Layer (Redis 7) β
β ββ User Profile Caching (15min TTL) β
β ββ Runs Data Caching (5min TTL) β
β ββ Leaderboard Caching (10min TTL) β
β ββ Social Feed Caching (3min TTL) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Database Layer (PostgreSQL 15) β
β ββ User Profiles & Preferences β
β ββ Running Activities & Metrics β
β ββ Social Graph & Interactions β
β ββ Training Plans & Goals β
β ββ Gear Tracking & Analytics β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
maratron-monorepo/
βββ apps/
β βββ web/ # Next.js application
β β βββ src/
β β β βββ app/ # App Router pages & API routes
β β β βββ components/ # React components by feature
β β β βββ lib/ # Core utilities & business logic
β β β β βββ cache/ # Redis caching system
β β β β βββ utils/ # Running calculations & helpers
β β β β βββ middleware/# Auth & rate limiting
β β β β βββ mcp/ # AI server integration
β β β βββ hooks/ # Custom React hooks
β β β βββ maratypes/ # TypeScript type definitions
β β βββ prisma/ # Database schema & migrations
β β βββ public/ # Static assets
β βββ ai/ # Python AI server
β βββ src/maratron_ai/ # MCP server implementation
β βββ tests/ # Python test suite
β βββ requirements/ # Python dependencies
βββ docs/ # Comprehensive documentation
βββ assets/ # Shared brand assets
βββ docker-compose.yml # Container orchestration
βββ Dockerfile # Application container definition
βββ package.json # Workspace configuration
- Docker & Docker Compose - For containerized development
- Node.js 20+ - For local development (optional)
- Python 3.11+ - For AI server development (optional)
# Clone the repository
git clone <repository-url>
cd maratron-monorepo
# Start the complete development environment
npm run dev
# Access the application
open http://localhost:3000# Start databases in containers, app locally (recommended for daily development)
npm run dev:hybrid
# Access the application
open http://localhost:3000# Terminal 1: Start containerized databases
docker-compose up postgres redis -d
# Terminal 2: Start AI server locally
cd apps/ai && uv sync && python run_server.py
# Terminal 3: Start web application locally
cd apps/web && npm install && npm run dev# Development
npm run dev # Start complete development environment
npm test # Run test suite
npm run lint # Code quality checks
npm run build # Production build
# Database
npm run db:studio # Open Prisma Studio
npm run db:seed # Load comprehensive test data
# Maintenance
npm run clean # Clean Docker environment- Cache Hit Rate: 85-95% for user data
- Response Time: <2ms for cached responses
- Database Load Reduction: 70-90%
- Redis Operations: 2000+ ops/second
- Cache Invalidation: Tag-based with smart patterns
- Query Optimization: Comprehensive indexing on high-frequency patterns
- Connection Pooling: Efficient resource utilization with health monitoring
- N+1 Query Elimination: Transaction-based query optimization
- Memory Usage: Pagination for large datasets
- Build Time: <30 seconds with Turbopack
- Live Reload: <500ms for code changes (hybrid mode: <100ms)
- Bundle Size: Optimized with dynamic imports
- Container Startup: ~5 seconds (hybrid), ~2-3 minutes (full Docker first time)
- Framework: Next.js 15 with App Router
- Database: PostgreSQL with Prisma ORM
- Auth: NextAuth.js
- UI: Tailwind CSS + shadcn/ui
- Features: Run tracking, social feeds, training plans, AI chat
- Framework: FastMCP (Model Context Protocol)
- Database: Direct PostgreSQL with asyncpg
- Features: User context management, intelligent responses, database tools
- Package Manager: uv (modern Python package management)
π Complete Development Commands β
Comprehensive documentation is available in the docs/ directory:
- Performance Monitoring Guide - π₯ NEW: Enterprise-grade monitoring, alerting, and optimization
- Production Deployment Guide - π₯ NEW: Complete production deployment with security hardening
- Error Handling & Validation - π₯ NEW: AppError patterns, Yup validation, and security best practices
- Advanced Redis Caching Guide - π₯ NEW: Tag-based invalidation, warming strategies, and production scaling
- MCP-LLM Integration - Technical deep-dive into the function calling architecture
- Architecture Overview - System design and component relationships
- Web Application - Next.js frontend with social features and run tracking
- AI MCP Server - Python MCP server with database tools and context management
- API Reference - Complete API documentation
- Development Guide - Setup, testing, and contribution guidelines
- PostgreSQL 15 - Primary database with persistent storage
- Redis 7 - High-performance caching with AOF persistence
- Automatic Schema Management - Prisma migrations applied on startup
- Health Monitoring - Built-in health checks for all services
- Data Persistence - Volumes ensure data survives container restarts
// User data caching examples
cache.user.profile(userId, fetchUserFromDB, {
ttl: 900, // 15 minutes
tags: ['user', 'profile'],
compress: true
});
cache.user.runs(userId, page, limit, fetchRunsFromDB, {
ttl: 300, // 5 minutes
tags: ['user', 'runs'],
serialize: true
});
cache.leaderboard(groupId, period, calculateRankings, {
ttl: 600, // 10 minutes
tags: ['leaderboard', 'social'],
compress: true
});When using npm run dev, services automatically connect via Docker network:
# Automatically configured in Docker Compose
DATABASE_URL=postgresql://maratron:yourpassword@postgres:5432/maratrondb
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_ENABLED=true
REDIS_KEY_PREFIX=maratron:dev:For npm run dev:hybrid (recommended for daily development):
# Database and Redis via localhost (Docker containers)
DATABASE_URL="postgresql://maratron:yourpassword@localhost:5432/maratrondb"
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your_secret_key
# Redis caching (containerized)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_ENABLED=true
REDIS_KEY_PREFIX=maratron:dev:
# AI API Keys
ANTHROPIC_API_KEY=your_anthropic_key
WEATHER__API_KEY=your_weather_key# Production database (managed service)
DATABASE_URL="postgresql://user:pass@prod-db.cloud:5432/maratrondb"
# Production Redis (managed service)
REDIS_URL="redis://prod-redis.cloud:6379"
REDIS_ENABLED=true
REDIS_KEY_PREFIX=maratron:prod:
# Security
NEXTAUTH_SECRET=production-secret-key
NEXTAUTH_URL=https://your-domain.com- β Comprehensive test coverage - All tests passing across components
- β Redis caching validated - Real-world performance testing confirmed
- β MCP integration fully functional - AI chat responds with actual user data
- β Seed data available - Rich test data for validation and development
- β Docker integration tested - Full containerized stack validated
cd apps/web
npm test # Unit tests with Jest
npm run test:watch # Watch mode for development
npm run lint # ESLint validation
npm run build # Production build validation
# Specific test categories
npm test -- --testPathPattern=cache # Redis caching tests
npm test -- --testPathPattern=api # API endpoint tests
npm test -- --testPathPattern=utils # Utility function tests
npm test -- --testPathPattern=components # Component testscd apps/ai
uv run pytest tests/unit/ # Unit tests
uv run pytest tests/integration/ # Integration tests
uv run pytest --cov=src # With coverageLoad comprehensive test data for development and validation:
# Load seed data (from apps/web directory)
npm run db:seedIncludes:
- 10 diverse users with different training levels (beginner to Olympic Trials)
- 27 shoes across various brands and categories
- 26 recent runs with comprehensive metrics
- Complete social graph (posts, comments, likes, follows)
- Training plans and group memberships
Test Accounts (password: "password"):
jackson@maratron.ai- Advanced runner, VDOT 60john@example.com- Marathon enthusiast, VDOT 52sarah@example.com- Track specialist, VDOT 58- Plus 7 more diverse running profiles
- Run Tracking: Distance, pace, heart rate, elevation
- Shoe Management: Mileage tracking and retirement alerts
- Training Plans: AI-generated plans based on goals and VDOT
- VDOT Calculations: Jack Daniels running calculator integration
- User Profiles: Customizable running profiles
- Run Groups: Create and join running communities
- Social Feed: Share runs and interact with other runners
- Comments & Likes: Engage with the running community
- Function Calling Architecture: π₯ NEW - Claude 3.5 intelligently selects and uses 9 specialized tools
- Automatic Context Management: Seamless user context setting - no technical details exposed
- Real-Time Tool Execution: Claude accesses user data, analyzes patterns, and adds records on-demand
- Intelligent Chat: Context-aware running advice with personalized data analysis
- Multi-Tool Coordination: Complex queries automatically use multiple tools (runs + patterns + motivation)
- Natural UX: Users simply ask questions - tools work transparently in background
- MCP Protocol: Modern AI-to-application communication with comprehensive user context
- Industry Best Practices: Professional implementation following enterprise AI assistant patterns
Available AI Tools: getUserRuns, listUserShoes, addRun, addShoe, analyzeUserPatterns, getMotivationalContext, getSmartUserContext, updateConversationIntelligence, getDatabaseSummary
π See Technical Implementation β
- Input validation and sanitization
- Rate limiting on AI operations
- Session management with timeouts
- Environment-based configuration
- No secrets in codebase
SuperClaude was used as a pair coder. See flag usage here
When working with Claude Code, the following MCP tools are available for enhanced development:
-
21st Magic Component Builder - Generate UI components with
/uicommand- Documentation: 21st.dev/magic
- Usage:
/ui create a dashboard card component - Integration: Works with shadcn/ui components
-
21st Magic Component Inspiration - Browse component library for inspiration
- Usage:
/21st fetchto explore existing components
- Usage:
-
21st Magic Component Refiner - Improve existing UI components
- Usage:
/ui refineto enhance component design and functionality
- Usage:
-
Logo Search - Find company logos in JSX/TSX/SVG formats
- Usage:
/logo GitHubto search for brand logos
- Usage:
-
Context7 Library Resolver - Resolve package names to Context7 library IDs
- Documentation: context7.com
- Claude Code Setup: Local Server Connection Guide
- Usage: Automatically resolves library names to fetch documentation
-
Context7 Documentation - Fetch up-to-date library documentation
- Features: Real-time documentation for 1000+ libraries
- Usage: Get current docs for React, Next.js, Prisma, and more
- Puppeteer MCP Server - Full browser automation
- Documentation: Puppeteer API
- Features: Navigate, screenshot, click, fill forms, evaluate JavaScript
- Usage: Automated testing, screenshot generation, web scraping
- Sequential Thinking - Multi-step problem-solving
- Features: Reflection, revision, hypothesis generation and verification
- Usage: Complex feature planning with iterative refinement
- Model Context Protocol (MCP) - Core protocol documentation
- Claude Code Documentation - Complete guide to Claude Code
- FastMCP - Python MCP server framework (used in our AI server)
- MCP Servers Repository - Collection of MCP server implementations
- Smithery.ai - MCP server marketplace and discovery
- shadcn/ui - UI component library used in web application
# Generate modern UI components
/ui create a responsive data table with filters
# Get up-to-date library documentation
Ask about "react-hook-form validation patterns"
# Automate browser testing
Take a screenshot of the dashboard at localhost:3000
# Complex problem solving
Plan and implement a new feature with multiple iterations and refinements
# Search for brand assets
/logo Discord Slack GitHubThese tools significantly enhance development workflows by providing AI-powered component generation, real-time documentation access, browser automation, and sophisticated problem-solving capabilities.
MIT License - see LICENSE file for details