Set up a modern backend app by running one command. This project has the goal to create a complete setup for a backend application using TypeScript and Express, Fastify or Hono. It will create many files that are usually created manually. Think about Simba.js like a CRA, but for backend development. Check the project structure for more information.
This package is meant to be installed globally in your computer by using:
npm i -g @anthonylzq/simba.jsAs developer you have two main options to create your new project, one is by running:
simba -qBy doing this your prompt will ask you the following questions:
Project name?, at least one character must be provided.Project description:, at least one character must be provided.Select your package manager,npm,yarnandpnpmare available.Author:, at least one character must be provided.Email:, a correct email address must be provided.Project version:the initial version of the project,0.1.0as default.License:, the license you have chosen for the project.License year (current year):, the year where your license starts, current year as default.Main entity/model name (PascalCase):, the name of the main entity for the generated project. Default:User.Would you want to have a basic GitHub Action for the suit of tests and linting? [y/n]:.Express, Fastify or Hono?, only one of them is valid (lowercase).Will this project use GraphQL? [y/n]:, yes or no question, only y or n is accepted. This is not case sensitive.Which database do you want to use?,MongoDB,PostgreSQL,MySQL,MariaDB,SqliteandMicrosoft SQL Serverare available.
The second option you have is by passing flags in one single command. If you need help, please run:
simba -hThis will generate the following output:
Simba.js, the easiest way to create your TypeScript APIs
Usage:
"simba [options]" or only "simba -q" if you want to be asked for the options one
by one.
Options:
-N, --projectName Project name.
-D, --projectDescription Project description.
-a, --author Author of the project.
-e, --email Email of the author.
-l, --license Type of license for the project, it can be one
of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0
and AGPL 3.0, in lowercase without its version.
[default: "unlicensed"]
-v, --version Project initial version. [default: "0.1.0"]
-y, --licenseYear Year when the license starts. [default: "2026"]
-m, --manager Which package manager you want to use,
available package managers are: npm, yarn and
pnpm. [default: "pnpm"]
-f, --mainFile Main file of the project.
[default: "src/index.ts"]
-q, --questions Whether or not you want to be asked to answer
the questions related to the project one by
one. [boolean] [default: false]
-F, --fastify Whether or not you want to use Fastify for your
project. [boolean] [default: false]
-O, --hono Whether or not you want to use Hono for your
project. [boolean] [default: false]
-g, --graphql Whether or not you want to use GraphQL for your
project. [boolean] [default: false]
--ghat, --gh-action-tests Whether or not you want to have a GitHub Action
with a CI for your tests and linting. If this
option is set to true, the tests flag must be
set to true. [default: false]
-E, --entity Name of the main entity/model to generate
(PascalCase). Default: User. [default: "User"]
-d, --database Which database you want to use, available
databases are: MongoDB (mongo), PostgreSQL
(postgres), MySQL (mysql), MariaDB (mariadb),
Sqlite (sqlite) and Microsoft SQL Server
(sqlServer). [default: "mongo"]
-h, --help Show help [boolean]
Examples:
simba -N 'Project Name' -D 'Project description' -a Anthony -e
sluzquinosa@uni.pe -l mit -F -d mongo --ghat
Developed by AnthonyLzqLet's suppose you want to build a project with Express (the default framework):
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.comHere we are specifying that we want to create a new project called myProject using the MIT license, my name and my email are respectively: myName and myEmail@email.com.
As default, pnpm is selected as package manager, but if you don't want to use it, you can pass the flag -m or --manager as follows:
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -m yarnWhat if I want to use Fastify instead Express? Well, you only have to pass the -F flag:
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -FAnd if I want to use Hono? Pass the -O flag:
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -OIf I want to use a relational database instead MongoDB? Well, you only have to pass the -d flag:
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -d postgresThe available databases are:
MongoDB(mongo)PostgreSQL(postgres)MySQL(mysql)MariaDB(mariadb)Sqlite(sqlite)Microsoft SQL Server(sqlServer).
And how can I use GraphQL? Well, you only have to pass the -g flag:
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -F -gWhat if I want my project scaffolded around a different entity instead of User? Pass the -E flag with a PascalCase name:
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -E ProductThe default entity (User) generates lastName and name fields. A custom entity generates name and description fields. Routes, services, schemas, Prisma models, and tests are all scaffolded around the provided entity name.
Finally, you may not want to use a license or one of the available licenses, don't worry, just don't pass the flag -l neither --license as follows:
simba -N myProject -D 'This is a test' -a myName -e myEmail@email.comIf you want to check the content of the files, please check the example folder, there you will find an example for Express, Fastify and Hono (REST and GraphQL versions). Regardless of the option chosen, a new folder will be generated with the name of the project.
Also, if you are interested in the folder structure of each case, please take a look at:
- Express
- Express-GraphQL
- Express-Mongo
- Express-Mongo-GraphQL
- Fastify
- Fastify-GraphQL
- Fastify-Mongo
- Fastify-Mongo-GraphQL
- Hono
- Hono-GraphQL
- Hono-Mongo
- Hono-Mongo-GraphQL
-
Prisma v6: Generated projects use Prisma v6 (pinned). Prisma v7 is not used because it does not support MongoDB. When Prisma v7 adds MongoDB support, Simba.js will be updated accordingly.
-
You are able to run a server that has one main route,
home(/), your entity route (e.g.api/userorapi/user/:idfor the defaultUserentity) anddocs(api/docs), in case you are not using GraphQL. The route name is derived from the entity name you provide. -
In case you are using GraphQL, there are 3 mutations (
store,update, anddeleteById) and 1 query available (getById), you can find them in the playground under the route/api. -
To connect your server with your database, you need to provide your database url in the
.env, except if you choosesqlite. By default, Simba will try to connect to a local database. The content of the.envfile is:DATABASE_URL = mongodb://mongo:mongo@mongo:27017/${projectName} # in case you choose mongo # or DATABASE_URL = postgres://postgres:postgres@postgres:5432/${projectName} # in case you choose postgres
Where
${projectName}will be replaced by the name of the project you provided in lowercase. -
Once you have done that, now you can perform the following
HTTP REQUEST:GET,POST,PATCHandDELETE. -
In order to use global variables, just add the one you need in the
src/@types/index.d.tsfile, and add a newvarwith its type to theglobalinterface, as follows:// src/@types/index.d.ts // Some code... declare global { var globalStringVariable: string // Some more code... } // Some more code... // another file global.globalStringVariable = 'Hi mom, I am global' console.log({ globalStringVariable })
-
The provided project structure is inspired in my personal experience as
Node.jsdeveloper and theNestframework. It follows a layered architecture:- Presentation layer (network layer): it is represented by the network and schemas folders, which contains the routes and the schemas necessary for each route.
- Business layer (services layer): it is represented by the services folder, which contains all the code related to the business logic of your application.
- Persistance layer (database layer): it is represented by the database folder, which contains the database connection, models and queries (that will be used by the services). Multiple database connection are possible and should be implemented here.
-
The server is fully tested and has no errors (at least for now), feel free to report one here.
-
Support for windows and linux platforms is available.
-
To check the content of the files generated, please check the
examplefolder. -
If you provide a project name that contains spaces, something like 'My awesome Project', every space will be replaced with a hyphen. So at the end your project name will be 'My-awesome-project', but in its README.md file, the hyphens will be removed and the project name will be parsed to title case (My Awesome Project).
-
Finally,
gitwill be initialized and a list of libraries will be installed. Check the notes. -
Relative imports is already configured, you do not need to import a file using
../../../some/very/nested/stuff/in/other/folder, you can usesome/very/nested/stuff/in/other/folderassuming that your folder is under thesrcfolder.
|
|
|
| Chazki | Mein | Securitec |
Please check the changelog.md file. Also, if you want to check what is coming, check the road map.
Here is the list of the packages that are being installed, as dependencies:
As devDependencies:
@biomejs/biome@types/debug@types/http-errors@types/nodeaxiosdotenvnodemonprismacommit-and-tag-versiontsxtypescriptvite-tsconfig-pathsvitest
As dependencies:
As devDependencies:
As dependencies:
@as-integrations/express5(only when using GraphQL)@asteasolutions/zod-to-openapicorsexpressswagger-ui-express
As devDependencies:
As dependencies:
@as-integrations/fastify(only when using GraphQL)@fastify/cors@fastify/swagger@fastify/swagger-uifastifyfastify-type-provider-zod
As dependencies:
As dependencies:
As dependencies:
As dependencies:
As dependencies:
As dependencies:
Feel free to contribute to this project. Every contribution will be appreciated.
- Anthony Luzquiños - Initial Work - Documentation - AnthonyLzq.
- Andree Anchi - Bug reports - andreewaD.
