Skip to content

💻 A full-stack, dual-db code snippet manager. Purposefully overengineered for demonstration purposes.

Notifications You must be signed in to change notification settings

peter-gy/snip-man

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SnipMan

This project was generated using Nx.

NX Logo

🔎 Smart, Fast and Extensible Build System

Table of contents

One-liner App Start

docker build . -t snip-man:nx-base && docker-compose up --build

The app start might take up to 10-15 minutes based on your internet connection and your machine's performance. The system will be fully functional, once snip-man-prisma-migrate exits with code 0. Please note that it is possible that snip-man-prisma-migrate will exit with code 1 first, indicating an error, but this will be the case iff the mongo replica set snip-man-mongo starts up too slow. The system will self-heal automatically, you should just wait until you see snip-man-prisma-migrate exited with code 0 in your logs.

You will be able to access the app via https://localhost. You will need to accept the self-signed certificates, or ignore them in your browser. Both of the urls below need to be accessible by your browser:

  • https://localhost
  • https://localhost:8443/api-docs/

Development Environment

The development environment of this project is fully dockerized via Dockerfile.dev and docker-compose.dev.yml. The setup makes it possible to edit the source files locally and run the nx commands inside a docker container. In addition, the database services can be also managed via docker-compose.

Steps to start the development environment:

  1. Build and run the services: make dev-up
  2. Start Nx services of your choice (scripts in package.json might be helpful)

Note that the repository root gets mounted bi-directionally into the /usr/snip-man-dev/ directory of the nx-dev service, therefore file-system changes made on the host will be immediately present inside the container, and vice-versa.

The web and server components can be served in development mode at once by executing npm run project:serve.

Truly Local Development

Install node modules:

npm install

Start the database instances with Docker and serve the project from your local machine:

make dev-up-local

The following services will be started:

  • postgres: localhost:15432
  • mongo: localhost:37017
  • server: localhost:3333
  • web: localhost:4200

Production Build & Run

The system can be built using Docker only:

  1. Build the base nx image:
docker build . -t snip-man:nx-base

Note that this base image containing the whole repository source is necessary for the build to succeed, as nx needs access to the whole monorepo to do shared module transpilation and more advanced dependency-graph based dependency resolution.

  1. Build the Docker services:
docker-compose build

The full system can be started by executing:

docker-compose up

Convenience command to execute the steps above at once:

Using pure bash:

docker build . -t snip-man:nx-base && docker-compose build && docker-compose up -d

Using make:

make prod-up

Accessing App Components

Only the web and server components are exposed publicly. They can be accessed both with and without using SSL. Please note that self-signed SSL certificates are generated upon container startup, hence your browser will complain about security risks when visiting any of the below HTTPS links.

Please note that it is necessary to ignore SSL certificate errors with browsers when visiting the above links.

  • macOS, Chromium: open /Applications/Chromium.app --args --ignore-certificate-errors
  • Windows, Chrome: using flag --ignore-certificate-errors

helper

Working with nx

Serving Project web

In order to serve the Next application, residing in ./apps/web, execute:

npx nx run web:serve

The app should be accessible under http://localhost:4200.

Serving Project server

In order to serve the Nest application, residing in ./apps/server, execute:

npx nx run server:serve

The app should be accessible under http://localhost:3333/api.

Parallel Serve

In order to execute both the Next and Nest applications, execute:

npx nx run-many --target=serve --projects=web,server

Formatting the Whole Project

The whole project source code can be formatted by executing:

npx nx format:write

Understand your workspace

Run nx graph to see a diagram of the dependencies of your projects.

Further help

Visit the Nx Documentation to learn more.

☁ Nx Cloud

Distributed Computation Caching & Distributed Task Execution

NX Cloud Card

Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times. Even teams that are new to Nx can connect to Nx Cloud and start saving time instantly.

Teams using Nx gain the advantage of building full-stack applications with their preferred framework alongside Nx’s advanced code generation and project dependency graph, plus a unified experience for both frontend and backend developers.

Visit Nx Cloud to learn more.

Working With Prisma

Useful links

Generating Code

Generate TypeScript clients:

npm run generate:prisma

Generate SQL:

npm run migrate:prisma