Describe an API in plain English, and get a live, stateful, and mockable REST or GraphQL server in seconds.
Powered by FastAPI, Vue.js, Docker, and your choice of OpenAI's GPT or Google's Gemini.
mockgen-demo.mp4
A narrated tour — describing an API in chat, publishing it, and hitting the live stateful mock. (The video is also in the repo: docs/demo.mp4.)
MockGen is an open-source tool that uses Large Language Models (LLMs) to generate fully functional mock APIs from a simple text description. It instantly creates schemas and deploys live endpoints for both REST (OpenAPI) and GraphQL. The vision is to create truly intelligent, stateful mock servers for developers who need to simulate a backend that doesn't exist yet.
- AI-Powered Schema Generation: Describe your API conversationally and get an OpenAPI (REST) schema or SDL (GraphQL) schema using GPT or Gemini — the assistant asks clarifying questions before it generates.
- Dynamic Mock Endpoints: Every endpoint returns a realistic mocked response from the moment it is published, honouring the schema's declared
examples and status codes (201on create,204on delete, …). Routes that aren't collection-shaped (/health, actions, search) respond with a fresh schema-derived example on every request, and GraphQL queries get mock data shaped to exactly the fields they select. - Stateful REST Mocks: Published REST mocks aren't frozen examples — collection routes (
/posts,/posts/{id}/comments) do real CRUD against rows stored in SQLite, so aPOSTshows up in the nextGETand a missing id returns a real 404. On publish, the LLM seeds each collection once with a coherent, cross-referenced dataset (falling back to Faker-generated rows if that fails), and the data survives a restart. - In-App Playground: Exercise your published mock without leaving the app — a built-in request console lets you pick an endpoint, fill in a body, and fire a live call, with one-click copy-as-curl and schema download.
- Sessions That Survive a Restart: Chat sessions and their draft/published schemas are stored in SQLite (
MOCKGEN_DB_PATH), not just in memory — published mocks are automatically remounted when the backend restarts. - Service-Oriented Architecture: A clean backend design separates concerns into services, routers, and configuration for maximum maintainability.
- Modern Frontend Stack: The Vue.js frontend is professionally structured with a dedicated API service layer and Pinia for state management.
- Unified FastAPI Backend: A high-performance Python backend serves both the API mocks and the frontend application on a single port.
- Dockerized: A multi-stage Dockerfile provides a simple setup for the entire stack.
For the best experience and to access dynamically generated APIs, it is recommended to run the frontend and backend services separately.
1. Start the Backend (FastAPI):
# Navigate to the backend directory
cd backend
# Install dependencies with Poetry (it creates and manages the virtual
# environment for you — install it first if needed: `pip install poetry`)
poetry install
# Configure your environment (add AI API keys)
cp .env.example .env
nano .env # set OPENAI_API_KEY or GEMINI_API_KEY — only one is required
# Run the development server
poetry run uvicorn mockapi.main:app --reloadThe backend will be available at http://localhost:8000.
2. Start the Frontend (Vue.js):
# In a new terminal, navigate to the frontend directory
cd frontend
# Install dependencies and run the server
npm install
npm run devAccess the MockGen UI at http://localhost:5173.
Note: Docker Compose loads environment variables from backend/.env and sets APP_ROOT=/app inside the container. Healthchecks use curl. Set MOCKGEN_PORT in your shell to change the host port (defaults to 8000). The container deliberately runs a single uvicorn worker, since mounted mock routes live in-process.
# Builds the frontend into the image and serves the full stack from one port
docker-compose up --build- Architecture.md: A deep dive into the project's structure and data flow.
- Configuration.md: How to configure the application using environment variables and Pydantic settings.
- LLM-Integration.md: Details on the supported LLM providers, the JSON response contract, and error handling.
- PromptSpec.md: The prompt template contract — response modes, JSON shapes, and the brace-escaping rule.
This project is licensed under the MIT License.
Contributions, issues, and feature requests are welcome! Please check the issues page for ongoing work.
Before your first commit, enable the repo's git hooks so gitleaks can block accidentally staged secrets (brew install gitleaks first):
git config core.hooksPath .githooksCI runs the same secret scan over the full history, the backend test suite, and a frontend build on every push and pull request.
Created by Mohsin Kokab
- GitHub: @Mo-Ko
- Website: @Mohsin Kokab
- LinkedIn: Mohsin Kokab
