Skip to content

Commit

Permalink
feat: move and fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
BoscoDomingo committed Nov 9, 2024
1 parent 0c860ff commit 966ca4a
Show file tree
Hide file tree
Showing 40 changed files with 911 additions and 913 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NODE_COMPILE_CACHE = /tmp/node-cache
NODE_COMPILE_CACHE = /tmp/node-cache
PORT = 8080
3 changes: 3 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_COMPILE_CACHE = /tmp/node-cache
PORT = 8080
NODE_ENV=test
84 changes: 42 additions & 42 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
name: test

on: push

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: latest

- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"

# Alternative
# - name: Cache node modules
# uses: actions/cache@v3
# env:
# cache-name: cache-node-modules
# with:
# path: ~/.pnpm-store
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-

- name: Install Dependencies
run: pnpm i --frozen-lockfile

- name: Build
run: pnpm build

- name: Test
run: pnpm test
name: test

on: push

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: latest

- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"

# Alternative
# - name: Cache node modules
# uses: actions/cache@v3
# env:
# cache-name: cache-node-modules
# with:
# path: ~/.pnpm-store
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-

- name: Install Dependencies
run: pnpm i --frozen-lockfile

- name: Build
run: pnpm build

- name: Test
run: pnpm test
40 changes: 22 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# API keys and secrets
.env*
!.env.example

# Dependency directory
node_modules

# Ignore built ts files
dist
coverage

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
.vscode
# API keys and secrets
.env*
!.env.example
!.env.test

# Dependency directory
node_modules

# Ignore built ts files
dist
coverage

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
.vscode

logs
*.log
125 changes: 63 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
# TypeScript | Node.js Bootstrap (template) for DDD/Hexagonal Architecture

This repository is intended to serve as a starting point if you want to bootstrap a more complexTypeScript project.

⚠️ It is meant for larger use cases where you need the extra complexity. However, it still has its shortcomings:
- No proper DI framework/container/tool (just simple DI via constructor injection)
- Logging tied to the framework (Fastify)
- Ready for events, but not yet implemented

If these issues don't matter for your intended use, or you know how to fix them, this will be a fast way to run a quick script or program.
If you're looking for a simpler setup, check out my [TypeScript API Template](https://github.com/BoscoDomingo/typescript-api-skeleton) or my [TypeScript Simple Setup](https://github.com/BoscoDomingo/typescript-skeleton)

It is opinionated, but easily adaptable to your needs and preferences. Check out below for more details.

## Features

