Skip to content

Commit

Permalink
refactor(domain): move the database schema next to application busine…
Browse files Browse the repository at this point in the history
…ss rules (#66)

* refactor(domain): move the database schema next to business rules

* chore(core): build the docker image without esbuild

* chore(core): optimize the docker build

* docs(app): create the changelog

* build(app): fix lint errors in the ci

* build(app): fix lint errors in the ci

* build(app): fix lint errors in the ci

* build(app): fix build errors in the ci
  • Loading branch information
tericcabrel committed May 22, 2024
1 parent f3928a7 commit 43e67ac
Show file tree
Hide file tree
Showing 118 changed files with 813 additions and 733 deletions.
8 changes: 8 additions & 0 deletions .changeset/itchy-cars-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@snipcode/domain": minor
"@snipcode/core": minor
"@snipcode/code-embed": patch
"@snipcode/embed": patch
---

Merge the database schema and the application business rules into a single package
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runs:
shell: bash
run: |
corepack enable
yarn set version 4.2.1
yarn set version 4.2.2
- name: Install projects dependencies
shell: bash
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ jobs:
run: sudo systemctl start mysql.service

- name: Run tests
run: yarn test
run: |
yarn prisma migrate dev --schema=packages/domain/prisma/schema.prisma
yarn test
version:
runs-on: ubuntu-latest
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
MYSQL_DATABASE: test
MYSQL_PORT: 3306
DATABASE_URL: mysql:https://root:[email protected]:3306/test
ADMIN_PASSWORD: admin_password
TEST_DATABASE_URL: mysql:https://root:[email protected]:3306/test
CONVERTKIT_API_KEY: api_key
CONVERTKIT_FORM_ID: form_id
outputs:
Expand All @@ -43,7 +43,9 @@ jobs:
run: sudo systemctl start mysql.service

- name: Run tests
run: yarn test
run: |
yarn prisma migrate dev --schema=packages/domain/prisma/schema.prisma
yarn test
preview-frontend:
runs-on: ubuntu-latest
Expand All @@ -56,7 +58,7 @@ jobs:
- name: Install Yarn 4
run: |
corepack enable
yarn set version 4.2.1
yarn set version 4.2.2
- name: Install Vercel CLI
run: npm install --global vercel@latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Yarn 4
run: |
corepack enable
yarn set version 4.2.1
yarn set version 4.2.2
- name: Install Vercel CLI
run: npm install --global vercel@latest
Expand Down
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
compressionLevel: mixed

defaultSemverRangePrefix: ""

httpRetry: 30

nodeLinker: node-modules
Expand Down
211 changes: 211 additions & 0 deletions apps/core/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

9 changes: 7 additions & 2 deletions apps/core/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"ignorePatterns": ["graphql.d.ts", "jest.config.ts"],
"root": true,
"extends": "../../.eslintrc.json",
"ignorePatterns": [
"graphql.d.ts",
"jest.config.ts"
],
"parserOptions": {
"ecmaVersion": 2021,
"ecmaVersion": 2023,
"sourceType": "module",
"project": "tsconfig.json"
}
Expand Down
42 changes: 31 additions & 11 deletions apps/core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,55 @@ RUN corepack enable && yarn set version berry

RUN yarn install

RUN npx prisma generate --schema=./packages/database/prisma/schema.prisma
RUN npx prisma generate --schema=./packages/domain/prisma/schema.prisma

WORKDIR /app/apps/core
RUN yarn build --filter=...@snipcode/core

RUN yarn build:prod

FROM node:20-alpine as schema-builder

WORKDIR /app

COPY --chown=node:node --from=builder /app/packages/database/prisma/schema.prisma ./app/prisma/
COPY --chown=node:node --from=builder /app/packages/domain/prisma/schema.prisma ./app/prisma/

# Generate the Prisma query engine for Node Alpine
RUN npx prisma generate --schema=./app/prisma/schema.prisma
RUN npx prisma generate --schema=./app/prisma/schema.prisma && \
rm ./node_modules/.prisma/client/libquery_engine-rhel-openssl-1.0.x.so.node
# https://www.prisma.io/docs/orm/reference/prisma-schema-reference#binarytargets-options

FROM node:20-alpine AS runner

FROM node:20-alpine AS snipcode
ARG APP_VERSION="1.0.0"

ENV NODE_ENV=production
ENV APP_VERSION=${APP_VERSION}

WORKDIR /app

COPY --chown=node:node --from=builder /app/apps/core/build/index.js ./
RUN corepack enable && yarn set version berry

COPY --chown=node:node --from=builder /app/package.json .
COPY --chown=node:node --from=builder /app/.yarnrc.yml .

COPY --chown=node:node --from=builder /app/apps/core/dist/src ./apps/core/src
COPY --chown=node:node --from=builder /app/apps/core/package.json ./apps/core

COPY --chown=node:node --from=builder /app/packages/domain/package.json ./packages/domain/package.json
COPY --chown=node:node --from=builder /app/packages/domain/dist ./packages/domain/dist

COPY --chown=node:node --from=builder /app/packages/utils/package.json ./packages/utils/package.json
COPY --chown=node:node --from=builder /app/packages/utils/dist ./packages/utils/dist

COPY --chown=node:node --from=builder /app/packages/embed/package.json ./packages/embed/package.json
COPY --chown=node:node --from=builder /app/packages/embed/dist ./packages/embed/dist

COPY --chown=node:node --from=builder /app/packages/logger/package.json ./packages/logger/package.json
COPY --chown=node:node --from=builder /app/packages/logger/dist ./packages/logger/dist

COPY --chown=node:node --from=schema-builder /app/node_modules/.prisma/client/schema.prisma ./
COPY --chown=node:node --from=schema-builder /app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node ./
RUN yarn workspaces focus --all --production && yarn cache clean --all

RUN yarn init -y
COPY --chown=node:node --from=schema-builder /app/node_modules/.prisma/client ./node_modules/.prisma/client

EXPOSE 7501

CMD ["node", "index.js"]
CMD ["node", "apps/core/src/index.js"]
8 changes: 4 additions & 4 deletions apps/core/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Snipcode Core

This is the core backend of Snipcode. All the business logic behind this application is implemented here.
This is the backend of Snipcode, containing the business logics related to .

## Tech Stack
* Node.js
* Typescript
* TypeScript
* GraphQL
* MySQL 8 through PlanetScale
* MySQL
* Prisma

## Prerequisites
Expand All @@ -15,13 +15,13 @@ Make sure you have this tools installed before running the project
* NPM or Yarn
* Docker
* AWS CLI v2
* MySQL 8 on PlanetScale

## Packages dependencies
We use Yarn workspace to create packages we can share with other applications.
These packages are located in the folder `packages`, so you might need to change the code of one or many packages to implement a feature.
Here are the packages used in this project:

* [@snipcode/database](../../packages/database)
* [@snipcode/domain](../../packages/domain)
* [@snipcode/logger](../../packages/logger)
* [@snipcode/utils](../../packages/utils)
Expand Down

0 comments on commit 43e67ac

Please sign in to comment.