Short Executive Summary: Enterprise-grade production microservice that ingests noisy, unstructured news payloads (raw text, HTML, RSS feeds) and transforms them into strictly validated, typed JSON records with zero runtime schema drift.
-
β‘ Zero-Setup Onboarding: Onboard & run in
< 5 minutes(make installββ> ready to develop). -
π Type Safety & Quality Gates: 100%
Mypy --strictcoverage andRufflinting enforced across all microservice modules. -
π‘οΈ Defensive Security & Guardrails: Prompt injection defenses, XML tag isolation (
<untrusted_news_payload>), and developer authority enforcement. -
π§± Pydantic V2 Validation Firewall: Strict contract validation, bounded ranges (e.g.,
confidence_score$\in [0.0, 1.0]$ ), and structured enum taxonomies. -
β‘ Two-Tiered Fault Tolerance: Decorated
Tenacityretry policy (exponential backoff on HTTP 429/5xx) paired withInstructorschema self-correction feedback loops. - π Integrated Monitoring Dashboard: Next.js frontend interface providing real-time schema inspection, batch execution testing, and metrics visualization.
-
π³ Hardened Containerization: Multi-stage non-root Docker build (
python:3.11-slim) ready for production container orchestrators.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INGESTION LAYER β
β FastAPI Microservice (POST /v1/extract, /v1/extract/batch) β
ββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββ
β Config & Schemas β
β (config.py, β
β schemas.py) β
βββββββββββ¬ββββββββββ
β
ββββββββββββββββββββββββΌβββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β Defensive Prompt β β Deduplication β β Structlog JSON β
β Isolation Layer β β Cache (SHA256) β β FinOps Logger β
β (security.py) β ββββββββββ¬ββββββββββ β (logger.py) β
ββββββββββ¬ββββββββββ β ββββββββββ¬ββββββββββ
β β Hit β
β βββββββββββββββββββββββββ€
βΌ β Miss β
βββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββ
β LLM ENGINE & TWO-TIERED RESILIENCE β
β (engine.ExtractionEngine) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Tier 1: Tenacity Exponential Backoff Retry β β
β β (Network, Rate Limits 429, 5xx) β β
β ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Instructor SDK Constrained LLM Inference β β
β β (AsyncOpenAI / Anthropic / Mistral, temp=0.0) β β
β ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββ β
β β Raw Output β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Tier 2: Pydantic V2 Validation Firewall & β β
β β Schema Self-Correction Loop (Max 2) β β
β ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββ
β Validated Record
βΌ
βββββββββββββββββββββββββββ
β ArticleExtractionRecord β
β (JSON Response / DB) β
βββββββββββββββββββββββββββ
.
βββ docs/ # Architecture & technical documentation
β βββ architecture_en.md # Software architecture specification & invariants
β βββ specifications_en.md # Product requirements & data model specification
β βββ code_en.md # Source code architecture reference
β βββ glossary_en.md # Domain & technical terminology glossary
β βββ code_fr.md / glossary_fr.md # French documentation variants
β
βββ src/ # Microservice source code
β βββ main.py # FastAPI application setup, routes & exception handlers
β βββ config.py # Central configuration (Pydantic BaseSettings)
β βββ engine.py # Extraction engine, Instructor integration & retries
β βββ schemas.py # Pydantic V2 schemas & API DTOs
β βββ security.py # Prompt isolation & XML sanitization logic
β βββ logger.py # Structlog JSON logging configuration
β
βββ dashboard/ # Monitoring & testing frontend (Next.js 14)
β βββ src/ # UI components & API bindings
β βββ package.json # Dashboard dependencies
β
βββ tests/ # Automated test suite
β βββ conftest.py # Pytest fixtures & mock clients
β βββ test_schemas.py # Schema field validation unit tests
β βββ test_engine.py # Extraction engine & retry integration tests
β βββ test_security.py # Defensive security & prompt injection suite
β
βββ data/ # Validation datasets
β βββ dataset_100_articles.jsonl # 100 sample article extraction benchmark
β
βββ Dockerfile # Multi-stage non-root container configuration
βββ docker-compose.yml # Local microservice orchestration
βββ Makefile # Unified command interface
βββ pyproject.toml # Poetry dependencies, Mypy strict & Ruff rules
βββ README.md # Project overview & quickstart guide
# Clone repository and enter directory
cd projets/4_ASCGenerator
# Automatic onboarding (installs dependencies via Poetry)
make installCopy .env.example to .env and set your LLM API keys.
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-...
DEFAULT_MODEL=gpt-4o-mini
LOG_LEVEL=INFOLLM_PROVIDER=google
GOOGLE_API_KEY=your_google_gemini_api_key_here
DEFAULT_MODEL=gemini-2.0-flash
LOG_LEVEL=INFOπ‘ Where to change the model: Set the
DEFAULT_MODELenvironment variable in your.envfile.
- OpenAI models:
gpt-4o-mini,gpt-4o,gpt-4-turbo, etc.- Google Gemini models:
gemini-2.0-flash,gemini-2.5-pro,gemini-1.5-pro, etc.You can also override the model at runtime by passing
modeltoExtractionEngine(model="...").π Get a Gemini API key: Visit https://aistudio.google.com/app/apikey to create one.
make lintmake testmake devOpen API documentation at http://localhost:8000/docs.
make dashboardAccess the interactive dashboard at http://localhost:3000.
# Build container image
make docker-build
# Run microservice container
make docker-run| Metric | Target / Measured | Status |
|---|---|---|
| Mypy Strict Coverage | 100% |
β Passing |
| Schema Compliance Rate | 100% (Zero Schema Drift) |
β Passing |
| Prompt Injection Resilience | 100% Pass Rate |
β Passing |
| Network Retry Recovery (Tier 1) | Up to 3 attempts (Tenacity backoff) | β Passing |
| Schema Repair Rate (Tier 2) | Max 2 correction attempts | β Passing |
| Docker Container Size | < 250 MB |
β Passing |
Distributed under the MIT License. See LICENSE for more information.