- [Pure DI](https://blog.ploeh.dk/2014/06/10/pure-di/). If you prefer using containers, check out:
- [tsyringe](https://github.com/microsoft/tsyringe)
- [typescript-ioc](https://www.npmjs.com/package/typescript-ioc)
- [TypeDI](https://github.com/typestack/typedi)
- [NestJS](https://nestjs.com/)
- [InversifyJS](https://inversify.io/)
- [Awilix](https://github.com/jeffijoe/awilix)
- If you prefer mocking dependencies (no DI) use [proxyquire](https://www.npmjs.com/package/proxyquire)
- [TypeScript](https://www.typescriptlang.org/)
- Find other `tsconfig.json` options [here](https://github.com/tsconfig/bases#centralized-recommendations-for-tsconfig-bases)
- [tsx](https://tsx.is/) when running TS files directly
- [pnpm](https://pnpm.io/) for package management
- [Biome](https://biomejs.dev/) for formatting and linting.
- [Node Test Runner](https://nodejs.org/api/test.html) for testing.
- [Fastify](https://www.fastify.dev/) for the server with multiple plugins:
- [cors](https://github.com/fastify/fastify-cors)
- [helmet](https://github.com/fastify/fastify-helmet)
- [rate-limit](https://github.com/fastify/fastify-rate-limit)
- [sensible](https://github.com/fastify/fastify-sensible)
- [type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox)
- [swagger](https://github.com/fastify/fastify-swagger) - Commented
- [swagger-ui](https://github.com/fastify/fastify-swagger-ui) - Commented
- [GitHub Action workflows](https://github.com/features/actions) set up to run build, tests and formatting (with an automatic commit) on push.

## Local dev

You'll need to duplicate the `.env.example` file and rename it to `.env` and to `.env.test` first.

| Action | Command | Description |
| -------------------- | ------------ | ------------------------------------------------ |
| Install dependencies | `pnpm i` | Installs the necessary dependencies |
| Compile | `pnpm build` | Transpiles TS into JS |
| Run | `pnpm start` | Runs the compiled JS |
| Dev | `pnpm dev` | Runs the TypeScript code and watches for changes |

## Testing (Node Test Runner)

| Action | Command | Description |
| ------ | ----------- | ------------------ |
| Test | `pnpm test` | Runs all the tests |

## Formatting (Biome)
| Action | Command | Description |
| ------ | ------------- | --------------------------------------- |
| Format | `pnpm format` | Ensures code follows style guides |
| Lint | `pnpm lint` | Runs the linter and points out mistakes |
# TypeScript | Node.js Bootstrap (template) for DDD/Hexagonal Architecture

This repository is intended to serve as a starting point if you want to bootstrap a more complexTypeScript project.

⚠️ It is meant for larger use cases where you need the extra complexity. However, it still has its shortcomings:
- No proper DI framework/container/tool (just simple DI via constructor injection)
- Logging tied to the framework (Fastify)
- Ready for events, but not yet implemented
- Criteria pattern with SQL translation coming soon™️

If these issues don't matter for your intended use, or you know how to fix them, this will be a fast way to run a quick script or program.
If you're looking for a simpler setup, check out my [TypeScript API Template](https://github.com/BoscoDomingo/typescript-api-skeleton) or my [TypeScript Simple Setup](https://github.com/BoscoDomingo/typescript-skeleton)

It is opinionated, but easily adaptable to your needs and preferences. Check out below for more details.

## Features

- [Pure DI](https://blog.ploeh.dk/2014/06/10/pure-di/). If you prefer using containers, check out:
- [tsyringe](https://github.com/microsoft/tsyringe)
- [typescript-ioc](https://www.npmjs.com/package/typescript-ioc)
- [TypeDI](https://github.com/typestack/typedi)
- [NestJS](https://nestjs.com/)
- [InversifyJS](https://inversify.io/)
- [Awilix](https://github.com/jeffijoe/awilix)
- If you prefer mocking dependencies (no DI) use [proxyquire](https://www.npmjs.com/package/proxyquire)
- [TypeScript](https://www.typescriptlang.org/)
- Find other `tsconfig.json` options [here](https://github.com/tsconfig/bases#centralized-recommendations-for-tsconfig-bases)
- [tsx](https://tsx.is/) when running TS files directly
- [pnpm](https://pnpm.io/) for package management
- [Biome](https://biomejs.dev/) for formatting and linting.
- [Node Test Runner](https://nodejs.org/api/test.html) for testing.
- [Fastify](https://www.fastify.dev/) for the server with multiple plugins:
- [cors](https://github.com/fastify/fastify-cors)
- [helmet](https://github.com/fastify/fastify-helmet)
- [rate-limit](https://github.com/fastify/fastify-rate-limit)
- [sensible](https://github.com/fastify/fastify-sensible)
- [type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox)
- [swagger](https://github.com/fastify/fastify-swagger) - Commented
- [swagger-ui](https://github.com/fastify/fastify-swagger-ui) - Commented
- [GitHub Action workflows](https://github.com/features/actions) set up to run build, tests and formatting (with an automatic commit) on push.

## Local dev

You'll need to duplicate the `.env.example` file and rename it to `.env` and to `.env.test` first.

| Action | Command | Description |
| -------------------- | ------------ | ------------------------------------------------ |
| Install dependencies | `pnpm i` | Installs the necessary dependencies |
| Compile | `pnpm build` | Transpiles TS into JS |
| Run | `pnpm start` | Runs the compiled JS |
| Dev | `pnpm dev` | Runs the TypeScript code and watches for changes |

## Testing (Node Test Runner)

| Action | Command | Description |
| ------ | ----------- | ------------------ |
| Test | `pnpm test` | Runs all the tests |

## Formatting (Biome)
| Action | Command | Description |
| ------ | ------------- | --------------------------------------- |
| Format | `pnpm format` | Ensures code follows style guides |
| Lint | `pnpm lint` | Runs the linter and points out mistakes |
Loading

0 comments on commit 966ca4a

Please sign in to comment.