Gathering detailed insights and metrics for @bharathsj/cfapi
Gathering detailed insights and metrics for @bharathsj/cfapi
Gathering detailed insights and metrics for @bharathsj/cfapi
Gathering detailed insights and metrics for @bharathsj/cfapi
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.
npm install @bharathsj/cfapi
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
8 Commits
1 Branches
1 Contributors
Updated on Jun 28, 2025
Latest Version
1.0.1
Package Id
@bharathsj/cfapi@1.0.1
Unpacked Size
102.63 kB
Size
21.68 kB
File Count
26
NPM Version
10.9.2
Node Version
22.14.0
Published on
Jun 25, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
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.
🔰 This is my first prototype. I'm still learning backend and open source patterns — feedback is welcome and appreciated!
✅ Generate a complete API with one command
✅ Choose between:
mock
engine – JSON file storage with auto-persistencemongo
engine – Mongoose ODM with full validation✅ Auto-generates:
✅ Schema-aware:
ref
fieldsrequired
, enum
, pattern
, minLength
, unique
, etc.✅ Built-in support for:
addModel
to extend existing APIs.cfapi.config.json
created on first run✅ Mock engine:
✅ MongoDB engine:
timestamps
, ref
, and full validation logic1cfapi --type <generate|add> --schema <path> --output <dir> --engine <mock|mongo>
1cfapi -t generate -s ./schema.json -o ./my-api -e mock
✅ When using the
mock
engine, 10 sample mock records are created automatically.
1cfapi -t add -s ./new-models.json -o ./my-api -e mongo
⚠️ You cannot add a model twice — existing models will be skipped unless
--force
is used.
1cfapi --help
✅ PATCH
route exists
❌ Only supports top-level fields (e.g. email
, not profile.bio
)
🛠️ Nested patching is not supported due to complexity and business logic ambiguity.
cfapi 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:
Mock Engine Output | MongoDB Engine Output |
---|---|
![]() | ![]() |
ref
), nested object fields, and validations.mock
vs mongo
behavior with relational handling.sample-schema2-mock
sample-schema2-mongo
my-api/
├── config/
│ └── cfapi.config.json # Project config
│ └── db.json # MongoDB connection details
├── controller/ # Controller functions
├── middleware/ # Validation logic
├── models/ # Mongoose or mock schemas
├── openapi-models/ # OpenAPI model schemas
├── routes/ # REST routes per model
├── data/ # Mock engine only: .json files
├── .env
├── package.json
└── server.js
1{ 2 "user": { 3 "type": "object", 4 "properties": { 5 "id": { 6 "type": "uuid" 7 }, 8 "username": { 9 "type": "string", 10 "required": true, 11 "unique": true, 12 "minLength": 3, 13 "maxLength": 20 14 }, 15 "email": { 16 "type": "email", 17 "required": true, 18 "unique": true 19 }, 20 "age": { 21 "type": "integer", 22 "minimum": 18, 23 "maximum": 100 24 }, 25 "isActive": { 26 "type": "boolean" 27 }, 28 "role": { 29 "type": "string", 30 "enum": ["user", "admin", "moderator"] 31 }, 32 "website": { 33 "type": "url" 34 }, 35 "bio": { 36 "type": "string", 37 "maxLength": 500 38 }, 39 "tags": { 40 "type": "array", 41 "items": { 42 "type": "string" 43 }, 44 "minItems": 1, 45 "maxItems": 5 46 }, 47 "address": { 48 "type": "object", 49 "properties": { 50 "street": { 51 "type": "string" 52 }, 53 "city": { 54 "type": "string" 55 }, 56 "postalCode": { 57 "type": "string", 58 "pattern": "^[0-9]{5}$" 59 } 60 } 61 }, 62 "createdAt": { 63 "type": "date" 64 } 65 } 66 } 67}
Feature | Supported | Notes |
---|---|---|
type | ✅ | string, number, boolean, integer, email, uuid, url, date, object, ref |
required | ✅ | Explicitly mark fields as required |
minLength , maxLength | ✅ | Only for strings |
minimum , maximum | ✅ | Only for numbers |
pattern | ✅ | Use string-form regex (e.g. "^\\d+$" ) |
enum | ✅ | Array of allowed values |
unique | ✅ | Works in both mock and mongo engines |
default | ✅ | Optional default values |
minItems , maxItems | ✅ | For arrays |
timestamps | ✅ | Adds createdAt and updatedAt automatically |
Got it! Here’s a clear, step-by-step Usage & Installation guide that explains how users can clone your repo, link locally, or install from npm and generate APIs:
You can use cfapi either by installing it globally from npm or by cloning and linking the repository locally for development.
1npm install -g @bharathsj/cfapi
Once installed globally, generate your API from a schema:
1cfapi -t generate -s ./schema.json -o ./my-api -e mongo 2cd my-api 3npm install 4npm start
If you want to use or modify the source code directly:
1git clone https://github.com/Bharath-S-J/cfapi.git 2cd cfapi 3chmod +x bin/index.js 4npm install 5npm link
This links the cfapi
command globally to your local code.
Now you can run the CLI as if installed globally:
1cfapi -t generate -s ./schema.json -o ./my-api -e mock 2cd my-api 3npm install 4npm start
1{ 2 "user": { 3 "type": "object", 4 "timestamps": true, 5 "properties": { 6 "username": { "type": "string", "minLength": 3, "unique": true }, 7 "email": { "type": "email", "required": true, "unique": true }, 8 "age": { "type": "integer", "minimum": 18 }, 9 "status": { "type": "string", "enum": ["active", "inactive", "pending"] }, 10 "password": { "type": "string", "pattern": "^(?=.*\\d).{8,}$" }, 11 "profile": { 12 "type": "object", 13 "properties": { 14 "bio": "string", 15 "dob": "date", 16 "social": { 17 "type": "object", 18 "properties": { 19 "twitter": "string", 20 "linkedin": "string" 21 } 22 } 23 } 24 }, 25 "roles": { 26 "type": "array", 27 "items": { "type": "string" }, 28 "minItems": 1 29 }, 30 "company": { "type": "ref", "model": "company" } 31 } 32 }, 33 34 "company": { 35 "type": "object", 36 "name": { "type": "string", "required": true }, 37 "website": { "type": "url" }, 38 "location": { 39 "type": "object", 40 "properties": { 41 "city": "string", 42 "country": "string" 43 } 44 } 45 } 46}
1cfapi --help
Usage:
cfapi --type <generate|add> --schema <path> --output <dir> --engine <mock|mongo>
Options:
--type, -t Operation type: "generate" or "add"
--schema, -s Path to schema JSON file
--output, -o Output directory
--engine, -e Engine to use: "mock" or "mongo"
--help, -h Show help
Examples:
cfapi -t generate -s ./schema.json -o ./my-api -e mock
cfapi -t add -s ./posts.json -o ./my-api -e mongo
This is a learning prototype — designed to explore how far you can go with schema-driven API generation. Feedback, PRs, or issues are all welcome!
No vulnerabilities found.
No security vulnerabilities found.