All Projects → chocolat-chaud-io → Stator

chocolat-chaud-io / Stator

Licence: mit
Stator, your go-to template for the perfect stack. 😍🙏

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Stator

Nestjs Bff
A full-stack TypeScript solution, and starter project. Includes an API, CLI, and example client webapp. Features include production grade logging, authorization, authentication, MongoDB migrations, and end-to-end testing.
Stars: ✭ 450 (+107.37%)
Mutual labels:  nestjs, fullstack, boilerplate, template
Graphql Starter
💥 Monorepo template (seed project) pre-configured with GraphQL API, PostgreSQL, React, Relay, and Material UI.
Stars: ✭ 3,377 (+1456.22%)
Mutual labels:  postgres, boilerplate, monorepo, template
Generate
A new command line tool and developer framework for scaffolding out GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.
Stars: ✭ 238 (+9.68%)
Mutual labels:  project, boilerplate, generator, template
Rest Nestjs Postgres
CrudJS implemented as a REST API, using Nest.js and Postgres
Stars: ✭ 93 (-57.14%)
Mutual labels:  postgres, crud, nest, boilerplate
Crud
NestJs CRUD for RESTful APIs
Stars: ✭ 2,709 (+1148.39%)
Mutual labels:  crud, nestjs, nest
Ngx Starter Kit
🅰️ Angular 🚀 NestJS 🐒 Starter Kit
Stars: ✭ 479 (+120.74%)
Mutual labels:  postgres, nestjs, monorepo
Extension Create
Create modern cross-browser extensions with no build configuration.
Stars: ✭ 167 (-23.04%)
Mutual labels:  boilerplate, generator, template
Suicrux
🚀 Ultimate universal starter with lazy-loading, SSR and i18n. [not maintained]
Stars: ✭ 958 (+341.47%)
Mutual labels:  fullstack, boilerplate, template
Fastapi React
🚀 Cookiecutter Template for FastAPI + React Projects. Using PostgreSQL, SQLAlchemy, and Docker
Stars: ✭ 501 (+130.88%)
Mutual labels:  postgres, full-stack, boilerplate
Sao
⚔ Futuristic scaffolding tool
Stars: ✭ 966 (+345.16%)
Mutual labels:  boilerplate, generator, template
Expo Three Demo
🍎👩‍🏫 Collection of Demos for THREE.js in Expo!
Stars: ✭ 76 (-64.98%)
Mutual labels:  project, boilerplate, template
Mevn Boilerplate
A fullstack boilerplate with Mongo, ExpressJS, VueJS and NodeJS.
Stars: ✭ 277 (+27.65%)
Mutual labels:  full-stack, fullstack, boilerplate
ogma
A monorepo for the ogma logger and related packages
Stars: ✭ 201 (-7.37%)
Mutual labels:  monorepo, nest, nestjs
Fullstack Apollo Express Postgresql Boilerplate
💥 A sophisticated GraphQL with Apollo, Express and PostgreSQL boilerplate project.
Stars: ✭ 1,079 (+397.24%)
Mutual labels:  postgres, fullstack, boilerplate
Pollinate
Template your base files and generate new projects from Git(Hub).
Stars: ✭ 213 (-1.84%)
Mutual labels:  project, boilerplate, generator
Swiftproject
🏆 Generate Swift project with necessary toolings
Stars: ✭ 27 (-87.56%)
Mutual labels:  project, generator, template
Swift Template
A template based module generator for Swift projects.
Stars: ✭ 34 (-84.33%)
Mutual labels:  boilerplate, generator, template
Vue Monorepo Boilerplate
Vue Fullstack App Monorepo Boilerplate
Stars: ✭ 136 (-37.33%)
Mutual labels:  fullstack, boilerplate, monorepo
Automatic Gatsbyjs App Landing Page
Automatic GatsbyJS App Landing Page - Automatically generate iOS app landing page using GatsbyJS
Stars: ✭ 137 (-36.87%)
Mutual labels:  boilerplate, generator, template
Yii2 Enhanced Gii
Enhanced Yii2 Gii (generator) that generates related Models & CRUD
Stars: ✭ 183 (-15.67%)
Mutual labels:  crud, generator

