How talgaon4/promptcraft works
Project Type and Purpose
• This is a backend-only REST API service written in Python.
• Its goal is to receive AI prompts, collect user feedback, and automatically optimize prompts (via background jobs).
• Key external dependencies: PostgreSQL (persistent storage) and Redis (job queue).
File Structure
Top-level:
• src/main.py – entry point, likely bootstraps FastAPI or similar.
• src/api – routes/controllers and error handling.
• src/services – business-logic layer (PromptService, FeedbackService, HealthService, etc.).
• src/database – DB connection and schema.
• src/models – ORM or data models.
Supporting:
• config.py – central configuration (DB URL, Redis URL, etc.).
• requirements.txt – tech stack (FastAPI/Uvicorn, SQLAlchemy, Celery/RQ).
Tests folder – validates each service and route.
Extract Architecture Insights from README
• REST endpoints for prompts, feedback, health checks, instances.
• Background jobs (using Redis) for long-running optimization tasks.
• Uses PostgreSQL for storing prompts, feedback, instances.
Main System Components
a. API Layer
– FastAPI (src/main.py + src/api/routes)
– Error handlers & request/response schemas
b. Service Layer
– PromptService, FeedbackService, HealthService, BaseService
– Export utilities for data export
c. Data Layer
– PostgreSQL database (schema.sql, database.py)
– ORM models (models.py)
d. Background Job Processor
– Redis-backed queue (e.g., Celery or RQ; implied by Redis requirement)
– Worker processes pulling tasks from queue to optimize prompts
e. External Clients
– Frontend or CLI clients issuing HTTP requests
– Automated scripts or other services
Component Interactions
• Client → HTTP(S) → API Layer
• API routes validate via Pydantic schemas → delegate to Service Layer
• Service Layer → read/write → PostgreSQL (through database.py & models)
• For optimization tasks: Service enqueues job → Redis queue
• Worker (“instance” route or separate process) dequeues from Redis → performs compute → writes results back to DB
• HealthService → simple DB/Redis pings
Architectural Patterns & Principles
– Layered architecture (API → Services → Database)
– Separation of concerns:
• Routing & validation in src/api
• Business logic in src/services
• Data access in src/database + src/models
– Asynchronous background processing (decouples heavy tasks via Redis queue)
– Configuration via environment variables (.env) for 12-factor compliance