A production-ready Containerized AI chatbot built with Claude API, featuring Redis caching, comprehensive observability with Prometheus/Grafana, and automated CI/CD pipelines.
My goal for this Project was to learn and demonstrate enterprise level software engineering practices like:
- Infrastructure-as-Code: Complete containerized deployment with orchestration
- Observability-First Design: Comprehensive metrics collection and visualization
- Reliability Engineering: Error handling, caching strategies, health checks
- DevOps Automation: CI/CD pipeline with automated testing and validation
- Production Thinking: Design decisions made for scalability and maintainability
git clone https://github.com/e-300/Containerized-Chatbot
cd ai-agent-mvpCreate .env file in project root:
Required:
ANTHROPIC_API_KEY=your_anthropic_api_key_here
Optional (defaults provided):
REDIS_HOST=redis
REDIS_PORT=6379
docker compose upThis will start four Containers:
- AI Agent: FastAPI server on http://localhost:8000
- Redis: Cache server on localhost:6379
- Prometheus: Metrics collector on http://localhost:9090
- Grafana: Dashboard on http://localhost:3000
Check agent health:
curl http://localhost:8000/healthExpected: {"status": "healthy"}
Check Prometheus targets:
curl http://localhost:9090/-/healthyExpected: Prometheus is Healthy.
Grafana Dashboard:
- URL: http://localhost:3000
- Credentials:
admin/admin
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{"message": "What is Docker?"}'Stop containers:
docker-compose downRemove containers, networks, and volumes:
docker-compose down -vRemove images:
docker-compose down --rmi all
- Runtime: Python 3.10.12
- API Framework: FastAPI with Pydantic validation
- LLM Provider: Anthropic Claude (Haiku 3.5)
- Caching Layer: Redis 7 (Alpine)
- Containerization: Docker & Docker Compose
- Monitoring: Prometheus + Grafana
- CI/CD: GitHub Actions
- Testing: Pytest with coverage reporting
- Code Quality: Flake8, Black
┌─────────────┐
│ Client │
└──────┬──────┘
│ HTTP POST /chat
▼
┌─────────────────────────────────────┐
│ FastAPI Layer │
│ • Request validation (Pydantic) │
│ • Metrics instrumentation │
│ • Error handling │
└──────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ AnthropicAgent Layer │
│ • Cache key generation (SHA-256) │
│ • Redis cache check │
│ • Response extraction │
└──────┬──────────────────────────────┘
│
├─── Cache Hit? ───► Redis ────┐
│ │
└─── Cache Miss ───► Claude API │
│
Response ◄─┘
┌─────────────────────────────────────┐
│ Monitoring Stack │
│ Prometheus ──scrapes──► /metrics │
│ │ │
│ └──► Grafana (visualization) │
└─────────────────────────────────────┘
- Abstract
AI_Platforminterface - Enables future support for various LLM providers
- Enforces consistent behavior
AnthropicAgentclass extends from the Abstract Interface- Claude API integration
- Redis Caching Logic with:
- SHA-256 cache keys with collision resistance
- Connection pooling
- FastAPI REST endpoint with Pydantic Validation
- Prometheus Metrics captured:
- Request count
- Response time
- Cache miss/hit
- Health check endpoint for container orchestration
✅ RESTful chat API with JSON request/response
✅ Input validation and sanitization
✅ Comprehensive error handling with informative messages
✅ Empty input detection and rejection
✅ Redis-based response caching (1-hour TTL)
✅ Graceful degradation when Redis unavailable
✅ Connection pooling for Redis client
✅ Cache key generation using system prompt + user input
✅ Prometheus metrics endpoint (/metrics)
✅ Request counter with success/error labels
✅ Response time histogram
✅ Cache hit/miss counters
✅ Error type categorization
✅ Pre-configured Grafana dashboard
✅ Multi-container orchestration (Agent, Redis, Prometheus, Grafana)
✅ Health check endpoints for monitoring
✅ Automated container restarts
✅ Volume management for persistent data
✅ Network isolation between services
✅ Automated testing on push/PR
✅ Code linting with Flake8
✅ Test coverage reporting
✅ Docker image build validation
✅ Branch protection ready
Stage 1 is Complete:
- Project structure and planning
- Core agent implementation
- FastAPI REST API with validation
- Docker containerization
- Docker Compose orchestration
- Redis server-side caching
- Prometheus and Grafana monitoring
- GitHub Actions CI/CD pipeline
- Documentation and polish
Next Stage: Kubernetes Deployment with a proper use case that allows horizontal scaling
The pipeline runs on every push and pull request to main and develop branches.
1. Test Job:
- Checkout code
- Set up Python 3.10
- Install dependencies
- Run Flake8 linting
- Execute pytest with coverage reporting
2. Docker Job (runs after tests pass):
- Checkout code
- Build Docker image with commit SHA tag
- Verify image creation
Building this project taught me:
- Container orchestration with Docker Compose
- Metrics-driven development with Prometheus
- Visualization best practices with Grafana
- CI/CD pipeline design with GitHub Actions
- Abstract interfaces for flexibility (Strategy pattern)
- Separation of concerns in layered architecture
- Error handling and graceful degradation
- Caching strategies for external APIs
- Observability instrumentation from day one
- Health checks for container orchestration
- Connection pooling for resource efficiency
- Cost optimization through intelligent caching
- FastAPI for high-performance APIs
- Pydantic for data validation
- Pytest for comprehensive testing
- Type hints for code clarity
MIT
✨ Initial MVP release
✨ Three-layer architecture implementation
✨ Redis caching with fallback
✨ Prometheus + Grafana monitoring
✨ CI/CD pipeline with GitHub Actions
✨ Comprehensive unit test suite
✨ Docker Compose orchestration
📝 Complete documentation