Stator

Stator, your go-to template for the perfect stack.

🚀 Quick Start

The interactive CLI will guide you to easily setup your project.

npm run get-started

📋 Table of Contents

📚 About the Project

Have you ever started a new project by yourself?
If so, you probably know that it is tedious to set up all the necessary tools.
Just like you, the part I enjoy the most is coding, not boilerplate.

Say hi to stator, a full-stack TypeScript template that enforces conventions, handles releases, automates deployments and much more!

If you want more details about how this idea was implemented, I recommend reading the series of blog articles I wrote on the topic.

🦄 Demo Application

This template includes a demo todo application that serves as an example of sound patterns. Of course, you won't be creating a todo application for your project, but you can use this as an example of useful patterns and learn how to use the technologies presented in this project.

demo application

Technical Stack

For a detailed list of all those technologies, you can read this blog article.

Deployment Database Backend Frontend Testing Conventions
DigitalOcean App Platform Postgres Nest React jest commitlint
semantic-release Mongo Fastify React Router cypress eslint
TypeORM Swagger Redux prettier
NestJs CRUD ReDoc Redux Toolkit
Material UI

💥 Getting Started

Prerequisites

Copy the template

This repository is a repository template, which means you can use the Use this template button at the top to create your project based on this.

use template button

*Note: If you have an existing repository, this will require more work. I would recommend using the use template button and migrating your current code to the newly created projects.

Make it yours

You will now want to make this project yours by replacing all organization and project naming occurrences with your own names. Thankfully, we have a script just for that:

npm run rename-project -- --organization {YOUR_ORGANIZATION_NAME} --project {YOUR_PROJECT_NAME}

*Note: I highly recommend that the project name is the same as your git repository.

The file will delete itself once it has been completed. On completion, you will see the following message:

project appropriation success

Run the application

First, install the dependencies:

npm i

Then, run the whole stack:

npm run postgres
npm start api
npm start webapp

Finally, why not test it:

npm test api && npm run e2e webapp-e2e

For a full list of available commands, consult the package.json.

Continuous Integration

This templates integrates Github Actions for its Continuous Integration. The existing workflows are under .github/workflows. To have the CI working, you must:

  1. (Optional) Link your repository with Coveralls, or with Codecov by inserting your CODECOV_TOKEN in github secrets.
  2. (Optional) Insert your Nx Cloud access token in github secrets under NX_CLOUD_TOKEN. This enables for caching and faster build times.

Deployment

The application can be deployed in two different ways, depending on your objectives.

Digital Ocean App Platform

For a simple and fast deployment, the new App Platform from Digital Ocean makes it easy to work with monorepos. For our todo app, the config file lies under .do/app.yaml. There, you can change the configuration of the different apps being deployed. The spec can be found here.

To deploy this full stack application yourself, follow the steps below:

  1. Create an account on Digital Ocean Cloud (this is a sponsored link) and enable Github access
  2. Install doctl CLI
  3. Run doctl apps create --spec .do/app.yaml
  4. View the build, logs, and deployment url here

Once done, your app will be hooked to master branch commits as defined in the spec. Therefore, on merge, the application will update. To update the spec of the application, first get the application id with doctl apps list, then simply run doctl apps update <app id> --spec .do/app.yaml.

Kubernetes

More to come..

⚙️ Implementation

Database

Postgres

There are 2 databases available, postgres and mongo. To ensure your developers don't get into any trouble while installing those, they are already pre-configured with docker-compose.yml files.

By default, the project uses postgres. If this is what you want, you're good to go; everything will work out of the box.

Migrations

By default, the automatic synchronization is activated between your models and the database. This means that making changes on your models will be automatically reflected on your database schemas. If you would like to control your migrations manually, you can do so by setting synchronize to false in orm-config.ts file.

Generate migration from your modified schemas:

npm run typeorm -- migration:generate -n {MIGRATION_NAME}

This will check the difference between models for your defined entities and your database schemas. If it finds changes, it will generate the appropriate migration scripts.

Run all pending migrations:

npm run typeorm -- migration:run

To get all the information on migrations, consult typeorm documentation.

Mongo [NOT RECOMMENDED]

If you would like to use mongodb, even though it is absolutely not recommended because it currently doesn't work well with typeorm, you can still do that by updating the connection info under ./apps/api/src/config/configuration.ts. You simply need to replace type: "postgres" with type: "mongo".

Data seeding

If you want your database to be pre-populated with that, it is very easy to do so. For postgres add your sql statements to apps/database/postgres/init.sql file. For mongo add your mongo statements to apps/database/mongo/mongo-entrypoint/seed-data.js file.

Backend

We are using cutting edge technologies to ensure that you get the best development experience one could hope for. To communicate with the database, we make use of the great typeorm. We use the code-first approach, which means defining your models will also represent your tables in your database. Here is an example:

import { Column, Entity } from "typeorm"
import { RootEntity } from "./root.entity"
import { MinLength } from "class-validator"

@Entity()
export class Todo extends RootEntity {
  @Column()
  @MinLength(5, { always: true })
  text: string
}

To serve your API requests, we make use of nest alongside with fastify to ensure blazing fast performance.

To reduce the boilerplate commonly found around creating a new entity, we are using the nestjsx/crud plugin that will generate all necessary routes for CRUD operations.

Here is an example from our todo app:

import { Controller } from "@nestjs/common"
import { Crud, CrudController } from "@nestjsx/crud"
import { Todo } from "@stator/models"

import { TodosService } from "./todos.service"

@Crud({ model: { type: Todo } })
@Controller("todos")
export class TodosController implements CrudController<Todo> {
  constructor(public service: TodosService) {}
}

Of course, you're probably wondering if this actually works. To convince you, we have implemented integration tests that perform real requests using supertest.

Can I view the generated endpoints? Well, of course, you can!

We now have generated swagger documentation that is viewable with the beautiful redoc.

Once you navigate to localhost:3333, you will see this:

redoc

Frontend

For our webapp, we're using the very popular react alongside redux-toolkit and react-router. We highly recommend that you use function components as demonstrated in the example.

To further reduce the boilerplate necessary for redux-toolkit we provide you with a thunkFactory which allows you to generate all actions needed for a CRUD endpoint.

Here is how you use it:

import { Todo } from "@stator/models"

import { thunkFactory } from "../utils/thunkFactory"

export const todoThunks = {
  ...thunkFactory<Todo>("/todos"),
}

We also provide a sliceReducerFactory that will generate the required reducers for the thunks you just created.

Here is how you use it:

import { Slice, createSlice } from "@reduxjs/toolkit"
import { Todo } from "@stator/models"

import { sliceReducerFactory } from "../utils/sliceReducerFactory"
import { SliceState, getInitialSliceState } from "../utils/SliceState"
import { todoThunks } from "./todos.thunk"

export interface TodoState extends SliceState<Todo> {}

export const todoSlice: Slice = createSlice({
  name: "todos",
  initialState: getInitialSliceState<TodoState, Todo>(),
  reducers: {},
  extraReducers: {
    ...sliceReducerFactory<Todo, TodoState>(todoThunks),
  },
})

As you can see, everything is typed adequately. Thus you will get auto-completion when developing.

Now let's say we want to fetch all our todos from our API, we can simply do this:

dispatch(todoThunks.getAll())

While the API is processing, we would like to add a loading. That is very easy because our thunkFactory handles all of this for us. You can access the loading status like this:

todoState.status.getAll.loading

For a complete example of CRUD operations, consult the app.tsx file.

In our example, we are using material-ui, but you could replace that with any other framework.

We also use axios to simplify our requests handling as it works very well with TypeScript.

General

We strongly believe that typing helps create a more robust program; thus, we use TypeScript.

To facilitate and optimize the usage of the monorepo, we make use of NX.

eslint enforces excellent standards, and prettier helps you apply them.

Commit messages must abide to those guidelines. If you need help following them, simply run npm run commit and you will be prompted with an interactive menu.

File and directory names are enforced by the custom made enforce-file-folder-naming-convention.ts.

Branch names are enforced before you even commit to ensure everyone adopts the same standard: {issue-number}-{branch-work-title-kebab-case}.

For end to end testing, we use the notorious cypress.

We also have a pre-built CI toolkit for you that will build and run the tests.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].