Restrucure consumer + monorepo

This commit is contained in:
Emily
2024-11-15 23:36:40 +01:00
parent 5ac43dec6b
commit 41037a01a1
25 changed files with 11658 additions and 1479 deletions

View File

@@ -2,15 +2,18 @@ module.exports = {
apps: [ apps: [
{ {
name: 'consumer', name: 'consumer',
exec_mode: 'fork', exec_mode: 'cluster',
instances: '2',
script: './dist/consumer/src/index.js', script: './dist/consumer/src/index.js',
env: { env: {
MONGO_CONNECTION_STRING: "", EMAIL_SERVICE: '',
BREVO_API_KEY: '',
MONGO_CONNECTION_STRING: '',
REDIS_URL: "", REDIS_URL: "",
REDIS_USERNAME: "", REDIS_USERNAME: "",
REDIS_PASSWORD: "", REDIS_PASSWORD: "",
STREAM_NAME: "", STREAM_NAME: "",
GROUP_NAME: "" GROUP_NAME: ''
} }
} }
] ]

View File

@@ -1,8 +1,5 @@
{ {
"dependencies": { "dependencies": {
"@getbrevo/brevo": "^2.2.0",
"mongoose": "^8.3.2",
"redis": "^4.6.14",
"ua-parser-js": "^1.0.37" "ua-parser-js": "^1.0.37"
}, },
"devDependencies": { "devDependencies": {
@@ -11,15 +8,15 @@
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"typescript": "^5.4.5" "typescript": "^5.4.5"
}, },
"name": "consumer-database", "name": "consumer",
"version": "1.0.0", "version": "1.0.0",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"dev": "node scripts/start_dev.js", "dev": "node scripts/start_dev.js",
"compile": "tsc", "compile": "tsc",
"build": "node ../scripts/build.js", "build_project": "node ../scripts/build.js",
"build": "npm run compile && npm run build_project && npm run create_db",
"create_db": "cd scripts && ts-node create_database.ts", "create_db": "cd scripts && ts-node create_database.ts",
"build_all": "npm run compile && npm run build && npm run create_db",
"docker-build": "docker build -t litlyx-consumer -f Dockerfile ../", "docker-build": "docker build -t litlyx-consumer -f Dockerfile ../",
"docker-inspect": "docker run -it litlyx-consumer sh" "docker-inspect": "docker run -it litlyx-consumer sh"
}, },

View File

@@ -1,9 +1,9 @@
import { ProjectModel } from "@schema/ProjectSchema"; import { ProjectModel } from "@schema/project/ProjectSchema";
import { UserModel } from "@schema/UserSchema"; import { UserModel } from "@schema/UserSchema";
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema"; import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
import EmailService from '@services/EmailService'; import EmailService from '@services/EmailService';
import { requireEnv } from "@utils/requireEnv"; import { requireEnv } from "@utils/requireEnv";
import { TProjectLimit } from "@schema/ProjectsLimits"; import { TProjectLimit } from "@schema/project/ProjectsLimits";
if (process.env.EMAIL_SERVICE) { if (process.env.EMAIL_SERVICE) {
EmailService.init(requireEnv('BREVO_API_KEY')); EmailService.init(requireEnv('BREVO_API_KEY'));

View File

@@ -1,6 +1,6 @@
import { ProjectLimitModel } from '@schema/ProjectsLimits'; import { ProjectLimitModel } from '@schema/project/ProjectsLimits';
import { MAX_LOG_LIMIT_PERCENT } from '@data/broker/Limits'; import { MAX_LOG_LIMIT_PERCENT } from '@data/broker/Limits';
import { checkLimitsForEmail } from './EmailController'; import { checkLimitsForEmail } from './EmailController';

View File

@@ -2,7 +2,7 @@
import { requireEnv } from '@utils/requireEnv'; import { requireEnv } from '@utils/requireEnv';
import { connectDatabase } from '@services/DatabaseService'; import { connectDatabase } from '@services/DatabaseService';
import { RedisStreamService } from '@services/RedisStreamService'; import { RedisStreamService } from '@services/RedisStreamService';
import { ProjectModel } from "@schema/ProjectSchema"; import { ProjectModel } from "@schema/project/ProjectSchema";
import { VisitModel } from "@schema/metrics/VisitSchema"; import { VisitModel } from "@schema/metrics/VisitSchema";
import { SessionModel } from "@schema/metrics/SessionSchema"; import { SessionModel } from "@schema/metrics/SessionSchema";
import { EventModel } from "@schema/metrics/EventSchema"; import { EventModel } from "@schema/metrics/EventSchema";
@@ -10,8 +10,9 @@ import { lookup } from './lookup';
import { UAParser } from 'ua-parser-js'; import { UAParser } from 'ua-parser-js';
import { checkLimits } from './LimitChecker'; import { checkLimits } from './LimitChecker';
import { ProjectLimitModel } from '@schema/ProjectsLimits'; import { ProjectLimitModel } from '@schema/project/ProjectsLimits';
import { ProjectCountModel } from '@schema/ProjectsCounts'; import { ProjectCountModel } from '@schema/project/ProjectsCounts';
connectDatabase(requireEnv('MONGO_CONNECTION_STRING')); connectDatabase(requireEnv('MONGO_CONNECTION_STRING'));
main(); main();

View File

@@ -1,27 +1,10 @@
{ {
"extends": "../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".",
"module": "NodeNext", "module": "NodeNext",
"target": "ESNext", "target": "ESNext",
"esModuleInterop": true, "esModuleInterop": true,
"outDir": "dist", "outDir": "dist"
"paths": {
"@schema/*": [
"../shared/schema/*"
],
"@services/*": [
"../shared/services/*"
],
"@data/*": [
"../shared/data/*"
],
"@functions/*": [
"../shared/functions/*"
],
"@utils/*": [
"../shared/utils/*"
]
}
}, },
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"

View File

@@ -34,8 +34,7 @@ const snapshots = computed(() => {
project_id: project.value?._id as any, project_id: project.value?._id as any,
_id: 'current_month' as any, _id: 'current_month' as any,
name: 'Current month', name: 'Current month',
from: fns.startOfMonth() from: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30),
new Date(Date.now() - 1000 * 60 * 60 * 24 * 30),
to: new Date(Date.now()), to: new Date(Date.now()),
color: '#00CC00' color: '#00CC00'
}, },

View File

@@ -1,5 +1,5 @@
{ {
"name": "nuxt-app", "name": "dashboard",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
@@ -14,29 +14,22 @@
"docker-run": "docker run -p 3000:3000 litlyx-dashboard" "docker-run": "docker run -p 3000:3000 litlyx-dashboard"
}, },
"dependencies": { "dependencies": {
"@getbrevo/brevo": "^2.2.0",
"@nuxtjs/tailwindcss": "^6.12.0", "@nuxtjs/tailwindcss": "^6.12.0",
"@supabase/supabase-js": "^2.45.4",
"chart.js": "^3.9.1", "chart.js": "^3.9.1",
"chartjs-chart-funnel": "^4.2.1", "chartjs-chart-funnel": "^4.2.1",
"chartjs-plugin-annotation": "^2.2.1", "chartjs-plugin-annotation": "^2.2.1",
"date-fns": "^3.6.0",
"dayjs": "^1.11.11",
"google-auth-library": "^9.10.0", "google-auth-library": "^9.10.0",
"googleapis": "^144.0.0", "googleapis": "^144.0.0",
"highlight.js": "^11.10.0", "highlight.js": "^11.10.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",
"litlyx-js": "^1.0.2",
"mongoose": "^8.3.2", "mongoose": "^8.3.2",
"nodemailer": "^6.9.13",
"nuxt": "^3.11.2", "nuxt": "^3.11.2",
"nuxt-vue3-google-signin": "^0.0.11", "nuxt-vue3-google-signin": "^0.0.11",
"openai": "^4.61.0", "openai": "^4.61.0",
"pdfkit": "^0.15.0", "pdfkit": "^0.15.0",
"primevue": "^3.52.0", "primevue": "^3.52.0",
"redis": "^4.6.13",
"sass": "^1.75.0", "sass": "^1.75.0",
"stripe": "^15.8.0", "stripe": "^17.3.1",
"v-calendar": "^3.1.2", "v-calendar": "^3.1.2",
"vue": "^3.4.21", "vue": "^3.4.21",
"vue-chart-3": "^3.1.8", "vue-chart-3": "^3.1.8",
@@ -47,12 +40,9 @@
"devDependencies": { "devDependencies": {
"@nuxt/ui": "^2.15.2", "@nuxt/ui": "^2.15.2",
"@types/jsonwebtoken": "^9.0.6", "@types/jsonwebtoken": "^9.0.6",
"@types/markdown-it": "^14.1.2",
"@types/nodemailer": "^6.4.15",
"@types/pdfkit": "^0.13.4", "@types/pdfkit": "^0.13.4",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"tailwindcss": "^3.4.3", "tailwindcss": "^3.4.3"
"vitest": "^1.6.0"
} }
} }

View File

@@ -24,23 +24,23 @@ import type { MetricsTimeline } from "~/server/api/metrics/[project_id]/timeline
// getEndMonth: data => 23.59 dell ulrimo giorno del mese // getEndMonth: data => 23.59 dell ulrimo giorno del mese
// Snapshot -> Current Week -> 11/11-00:00 - 17/11-23:59 // Snapshot -> Current Week -> 11/11-00:00 - 17/11-23:59
// Converti UTC UTENTE -> ISO // Converti UTC UTENTE -> ISO
// Backend -> Prendi dati da ISO_A a ISO_B // Backend -> Prendi dati da ISO_A a ISO_B
// Funzioni da creare // Funzioni da creare
// UTC TO ISO
// Converte utc -> Iso // Converte utc -> Iso
// UTC TO ISO
// UTC TO ISO Day // UTC TO ISO Day
// UTC TO ISO Month // UTC TO ISO Month
// UTC_IS_NEXT_DAY // UTC_IS_NEXT_DAY
// True se il giorno passa a quello successivo // True se il giorno passa a quello successivo
// UTC_IS_PREV_DAY // UTC_IS_PREV_DAY
// True se il giorno passa a quello precedente // True se il giorno passa a quello precedente

18
package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "litlyx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "Emily",
"license": "MIT",
"dependencies": {
"@getbrevo/brevo": "^2.2.0",
"mongoose": "^8.3.2",
"redis": "^4.7.0"
},
"devDependencies": {
"globs": "^0.1.4"
}
}

11567
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

6
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,6 @@
packages:
# - "dashboard"
- "producer"
- "consumer"
- "security"
- "shared"

2
shared/.gitignore vendored
View File

@@ -1,2 +0,0 @@
node_modules
package-lock.json

View File

@@ -1,11 +1,7 @@
{ {
"dependencies": { "name": "shared",
"@getbrevo/brevo": "^2.2.0", "version": "1.0.0",
"dayjs": "^1.11.11", "author": "Emily",
"mongoose": "^8.4.0", "license": "MIT",
"redis": "^4.6.14" "description": ""
},
"devDependencies": {
"@types/node": "^20.12.13"
}
} }

1362
shared/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +0,0 @@
import { model, Schema, Types } from 'mongoose';
export type TIntegrationsCredentials = {
_id: Schema.Types.ObjectId,
project_id: Schema.Types.ObjectId,
supabase_url: string,
supabase_anon_key: string,
supabase_service_role_key: string,
}
const IntegrationsCredentialsSchema = new Schema<TIntegrationsCredentials>({
project_id: { type: Types.ObjectId, index: 1 },
supabase_url: { type: String },
supabase_anon_key: { type: String },
supabase_service_role_key: { type: String },
});
export const IntegrationsCredentialsModel = model<TIntegrationsCredentials>('integrations_credentials', IntegrationsCredentialsSchema);

View File

@@ -1,28 +0,0 @@
import { model, Schema, Types } from 'mongoose';
export type TSupabaseIntegration = {
_id: Schema.Types.ObjectId,
project_id: Schema.Types.ObjectId,
name: string,
chart_type: string,
table_name: string,
xField: string,
yMode: string,
from: Date,
to: Date,
slice: string
}
const SupabaseIntegrationSchema = new Schema<TSupabaseIntegration>({
project_id: { type: Types.ObjectId, index: 1 },
name: { type: String, required: true },
chart_type: { type: String, required: true },
table_name: { type: String, required: true },
xField: { type: String, required: true },
yMode: { type: String, required: true },
from: { type: Date, required: true },
to: { type: Date, required: true },
slice: { type: String, required: true }
});
export const SupabaseIntegrationModel = model<TSupabaseIntegration>('supabase_integrations', SupabaseIntegrationSchema);

View File

@@ -1,10 +1,11 @@
{ {
"extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"module": "NodeNext", "module": "NodeNext",
"target": "ESNext" "target": "ESNext",
"composite": true
}, },
"include": ["**/*.ts"], "include": [
"exclude": [ "**/*.ts"
"node_modules" ],
]
} }

28
tsconfig.json Normal file
View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "nodenext",
"paths": {
"@schema/*": [
"./shared/schema/*"
],
"@services/*": [
"./shared/services/*"
],
"@data/*": [
"./shared/data/*"
],
"@functions/*": [
"./shared/functions/*"
],
"@utils/*": [
"./shared/utils/*"
]
},
"skipLibCheck": true
},
"exclude": [
"node_modules"
]
}