
A delightful way to building a Node.js RESTful API Services with beautiful code written in TypeScript.
Inspired by the awesome framework laravel in PHP and of the repositories from pleerock
Made with ❤️ by w3tech, Gery Hirschfeld and contributors

Our main goal with this project is a feature complete server application. We like you to be focused on your business and not spending hours in project configuration.
Try it!! We are happy to hear your feedback or any kind of new features.


You need to set up your development environment before you can do anything.
Install Node.js and NPM
brew install nodechoco install nodejsInstall yarn globally
yarn install yarn -g
Install a MySQL database.
If you work with a mac, we recommend to use homebrew for the installation.
Fork or download this project. Configure your package.json for your new project.
Then copy the .env.example file and rename it to .env. In this file you have to add your database connection information.
Create a new database with the name you have in your .env-file.
Then setup your application environment.
yarn run setup
This installs all dependencies with yarn. After that it migrates the database and seeds some test data into it. So after that your development environment is ready to use.
Go to the project dir and start your app with this yarn script.
yarn start serve
This starts a local server using
nodemon, which will watch for any file changes and will restart the sever according to these changes. The server address will be displayed to you ashttp://0.0.0.0:3000.

All script are defined in the package-scripts.js file, but the most important ones are listed here.
yarn installyarn start lint. This runs tslint.lint.yarn start test (There is also a vscode task for this called test).yarn start test.integration.yarn start test.e2e.yarn start serve to start nodemon with ts-node, to serve the app.http://0.0.0.0:3000yarn start build to generated all JavaScript files from the TypeScript sources (There is also a vscode task for this called build).dist use yarn start.typeorm migration:create -n <migration-file-name> to create a new migration file.typeorm -h to see more useful cli commands like generating migration out of your models.yarn start db.migrate.yarn start db.revert.yarn start db.drop.yarn start db.seed to seed your seeds into the database.
To debug your code run yarn start build or hit cmd + b to build your app.
Then, just set a breakpoint and hit F5 in your Visual Studio Code.

The route prefix is /api by default, but you can change this in the .env file.
The swagger and the monitor route can be altered in the .env file.
| Route | Description |
|---|---|
| /api | Shows us the name, description and the version of the package.json |
| /graphql | Route to the graphql editor or your query/mutations requests |
| /swagger | This is the Swagger UI with our API documentation |
| /monitor | Shows a small monitor page for the server |
| /api/users | Example entity endpoint |
| /api/pets | Example entity endpoint |

| Name | Description |
|---|---|
| .vscode/ | VSCode tasks, launch configuration and some other settings |
| dist/ | Compiled source files will be placed here |
| src/ | Source files |
| src/api/controllers/ | REST API Controllers |
| src/api/controllers/requests | Request classes with validation rules if the body is not equal with a model |
| src/api/controllers/responses | Response classes or interfaces to type json response bodies |
| src/api/errors/ | Custom HttpErrors like 404 NotFound |
| src/api/interceptors/ | Interceptors are used to change or replace the data returned to the client. |
| src/api/middlewares/ | Express Middlewares like helmet security features |
| src/api/models/ | Bookshelf Models |
| src/api/repositories/ | Repository / DB layer |
| src/api/services/ | Service layer |
| src/api/subscribers/ | Event subscribers |
| src/api/validators/ | Custom validators, which can be used in the request classes |
| src/api/resolvers/ | GraphQL resolvers (query, mutation & field-resolver) |
| src/api/types/ | GraphQL types ,input-types and scalar types |
| src/api/ schema.gql | Generated GraphQL schema |
| src/api/ swagger.json | Swagger documentation |
| src/auth/ | Authentication checkers and services |
| src/core/ | The core features like logger and env variables |
| src/database/factories | Factory the generate fake entities |
| src/database/migrations | Database migration scripts |
| src/database/seeds | Seeds to create some data in the database |
| src/decorators/ | Custom decorators like @Logger & @EventDispatch |
| src/loaders/ | Loader is a place where you can configure your app |
| src/public/ | Static assets (fonts, css, js, img). |
| src/types/ *.d.ts | Custom type definitions and files that aren't on DefinitelyTyped |
| test | Tests |
| test/e2e/ *.test.ts | End-2-End tests (like e2e) |
| test/integration/ *.test.ts | Integration test with SQLite3 |
| test/unit/ *.test.ts | Unit tests |
| .env.example | Environment configurations |
| .env.test | Test environment configurations |
| mydb.sql | SQLite database for integration tests. Ignored by git and only available after integration tests |

Our logger is winston. To log http request we use the express middleware morgan. We created a simple annotation to inject the logger in your service (see example below).
import { Logger, LoggerInterface } from '../../decorators/Logger';
@Service()
export class UserService {
constructor(
@Logger(__filename) private log: LoggerInterface
) { }
...

We use this awesome repository event-dispatch for event dispatching.
We created a simple annotation to inject the EventDispatcher in your service (see example below). All events are listed in the events.ts file.
import { events } from '../subscribers/events';
import { EventDispatcher, EventDispatcherInterface } from '../../decorators/EventDispatcher';
@Service()
export class UserService {
constructor(
@EventDispatcher() private eventDispatcher: EventDispatcherInterface
) { }
public async create(user: User): Promise<User> {
...
this.eventDispatcher.dispatch(events.user.created, newUser);
...
}

Isn't it exhausting to create some sample data for your database, well this time is over!
How does it work? Just create a factory for your entities (models) and a seed script.
For all entities we want to seed, we need to define a factory. To do so we give you the awesome faker library as a parameter into your factory. Then create your "fake" entity and return it. Those factory files should be in the src/database/factories folder and suffixed with Factory like src/database/factories/UserFactory.ts.
Settings can be used to pass some static value into the factory.
define(User, (faker: typeof Faker, settings: { roles: string[] }) => {
const gender = faker.random.number(1);
const firstName = faker.name.firstName(gender);
const lastName = faker.name.lastName(gender);
const email = faker.internet.email(firstName, lastName);
const user = new User();
user.firstName = firstName;
user.lastName = lastName;
user.email = email;
user.roles = settings.roles;
return user;
});
Handle relation in the entity factory like this.
define(Pet, (faker: typeof Faker, settings: undefined) => {
const gender = faker.random.number(1);
const name = faker.name.firstName(gender);
const pet = new Pet();
pet.name = name;
pet.age = faker.random.number();
pet.user = factory(User)({ roles: ['admin'] })
return pet;
});
The seeds files define how much and how the data are connected with each other. The files will be execu
$ claude mcp add express-typescript-boilerplate \
-- python -m otcore.mcp_server <graph>