A powerful AI-driven API service that converts natural language descriptions into beautiful Mermaid.js diagrams using Google's Gemini AI.
- Natural Language Processing: Convert plain text descriptions into professional diagrams
- Multiple Diagram Types: Support for flowcharts, sequence diagrams, class diagrams, state diagrams, Gantt charts, and ER diagrams
- AI-Powered: Leverages Google Gemini 2.5 Flash for intelligent diagram generation
- RESTful API: Simple and intuitive API endpoints
- TypeScript: Full TypeScript support for better development experience
- Production Ready: Built with security, logging, and CORS support
- Flowcharts - Process flows and workflows
- Sequence Diagrams - System interactions and communications
- Class Diagrams - Object-oriented models and structures
- State Diagrams - State transitions and workflows
- Gantt Charts - Project timelines and schedules
- ER Diagrams - Database relationships and entities
- Runtime: Node.js
- Framework: Express.js
- Language: TypeScript
- AI Provider: Google Gemini (via LangChain)
- Package Manager: pnpm
- Security: Helmet.js, CORS
- Logging: Morgan
- Environment: dotenv
- Node.js (v16 or higher)
- pnpm (recommended) or npm
- Google Gemini API key
-
Clone the repository
git clone https://github.com/brijeshdevio/DiagramAIAPI.git cd DiagramAIAPI
-
Install dependencies
pnpm install
-
Environment Configuration
cp .env.example .env
Update
.env
with your configuration:PORT=3000 NODE_ENV=development GEMINI_API_KEY=your_gemini_api_key_here
-
Start the development server
pnpm dev
-
Build for production
pnpm build pnpm start
POST /api/diagram
Generate a Mermaid.js diagram from natural language description.
{
"prompt": "Show a user login flow with authentication and error handling"
}
{
"response": "flowchart TD\n User([User]) --> Login[Enter Credentials]\n Login --> Validate{Valid Credentials?}\n Validate -->|Yes| Dashboard[Access Dashboard]\n Validate -->|No| Error[Show Error Message]\n Error --> Login",
"prompt": "Show a user login flow with authentication and error handling"
}
GET /
Returns API status and welcome message.
{
"message": "Welcome to the DiagramAI API"
}
curl -X POST http://localhost:3000/api/diagram \
-H "Content-Type: application/json" \
-d '{
"prompt": "Create a diagram showing how a user orders food online"
}'
curl -X POST http://localhost:3000/api/diagram \
-H "Content-Type: application/json" \
-d '{
"prompt": "Design a database schema for a blog with users, posts, and comments"
}'
curl -X POST http://localhost:3000/api/diagram \
-H "Content-Type: application/json" \
-d '{
"prompt": "Show the interaction between frontend, API, and database in a web application"
}'
Variable | Description | Required | Default |
---|---|---|---|
PORT |
Server port | No | 3000 |
NODE_ENV |
Environment mode | No | development |
GEMINI_API_KEY |
Google Gemini API key | Yes | - |
SYSTEM_PROMPT |
Custom AI system prompt | No | Built-in prompt |
You can customize the AI behavior by setting the SYSTEM_PROMPT
environment variable. The default prompt is optimized for generating clean, valid Mermaid.js diagrams.
- Helmet.js: Security headers for HTTP responses
- CORS: Cross-origin resource sharing configuration
- Environment Variables: Sensitive data protection
- Input Validation: Request body validation and sanitization
pnpm build
NODE_ENV=production pnpm start
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
pnpm dev
- Start development server with hot reloadpnpm build
- Build TypeScript to JavaScriptpnpm start
- Start production serverpnpm test
- Run tests (placeholder)
The project uses TypeScript with strict type checking. Follow these guidelines:
- Use TypeScript interfaces for type definitions
- Implement proper error handling
- Follow REST API conventions
- Use meaningful variable and function names
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the ISC License.
Brijesh - brijeshio@duck.com
- Mermaid.js - Diagram syntax and rendering
- LangChain - AI framework for LLM integration
- Google Gemini - AI model provider
Happy Diagramming! π¨β¨