A modern REST API for AI-powered conversations, built with Next.js 14 and TypeScript.
- 🤖 AI-powered responses using LangChain
- 🧠 Message history and conversation memory
- 💬 Conversation and message management
- 🔐 Authentication with Clerk
- 📝 Type-safe API with TypeScript
- 🗄️ DynamoDB for scalable storage
- 📚 OpenAPI documentation
- 🧪 Comprehensive test coverage
- Framework: Next.js 14
- Language: TypeScript
- AI Integration: LangChain
- Authentication: Clerk
- Database: DynamoDB
- Validation: Zod
- Testing: Vitest
- Documentation: OpenAPI/Swagger
- Package Manager: pnpm
- Node.js 18+
- pnpm
- AWS account with DynamoDB access
- Clerk account
- OpenAI API key
-
Clone the repository:
git clone https://github.com/yourusername/minted-api.git cd minted-api -
Install dependencies:
pnpm install
-
Set up environment variables:
cp .env.example .env.local
Update the following variables in
.env.local:NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEYDYNAMODB_TABLE_NAMEAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGIONOPENAI_API_KEYLLM_DEBUG_MODE(optional, set to 'true' to enable debug logging)
-
Start the development server:
pnpm dev
pnpm test # Run all tests
pnpm test:watch # Run tests in watch mode
pnpm test:coverage # Generate test coverage reportpnpm lint # Run ESLint
pnpm format # Format code with Prettierpnpm build # Build the application
pnpm start # Start the production serverThe API documentation is available at /api-docs when running the application locally. It provides detailed information about all available endpoints, request/response formats, and authentication requirements.
GET /api/conversations- List all conversationsPOST /api/conversations- Create a new conversationPUT /api/conversations/:id- Update a conversationDELETE /api/conversations/:id- Delete a conversation and its messagesPOST /api/conversations/:id/title- Update conversation title
GET /api/conversations/:id/messages- List messages in a conversation (with pagination)POST /api/conversations/:id/messages- Create a new message and get AI response (with conversation history)PUT /api/conversations/:id/messages/:messageId- Update a message's contentDELETE /api/conversations/:id/messages/:messageId- Delete a message
All API responses follow this format:
{
data: T | null; // The response data or null if there's an error
error: string | null; // Error message or null if successful
}For paginated endpoints (e.g., messages):
{
data: T[];
error: null;
pagination: {
hasMore: boolean;
lastEvaluatedKey: string | null;
limit: number;
}
}For message creation, the response includes both the user message and AI response:
{
data: {
message: {
id: string;
content: string;
isFromUser: true;
conversationId: string;
createdAt: number;
lastModified: number;
},
response: {
id: string;
content: string;
isFromUser: false;
conversationId: string;
createdAt: number;
lastModified: number;
}
},
error: null
}The API uses standard HTTP status codes:
- 200: Success
- 201: Created
- 400: Bad Request
- 401: Unauthorized
- 404: Not Found
- 500: Internal Server Error