Welcome to the Create MVC Server tool! This utility helps you easily scaffold a new MVC server for your project with an interactive setup.
You can customise your server with the following options:
- Server Framework: Choose between Express or Hono (PostgreSQL only).
- Database: Select from PostgreSQL, MongoDB, MySQL, or SQLite.
- Language: Pick either JavaScript or TypeScript.
You can create your project in two ways:
The interactive mode guides you through a series of prompts to configure your project:
npx create-mvc-server my-project
The process includes:
- Project Name: Enter your project name (defaults to "mvc-server" if not specified).
- Configuration Mode: Choose between individual component selection or a pre-defined template.
- Component Selection (if choosing individual components):
- Select your server framework (Express or Hono).
- Choose your database (PostgreSQL, MongoDB, MySQL, or SQLite).
- Pick your language (JavaScript or TypeScript).
- Template Selection (if choosing template mode):
- Select from available templates that match your framework, database, and language choices.
- Directory Handling: Decide what to do if the target directory exists (overwrite, merge, or cancel).
- Package Name Validation: Verify or modify the package name for npm compatibility.
- Configuration Summary: Review your selections before proceeding.
- Project Creation: Files are copied and customised based on your selections.
If you already know which template you want to use, you can skip the interactive prompts by specifying a template directly:
npx create-mvc-server my-project --template <template-name>
This mode is perfect for:
- Quickly creating projects with the same configuration.
- Using the tool in scripts or CI/CD pipelines.
Usage: create-mvc-server [options] [project-name]
Options:
-t, --template NAME Specify a template to use.
-h, --help Display this help message.
The CLI dynamically discovers templates from the filesystem. Here are some standard templates you can use:
pg-ts
: Express + PostgreSQL + TypeScriptpg
: Express + PostgreSQL + JavaScriptmongo-ts
: Express + MongoDB + TypeScriptmongo
: Express + MongoDB + JavaScriptmysql-ts
: Express + MySQL + TypeScriptmysql
: Express + MySQL + JavaScriptsqlite-ts
: Express + SQLite + TypeScriptsqlite
: Express + SQLite + JavaScripthono-pg-ts
: Hono + PostgreSQL + TypeScripthono-pg
: Hono + PostgreSQL + JavaScript
- Interactive CLI prompts for easy project configuration.
- Dynamic template discovery from the filesystem.
- Option to initialise a Git repository.
- Automatic package name validation.
- Smart template selection based on your choices.
- Support for multiple package managers (npm, yarn).
- Directory conflict resolution.
- Automatic file renaming (e.g., _gitignore → .gitignore).
The generated project will include:
- Basic server setup with your chosen framework.
- Database configuration.
- Type definitions (for TypeScript projects).
- Basic routing structure.
- Error handling middleware.
- Environment configuration.
- Testing setup.
# Create a new project with interactive prompts
npx create-mvc-server my-server
# Create a new project using a specific template
npx create-mvc-server my-server --template pg-ts
After creating your project, follow the printed instructions to:
- Navigate to the project directory.
- Install dependencies.
- Start the development server.
Depending on your chosen database, you'll need to set it up accordingly:
- Install PostgreSQL locally or use a cloud service (e.g., AWS RDS, DigitalOcean).
- Set up connection details in your
.env
file:DATABASE_URL=postgresql://user:password@localhost:5432/dbname
- Install MongoDB locally or use MongoDB Atlas.
- Set up connection details in your
.env
file:MONGODB_URI=mongodb://localhost:27017/dbname
- Install MySQL locally or use a cloud service.
- Set up connection details in your
.env
file:DATABASE_URL=mysql://user:password@localhost:3306/dbname
- No additional installation required.
- Set up the database path in your
.env
file:DATABASE_URL=file:./dev.db
You can deploy the generated server to various platforms, including:
- Supabase: Supports PostgreSQL, MongoDB, MySQL, and SQLite.
- Heroku: Compatible with all database options.
- Vercel: Works well with Serverless deployment (especially Hono).
- DigitalOcean: Supports all database options.
- AWS: Can be deployed to EC2, ECS, or Lambda.
- Railway: Excellent for both application and database hosting.
Remember to:
- Set up appropriate environment variables.
- Configure your database connection string.
- Implement proper security measures (e.g., SSL, firewalls).
The Create MVC Server tool uses a dynamic template discovery system to find and manage available templates:
- The CLI scans for directories with the naming pattern
template-{id}
. - Template requirements are automatically inferred from the ID based on naming conventions.
- Available options (frameworks, databases, languages) are mapped to parts of the template ID.
- The CLI provides a fallback to default templates if none are discovered.
- Template directories must follow the naming pattern:
template-[server]-[database]-[language]
. - Some parts can be omitted, and defaults will be used:
- If the server is omitted: Express is assumed.
- If the language is omitted: JavaScript is assumed.
- The database must always be specified.
The CLI recognises these technology identifiers in template names:
- Servers:
express
,hono
- Databases:
pg
(PostgreSQL),mongo
(MongoDB),mysql
(MySQL),sqlite
(SQLite) - Languages:
ts
(TypeScript) - omit for JavaScript
We welcome contributions to improve Create MVC Server! Here's how you can help:
- Fork the Repository: Visit the GitHub repository and click the "Fork" button to create a copy in your GitHub account.
- Clone Your Fork:
git clone https://github.com/your-username/create-mvc-server.git cd create-mvc-server
- Install Dependencies:
npm install
- Create a Feature Branch:
git checkout -b feature/your-feature-name
- Make Your Changes: Implement your features or bug fixes while following the project's code style and conventions.
- Build and Test:
npm run build # Test your changes thoroughly
- Commit Your Changes:
git commit -m "Add feature: your feature description"
- Push to Your Fork:
git push origin feature/your-feature-name
- Create a Pull Request: Go to the original repository, click "New Pull Request," select "compare across forks," and describe your changes in detail.
- Wait for Review: Maintainers will review your PR. Address any requested changes, and once approved, your PR will be merged.
You can contribute by creating new templates. Here's how:
- Create a new directory in the project using the naming convention:
template-[server]-[database]-[language]
. - Structure your template following existing templates as a guide.
- Ensure your template includes:
- A complete server setup with the specified framework.
- Database configuration for the specified database.
- Standard MVC architecture (models, views, controllers).
- A
package.json
file with appropriate dependencies. - Any special files like
_gitignore
(which will be renamed to.gitignore
).
For the best compatibility:
- Use consistent folder structures across templates.
- Include clear documentation within the template.
- Add appropriate TypeScript types (for TypeScript templates).
- Include basic security measures (e.g., helmet for Express).
- Add sensible defaults for configuration.
- Ensure all environment variables are properly documented.
- Include example routes and controllers.
After creating a new template:
- Build the project with
npm run build
. - Test your template with:
node packages/create-mvc/index.js my-test-project --template your-template-id
- Validate that the generated project works as expected.
If you find a bug or have a feature request:
- Check if the issue already exists in the GitHub issues.
- If not, create a new issue with a descriptive title.
- Include detailed steps to reproduce the bug or a clear description of the feature.
- Provide relevant information like your operating system, Node.js version, etc.
We appreciate your contributions to making Create MVC Server better!