Skip to content

lhpaul/node-server-monorepo-starter

Repository files navigation

Monorepo Starter

This repository provides a robust foundation for developing a server-side application with a well-structured domain architecture.

This starter template is designed to be cloud platform and database independent, giving you the flexibility to choose your preferred infrastructure. For specialized implementations tailored to specific cloud providers, explore these extensions:

What's Inside?

This monorepo includes the following packages and applications:

Apps and Packages

  • internal-api: A Fastify application that provides a REST API and MCP server implementation. Designed for server-to-server communication with authentication via API keys or service accounts. Ideally it should be used in a internal network to ensure secure data transmission.
  • public-api: A Fastify application that provides a REST API implementation. Designed for secure internet-facing access with robust authentication and authorization protocols such as OIDC.
  • @repo/configs: Shared configuration files for ESLint, Jest, Prettier and TypeScript to ensure consistent code quality and style across all packages.
  • @repo/fastify: Shared Fastify utilities and plugins providing common server functionality, middleware, and helper methods.
  • @repo/shared: Shared business logic including domain models, services, interfaces and utilities used across all applications.

Development Tools

This monorepo comes pre-configured with essential development tools:

  • PNPM Fast, disk space efficient package manager.
  • Turborepo for efficient monorepo management and shared library handling.
  • TypeScript for robust type checking.
  • ESLint for code quality and consistency.
  • Prettier for automated code formatting.

Project Structure

.vscode/                   # VS Code workspace settings and configurations
apps/                      # Application source codes
contexts/                  # Documentation for developers and vibe coding to be used as context.
packages/                  # Shared packages and libraries
.gitignore                 # Git ignore rules for the project
.lintstagedrc.json         # Lint-staged configuration for pre-commit hooks
.markdownlint.json         # Markdown linting rules
.monorepo.code-workspace   # VS Code workspace configuration
package.json               # Root package.json for workspace configuration
pnpm-lock.yaml             # PNPM lock file for dependency versioning
pnpm-workspace.yaml        # PNPM workspace configuration
PROMPTS.md                 # AI prompt templates for development assistance
TODOs.md                   # Project roadmap and pending tasks
turbo.json                 # Turborepo configuration file

Getting Started

Setup

Prerequisites

Before you begin, ensure you have the following installed:

  1. Node.js version 22 (we recommend using nvm for version management)

  2. pnpm package manager.

  3. Turborepo CLI globally installed:

    pnpm install turbo --global

Installation

Install all repository dependencies by running:

pnpm install

Build

The build process will create optimized production bundles in the dist directory of each package.

To build all applications and packages in the monorepo:

# Build for production (with optimizations)
pnpm build

You can also build individual packages or applications by navigating to their respective directories:

# Example: Building a shared package
cd packages/shared
pnpm run build

# Example: Building a specific application
cd apps/public-api
pnpm run build

Development

This project contains multiple applications that can be run independently. For development, we use development builds that support hot-reloading and provide better debugging capabilities.

To start development, choose one of the following applications:

Internal API

pnpm run dev:internal-api

Public API

pnpm run dev:public-api

Note: Each application may require specific environment variables to function properly. Check the .env.example file in each application's directory and create a .env file with the required variables before starting the development server.

Testing

The project uses Jest as the testing framework. Here's how to run tests:

Running All Tests

To run tests across all apps and packages from the root directory:

pnpm run test

Running Specific Tests

To run tests for a specific app or package:

  1. Navigate to the target directory:
cd packages/shared  # or any other package/app directory
  1. Run the tests:
pnpm run test

Test Coverage

Each package and app generates test coverage reports. To view detailed coverage information:

  1. Navigate to the package/app directory
  2. Open coverage/lcov-report/index.html in your browser

Project Conventions

Before starting a new development, please review the [Project Conventions] documentation inside the /contexts folder. Following these guidelines helps ensure consistency, maintainability, and smoother code reviews during Pull Requests.

Additional Resources

Explore more Turborepo features:

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request from your branch to main.

License

This project is licensed under the MIT License.

Contact

For questions or feedback, please contact lhpaul11@gmail.com.

About

Repository to be used as starting point for a server composed by multiple independent modules/apps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors