API Gen Platform
Generate Live Relational Mock APIs with Connected Data from Plain English
What it is
API Gen is a developer tool that turns plain-English requirements into a live, relational mock database in under 10 seconds. It solves frontend-backend blocking by generating full CRUD REST endpoints with realistic, foreign-key-consistent data powered by DAG topological sorting and Hono.
Tech Stack
System Architecture
Provides natural language prompt input, live schema relationship previews, and an interactive REST API testing client.
Core Engineering Highlight
DAG Topological Sorter for Relational Schema Integrity
Eliminating broken foreign keys and orphaned records in dynamic AI mock databases.
Static mock servers generate isolated JSON files where parent-child relationships break immediately. API Gen constructs a Directed Acyclic Graph (DAG) of all entities and performs a topological sort (e.g. Users & Categories ➔ Products ➔ Orders ➔ OrderItems). Faker.js hydrates records in strict topological order, ensuring every child record references a genuine, pre-existing parent ID.
export interface EntitySchema {
name: string;
dependencies: string[]; // Parent entity names
}
export function sortEntitiesTopologically(entities: EntitySchema[]): string[] {
const inDegree = new Map<string, number>();
const graph = new Map<string, string[]>();
entities.forEach(e => {
inDegree.set(e.name, 0);
graph.set(e.name, []);
});
// Build dependency edges
entities.forEach(e => {
e.dependencies.forEach(parent => {
graph.get(parent)?.push(e.name);
inDegree.set(e.name, (inDegree.get(e.name) || 0) + 1);
});
});
// Kahn's algorithm: queue nodes with 0 incoming dependencies
const queue: string[] = [];
inDegree.forEach((deg, name) => {
if (deg === 0) queue.push(name);
});
const sortedOrder: string[] = [];
while (queue.length > 0) {
const current = queue.shift()!;
sortedOrder.push(current);
graph.get(current)?.forEach(neighbor => {
inDegree.set(neighbor, inDegree.get(neighbor)! - 1);
if (inDegree.get(neighbor) === 0) queue.push(neighbor);
});
}
return sortedOrder; // Order: ['User', 'Category'] -> ['Product'] -> ['Order'] -> ['OrderItem']
}Key Challenges & Trade-offs
Preventing Broken Foreign Key Cascades
Naive mock generators populate tables in arbitrary order, causing child entities (e.g. order items) to reference non-existent orders and products.
Applied Kahn's DAG topological sort algorithm to guarantee parent entities are always generated and assigned valid IDs before any child entity is hydrated.