Spaces:
Runtime error
Runtime error
| from typing import Dict, Any, List | |
| class TechKnowledgeBase: | |
| def __init__(self): | |
| self.architect_patterns = { | |
| "microservices": "Decoupled services communicating via API/Events. Pros: Scalability. Cons: Complexity.", | |
| "serverless": "Event-driven, scale-to-zero logic. Best for intermittent workloads.", | |
| "layered_architecture": "Separation of concerns (UI, Domain, Data). Standard for enterprise apps." | |
| } | |
| self.api_best_practices = { | |
| "versioning": "Use URL versioning (e.g., /v1/) or Header versioning.", | |
| "security": "Implement OAuth2/OIDC. Use rate limiting and input validation.", | |
| "documentation": "OAS3 (Swagger) is the industry standard for REST APIs." | |
| } | |
| self.webhook_wizardry = { | |
| "security": "Verify signatures using HMAC SHA256. Use secret rotation.", | |
| "reliability": "Implement exponential backoff retries. Use an idempotency key to prevent double processing.", | |
| "payloads": "Keep payloads small; use 'thin' webhooks that prompt a GET request for full data." | |
| } | |
| self.domain_routing = { | |
| "dns_types": { | |
| "A": "Points domain to IPv4.", | |
| "CNAME": "Alias for another domain (good for CDNs/PaaS).", | |
| "TXT": "Used for SPF/DKIM/DMARC and site verification.", | |
| "MX": "Mail Exchange records." | |
| }, | |
| "ssl_tls": "Always use Let's Encrypt for automated certificates. Force HTTPS redirection." | |
| } | |
| self.app_builder_templates = { | |
| "fastapi_mcp": "Python-based high performance API with built-in MCP support.", | |
| "nextjs_tailwind": "Modern React frontend with utility-first CSS and server-side rendering.", | |
| "docker_slim": "Multi-stage builds to keep image size small and secure." | |
| } | |
| def get_info(self, module: str) -> Dict[str, Any]: | |
| data = { | |
| "architecture": self.architect_patterns, | |
| "api": self.api_best_practices, | |
| "webhooks": self.webhook_wizardry, | |
| "domains": self.domain_routing, | |
| "apps": self.app_builder_templates | |
| } | |
| return data.get(module, {"error": "Module knowledge not found."}) | |
| def get_all(self) -> Dict[str, Any]: | |
| return { | |
| "architecture": self.architect_patterns, | |
| "api": self.api_best_practices, | |
| "webhooks": self.webhook_wizardry, | |
| "domains": self.domain_routing, | |
| "apps": self.app_builder_templates | |
| } | |