This project is an "AI Capability Factory", designed to transform powerful, raw AI models like Google's Gemini and OpenAI's GPT into a manageable, scalable, and flexible professional backend service.
The core strength of this project lies in its ability to introduce new AI capabilities to the system without changing the application code, simply by adding a new template to the database. This provides incredible development speed and architectural flexibility.
The goal is not to reinvent artificial intelligence but to build a professional service that wraps raw AI engines with specific business rules, security, and reliability.
- Abstracting Expertise: Enables users to achieve optimal results with simple commands, eliminating the need for expert "prompt engineering." The expertise is embedded within our backend logic.
- Standardizing Output: Guarantees that the variable and sometimes unstructured responses from the AI are always processed into a predictable, clean, and structured JSON format, making it easy for other applications to consume.
- Security & Centralization: Manages valuable and costly API keys in a single, secure backend location, eliminating security risks and uncontrolled spending.
- Flexibility & Scalability: Avoids vendor lock-in by allowing the integration of any AI provider (Gemini, OpenAI, etc.) without altering the core business logic of the application.
The project is built on a layered architecture that adheres to the Separation of Concerns principle. The lifecycle of a request follows the Router -> Validator -> Controller -> Service flow.
- Dynamic Template Engine: Core tasks like "text summarization" or "translation" are not hard-coded. They are managed as dynamic templates stored in a
Templatetable in the database. Each template contains asystem_prompt, adefault_model, and a list ofallowed_models. - Abstracted AI Providers (Strategy Pattern): Different AI services (
GeminiService,OpenAIService) are abstracted behind a commonAIProviderinterface. A centralAIManagerservice acts as a factory, dynamically selecting the correct provider based on the requested model name (e.g., any model starting with 'gpt' is routed toOpenAIService). This makes the system incredibly extensible. - Centralized Error Handling: All errors thrown within the application are standardized using a custom
AppErrorclass. Errors from the service layer are propagated up to the controller, which then passes them to a single Global Error Handler middleware usingnext(error). This ensures consistent and secure error responses. - Type-Safe Validation: Incoming request bodies are rigorously validated against strict rules defined in DTO (Data Transfer Object) classes using the
class-validatorlibrary. Invalid requests are rejected at the entry point before they can reach the core business logic.
- Platform: Node.js
- Language: TypeScript
- Web Framework: Express.js
- Database ORM: Prisma
- Database: PostgreSQL
- Validation: class-validator
- Google Gemini:
gemini-1.5-flash,gemini-1.5-pro, etc. - OpenAI:
gpt-4o,gpt-4,gpt-3.5-turbo, etc.
- Package Manager: NPM
- API Testing Tool: Postman
- Version Control: Git
- Project Management: Trello
- Node.js (v18+ recommended)
- A running PostgreSQL database instance
-
Clone the Repository:
git clone https://github.com/your-username/your-repo-name.git cd your-repo-name -
Install Dependencies:
npm install
-
Set Up Environment Variables:
- Create a
.envfile in the project's root directory. - Copy the contents of
.env.exampleand fill in your own credentials:
# --- Database Configuration --- DATABASE_URL="postgresql://USERNAME:PASSWORD@localhost:5432/DATABASE_NAME?schema=public" # --- Server Configuration --- PORT=3000 # --- API Keys --- GEMINI_API_KEY="..." OPENAI_API_KEY="..."
- Create a
-
Set Up and Seed the Database:
- This command creates the database schema based on
prisma/schema.prismaand runs theprisma/seed.tsscript to populate theTemplatetable with initial capabilities.
npx prisma migrate dev
- This command creates the database schema based on
-
Start the Development Server:
- The server will start on
http://localhost:3000.
npm run dev
- The server will start on
All capabilities of the project are accessed through a single, intelligent endpoint.
POST /api/v1/templates/:id/execute
placeholders(required): An object used to fill in the dynamic variables within the template'ssystem_prompt.model(optional): A string specifying which AI model to use for the task. If omitted, the template'sdefault_modelfrom the database will be used. The specified model must be in the template'sallowed_modelslist.
{
"placeholders": {
"text_to_process": "This is a long text that needs to be summarized by the AI.",
"language": "English"
},
"model": "gpt-4o"
}