How pushkrjain/ai_marketing_api works
Project Type and Purpose
• This is a containerized, back-end API service (FastAPI) implementing a modular multi-agent architecture for generating personalized marketing content in real time.
• Key goals: expose HTTP endpoints, orchestrate Segmentation/Generation/Optimization agents, persist feedback, log activities, and emit metrics for Prometheus/Grafana.
File Structure
• Top-level files & directories:
– app.py: FastAPI application entrypoint
– agent/: segmentation.py, generation.py, optimization.py, orchestrator.py
– auth/: JWT authentication logic
– db/: feedback persistence
– hf_models/: local Hugging Face model storage
– monitoring/: Prometheus instrumentation code
– mylogging/: structured error & research logging
– prometheus.yml & prometheus-2.53.0…/: standalone Prometheus distribution
– Dockerfile & docker-compose.yml: container build & orchestration
– tests/: pytest integration & unit tests
• Patterns: modular agent packages, clear separation of concerns (auth, logging, monitoring, persistence).
README Insights
• Architecture sketch included: User Profile → Segmentation → Generation → (Feedback & Stats) → Optimization → Re-generation.
• Technical stack: FastAPI, Hugging Face Transformers, Chroma/FAISS, Prometheus, Grafana, Docker Compose.
• Monitoring: /metrics endpoint instrumented via prometheus-fastapi-instrumentator.
• Logging: Python logging to console & files (error.log, research.log).
Main Components
a. Client Layer
– “API Consumer” (curl, HTTPie, SDK)
b. API Gateway / Orchestrator
– FastAPI app (app.py)
– Auth module (auth/auth.py)
– Orchestration logic (agent/orchestrator.py)
c. Agent Layer
– Segmentation Agent (agent/segmentation.py) → Chroma/FAISS vector store
– Generation Agent (agent/generation.py) → local HF model (hf_models/)
– Optimization Agent (agent/optimization.py) → feedback from DB
d. Persistence & Storage
– Feedback DB (db/feedback.py; could be SQLite or JSON store)
– Vector store (external Chroma/FAISS service)
– Model store (local HF directories)
e. Cross-cutting Concerns
– Logging subsystem (mylogging/error_logger.py, research_logger.py)
– Monitoring subsystem (monitoring/metrics.py) → /metrics endpoint → Prometheus
f. Infrastructure Orchestration
– Docker Compose
· fastapi-app container
· prometheus container (prometheus.yml)
· optional grafana container
· other dependencies (vector store, DB)
Architectural Patterns & Design Principles
• Modular multi-agent pipeline—each agent is a reusable Python module.
• Separation of concerns—distinct layers for API, agents, persistence, logging, and monitoring.
• Containerization—isolated services orchestrated via Docker Compose.
• Observability—structured logs + metrics exposed for Prometheus/Grafana.
• Extensibility—new agents or model versions can be plugged in by adding modules under agent/ or hf_models/.
Final Checklist
[ ] All major components (API, Auth, Agents, DB, Stores, Observability) are represented.
[ ] Data flows are directional and labeled.
[ ] External dependencies and containers are drawn distinctly.
[ ] Architectural patterns (multi-agent, feedback loop) are clearly visible.