A comprehensive backend MVP that provides a generic CRUD API for mocking any entity, complete with REST endpoints, GraphQL API, auto-generated documentation, and comprehensive testing.
# Install dependencies
pnpm install
# Start development server
pnpm devThe server will start on http://localhost:3000 with the following endpoints available:
- API Root:
http://localhost:3000 - Health Check:
http://localhost:3000/health - REST API:
http://localhost:3000/api/:entity - GraphQL:
http://localhost:3000/graphql - API Documentation:
http://localhost:3000/docs
Generic CRUD operations for any entity type:
GET /api/:entity- List all entitiesGET /api/:entity/:id- Get entity by IDPOST /api/:entity- Create new entityPUT /api/:entity/:id- Update entityDELETE /api/:entity/:id- Delete entityGET /health- Health check endpoint
Full GraphQL implementation with:
- Auto-generated schema for all entity types
- Query and mutation support
- GraphQL playground at
/graphql - Custom JSON scalar for flexible data types
- OpenAPI 3.0 specification
- Interactive Swagger UI at
/docs - Comprehensive endpoint documentation
- Vitest + Supertest for API testing
- Health endpoint tests
- REST API integration tests
- GraphQL query/mutation tests
curl -X POST http://localhost:3000/api/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"age": 30
}'curl http://localhost:3000/api/userscurl http://localhost:3000/api/users/123e4567-e89b-12d3-a456-426614174000curl -X PUT http://localhost:3000/api/users/123e4567-e89b-12d3-a456-426614174000 \
-H "Content-Type: application/json" \
-d '{
"name": "John Smith",
"age": 31
}'curl -X DELETE http://localhost:3000/api/users/123e4567-e89b-12d3-a456-426614174000mutation {
createEntity(type: "products", input: {
name: "Laptop",
price: 999.99,
category: "Electronics"
}) {
id
data
createdAt
}
}query {
entities(type: "products") {
id
data
createdAt
updatedAt
}
}query {
entity(type: "products", id: "your-entity-id") {
id
data
createdAt
updatedAt
}
}query {
health {
status
timestamp
uptime
version
}
}# Run all tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Run linting
pnpm lint
# Fix linting issues
pnpm lint:fix
# Format code
pnpm formatsrc/
โโโ index.ts # Main server setup
โโโ types/ # TypeScript type definitions
โโโ services/
โ โโโ storage.ts # JSON file storage service
โโโ routes/
โ โโโ health.ts # Health check endpoint
โ โโโ api.ts # Generic CRUD endpoints
โโโ graphql/
โ โโโ schema.ts # GraphQL type definitions
โ โโโ resolvers.ts # GraphQL resolvers
โโโ docs/
โโโ openapi.ts # OpenAPI specification
tests/ # Test files
โโโ health.test.ts
โโโ api.test.ts
โโโ graphql.test.ts
mocks.json # JSON storage file
The API is completely generic - you can work with any entity type by simply using it in the URL path. Examples:
/api/users- User management/api/posts- Blog posts/api/products- Product catalog/api/orders- Order management/api/anything- Any custom entity
Each entity automatically gets:
- UUID-based ID generation
createdAtandupdatedAttimestamps- Flexible JSON data storage
- Full CRUD operations via REST and GraphQL
PORT- Server port (default: 3000)NODE_ENV- Environment (development/production)
Data is persisted in mocks.json file in the project root. The file is automatically created if it doesn't exist.
Visit http://localhost:3000/docs for interactive Swagger UI documentation with:
- Complete endpoint descriptions
- Request/response schemas
- Try-it-out functionality
- Authentication examples
Visit http://localhost:3000/graphql for GraphQL playground with:
- Schema introspection
- Query/mutation examples
- Real-time query execution
- Documentation explorer
# Build the project
pnpm build
# Start production server
pnpm start- Node.js v20+ - Runtime environment
- Express.js - Web framework
- Apollo Server - GraphQL server
- TypeScript - Type safety
- Vitest - Testing framework
- Supertest - HTTP testing
- Swagger UI - API documentation
- ESLint + Prettier - Code quality
MIT License - feel free to use this project for your own mock API needs!