{"id":28945896,"url":"https://github.com/bharath-s-j/cfapi","last_synced_at":"2026-04-02T01:16:17.844Z","repository":{"id":299579523,"uuid":"1003198828","full_name":"Bharath-S-J/cfapi","owner":"Bharath-S-J","description":"cfapi is a powerful command-line tool that generates full REST APIs from a simple JSON schema in seconds. Whether you're prototyping or building real apps, cfapi handles everything from input validation to route generation, database setup, and OpenAPI documentation with zero boilerplate.","archived":false,"fork":false,"pushed_at":"2025-06-25T15:04:17.000Z","size":281,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-24T00:58:54.307Z","etag":null,"topics":["automation","cfapi","express","json-schema","mongoose","nodejs","npm","openapi3","restful-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bharath-S-J.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-16T19:23:34.000Z","updated_at":"2025-06-28T17:23:51.000Z","dependencies_parsed_at":"2025-06-17T09:23:19.750Z","dependency_job_id":"99fb5573-2d6a-48ef-a1d9-e747186e2da3","html_url":"https://github.com/Bharath-S-J/cfapi","commit_stats":null,"previous_names":["bharath-s-j/cfapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Bharath-S-J/cfapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bharath-S-J%2Fcfapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bharath-S-J%2Fcfapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bharath-S-J%2Fcfapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bharath-S-J%2Fcfapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bharath-S-J","download_url":"https://codeload.github.com/Bharath-S-J/cfapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bharath-S-J%2Fcfapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31293748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:05:07.454Z","status":"ssl_error","status_checked_at":"2026-04-02T00:56:46.496Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","cfapi","express","json-schema","mongoose","nodejs","npm","openapi3","restful-api"],"created_at":"2025-06-23T07:32:23.759Z","updated_at":"2026-04-02T01:16:17.820Z","avatar_url":"https://github.com/Bharath-S-J.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚡ cfapi – Code-Free API Generator (Prototype)\n\n**cfapi** is a powerful command-line tool that generates full REST APIs from a simple JSON schema — in seconds. Whether you're prototyping or building real apps, cfapi handles everything from input validation to route generation, database setup, and OpenAPI documentation — **with zero boilerplate**.\n\n\u003e 🔰 This is my **first prototype**. I'm still learning backend and open source patterns — feedback is welcome and appreciated!\n\n---\n\n## ✨ Features\n\n✅ Generate a complete API with one command  \n✅ Choose between:\n\n- `mock` engine – JSON file storage with auto-persistence\n- `mongo` engine – Mongoose ODM with full validation\n\n✅ Auto-generates:\n\n- Controllers\n- Routes\n- Middleware validation based on constraints provided in the schema\n- Mongoose/mock models\n- OpenAPI model schemas\n\n✅ Schema-aware:\n\n- Deeply nested objects and arrays\n- References with `ref` fields\n- Validation: `required`, `enum`, `pattern`, `minLength`, `unique`, etc.\n\n✅ Built-in support for:\n\n- Unique constraints in both engines\n- `addModel` to extend existing APIs\n- `.cfapi.config.json` created on first run\n\n✅ Mock engine:\n\n- Auto-generates **10 fake records** per model on creation\n\n✅ MongoDB engine:\n\n- Uses Mongoose schemas with `timestamps`, `ref`, and full validation logic\n\n---\n\n## 📦 CLI Usage\n\n```bash\ncfapi --type \u003cgenerate|add\u003e --schema \u003cpath\u003e --output \u003cdir\u003e --engine \u003cmock|mongo\u003e\n```\n\n### 🔨 Generate Full API\n\n```bash\ncfapi -t generate -s ./schema.json -o ./my-api -e mock\n```\n\u003e ✅ When using the `mock` engine, **10 sample mock records** are created automatically.\n\n### ➕ Add Model(s)\n\n```bash\ncfapi -t add -s ./new-models.json -o ./my-api -e mongo\n```\n\u003e ⚠️ You cannot add a model twice — existing models will be skipped unless `--force` is used.\n\n### Help\n```bash\ncfapi --help\n```\n---\n\n\n## 🧠 PATCH Support: Explained\n\n✅ `PATCH` route exists\n❌ Only supports top-level fields (e.g. `email`, not `profile.bio`)\n🛠️ Nested patching is not supported due to complexity and business logic ambiguity.\n\n---\n\n## ⚠ Limitations\n\n- PATCH only supports flat fields (nested updates are not allowed).\n- No built-in support for authentication, pagination, or advanced filtering.\n- Malformed schemas may result in validation errors or undefined behavior.\n- The id field is handled internally – ensure your schema follows strict rules as demonstrated in the examples.\n- Validation is extremely strict – it will reject any input that does not exactly match the schema definition. No extra fields are allowed.\n\n---\n\n## 📦 Example Outputs\n\ncfapi generates complete, ready-to-run REST API scaffolding based on your schema and selected engine. Below are **four full examples** demonstrating both the `mock` and `mongo` engines across two different schemas:\n\n### 🧪 Sample Schema 1: User API\n\n- ✨ Demonstrates a **basic schema** with string, number, boolean, date, array, enum, and nested object types.\n- ✅ Both mock and MongoDB engines.\n- 📘 Includes auto-generated OpenAPI spec and route/controller/model/middleware files.\n\n| Mock Engine Output                                                                      | MongoDB Engine Output                                                                     |\n| --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| ![Mock Output](https://github.com/Bharath-S-J/cfapi/blob/main/images/mock.png?raw=true) | ![Mongo Output](https://github.com/Bharath-S-J/cfapi/blob/main/images/mongo.png?raw=true) |\n\n- 🔗 [`sample-schema1-mock`](https://github.com/Bharath-S-J/cfapi/tree/main/example-outputs/sample-schema1-mock)\n- 🔗 [`sample-schema1-mongo`](https://github.com/Bharath-S-J/cfapi/tree/main/example-outputs/sample-schema1-mongo)\n\n---\n\n### 🏢 Sample Schema 2: User + Company (Nested + Ref)\n\n- 🔗 Shows a **complex schema** with multiple models and references (`ref`), nested object fields, and validations.\n- 🌱 Highlights `mock` vs `mongo` behavior with relational handling.\n- 📘 Each version includes OpenAPI schema, working routes, and validation middleware.\n- 🔗 [`sample-schema2-mock`](https://github.com/Bharath-S-J/cfapi/tree/main/example-outputs/sample-schema2-mock)\n- 🔗 [`sample-schema2-mongo`](https://github.com/Bharath-S-J/cfapi/tree/main/example-outputs/sample-schema2-mongo)\n\n---\n\n## 📁 Output Structure\n\n```\nmy-api/\n├── config/\n│   └── cfapi.config.json         # Project config\n│   └── db.json                   # MongoDB connection details\n├── controller/                   # Controller functions\n├── middleware/                   # Validation logic\n├── models/                       # Mongoose or mock schemas\n├── openapi-models/               # OpenAPI model schemas\n├── routes/                       # REST routes per model\n├── data/                         # Mock engine only: .json files\n├── .env\n├── package.json\n└── server.js\n```\n\n---\n\n## 🧪 Example Schema\n\n```json\n{\n  \"user\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"id\": {\n        \"type\": \"uuid\"\n      },\n      \"username\": {\n        \"type\": \"string\",\n        \"required\": true,\n        \"unique\": true,\n        \"minLength\": 3,\n        \"maxLength\": 20\n      },\n      \"email\": {\n        \"type\": \"email\",\n        \"required\": true,\n        \"unique\": true\n      },\n      \"age\": {\n        \"type\": \"integer\",\n        \"minimum\": 18,\n        \"maximum\": 100\n      },\n      \"isActive\": {\n        \"type\": \"boolean\"\n      },\n      \"role\": {\n        \"type\": \"string\",\n        \"enum\": [\"user\", \"admin\", \"moderator\"]\n      },\n      \"website\": {\n        \"type\": \"url\"\n      },\n      \"bio\": {\n        \"type\": \"string\",\n        \"maxLength\": 500\n      },\n      \"tags\": {\n        \"type\": \"array\",\n        \"items\": {\n          \"type\": \"string\"\n        },\n        \"minItems\": 1,\n        \"maxItems\": 5\n      },\n      \"address\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"street\": {\n            \"type\": \"string\"\n          },\n          \"city\": {\n            \"type\": \"string\"\n          },\n          \"postalCode\": {\n            \"type\": \"string\",\n            \"pattern\": \"^[0-9]{5}$\"\n          }\n        }\n      },\n      \"createdAt\": {\n        \"type\": \"date\"\n      }\n    }\n  }\n}\n```\n\n---\n\n## 🔧 Supported Types \u0026 Validation Rules\n\n| Feature                  | Supported | Notes                                                                 |\n| ------------------------ | --------- | --------------------------------------------------------------------- |\n| `type`                   | ✅        | string, number, boolean, integer, email, uuid, url, date, object, ref |\n| `required`               | ✅        | Explicitly mark fields as required                                    |\n| `minLength`, `maxLength` | ✅        | Only for strings                                                      |\n| `minimum`, `maximum`     | ✅        | Only for numbers                                                      |\n| `pattern`                | ✅        | Use string-form regex (e.g. `\"^\\\\d+$\"`)                               |\n| `enum`                   | ✅        | Array of allowed values                                               |\n| `unique`                 | ✅        | Works in both mock and mongo engines                                  |\n| `default`                | ✅        | Optional default values                                               |\n| `minItems`, `maxItems`   | ✅        | For arrays                                                            |\n| `timestamps`             | ✅        | Adds `createdAt` and `updatedAt` automatically                        |\n\n---\n\n## 🚀 Getting Started\n\nGot it! Here’s a clear, step-by-step **Usage \u0026 Installation** guide that explains how users can clone your repo, link locally, or install from npm and generate APIs:\n\n---\n\n## 🚀 How to Use cfapi\n\nYou can use **cfapi** either by installing it globally from npm or by cloning and linking the repository locally for development.\n\n### Option 1: Install from npm (recommended)\n\n```bash\nnpm install -g @bharathsj/cfapi\n```\n\nOnce installed globally, generate your API from a schema:\n\n```bash\ncfapi -t generate -s ./schema.json -o ./my-api -e mongo\ncd my-api\nnpm install\nnpm start\n```\n\n### Option 2: Clone \u0026 link locally (for development)\n\nIf you want to use or modify the source code directly:\n\n```bash\ngit clone https://github.com/Bharath-S-J/cfapi.git\ncd cfapi\nchmod +x bin/index.js\nnpm install\nnpm link\n```\n\nThis links the `cfapi` command globally to your local code.\n\nNow you can run the CLI as if installed globally:\n\n```bash\ncfapi -t generate -s ./schema.json -o ./my-api -e mock\ncd my-api\nnpm install\nnpm start\n```\n\n---\n\n## 🛠 Example: Complex Schema\n\n```json\n{\n  \"user\": {\n    \"type\": \"object\",\n    \"timestamps\": true,\n    \"properties\": {\n      \"username\": { \"type\": \"string\", \"minLength\": 3, \"unique\": true },\n      \"email\": { \"type\": \"email\", \"required\": true, \"unique\": true },\n      \"age\": { \"type\": \"integer\", \"minimum\": 18 },\n      \"status\": { \"type\": \"string\", \"enum\": [\"active\", \"inactive\", \"pending\"] },\n      \"password\": { \"type\": \"string\", \"pattern\": \"^(?=.*\\\\d).{8,}$\" },\n      \"profile\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"bio\": \"string\",\n          \"dob\": \"date\",\n          \"social\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"twitter\": \"string\",\n              \"linkedin\": \"string\"\n            }\n          }\n        }\n      },\n      \"roles\": {\n        \"type\": \"array\",\n        \"items\": { \"type\": \"string\" },\n        \"minItems\": 1\n      },\n      \"company\": { \"type\": \"ref\", \"model\": \"company\" }\n    }\n  },\n\n  \"company\": {\n    \"type\": \"object\",\n    \"name\": { \"type\": \"string\", \"required\": true },\n    \"website\": { \"type\": \"url\" },\n    \"location\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"city\": \"string\",\n        \"country\": \"string\"\n      }\n    }\n  }\n}\n```\n\n---\n\n## 📚 Help Output\n\n```bash\ncfapi --help\n```\n\n```\nUsage:\n  cfapi --type \u003cgenerate|add\u003e --schema \u003cpath\u003e --output \u003cdir\u003e --engine \u003cmock|mongo\u003e\n\nOptions:\n  --type, -t     Operation type: \"generate\" or \"add\"\n  --schema, -s   Path to schema JSON file\n  --output, -o   Output directory\n  --engine, -e   Engine to use: \"mock\" or \"mongo\"\n  --help, -h     Show help\n\nExamples:\n  cfapi -t generate -s ./schema.json -o ./my-api -e mock\n  cfapi -t add -s ./posts.json -o ./my-api -e mongo\n```\n\n---\n\n## 🙌 Final Note\n\nThis is a **learning prototype** — designed to explore how far you can go with schema-driven API generation. Feedback, PRs, or issues are all welcome!\n\n---\n\n## 📦 Links\n\n- 🔗 GitHub: [https://github.com/Bharath-S-J/cfapi.git](https://github.com/Bharath-S-J/cfapi.git)\n- 📦 npm: [https://npmjs.com/package/@bharathsj/cfapi](https://npmjs.com/package/@bharathsj/cfapi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbharath-s-j%2Fcfapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbharath-s-j%2Fcfapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbharath-s-j%2Fcfapi/lists"}