├── .DS_Store ├── .gitignore ├── README.md └── client ├── config └── config.ini ├── package-lock.json ├── package.json ├── readme.md ├── src ├── index.ts └── infra │ ├── adapters │ └── controllers │ │ └── test.controller.ts │ ├── config │ └── index.ts │ ├── dependencies │ ├── container │ │ └── index.ts │ ├── dto │ │ └── dependencies.dto.ts │ └── factories │ │ ├── config.factory.ts │ │ ├── controller.factory.ts │ │ └── env.factory.ts │ ├── interfaces │ └── index.ts │ └── utils │ ├── captureControllers.ts │ ├── controller.ts │ ├── cpu.ts │ ├── env.ts │ └── logger.ts ├── tsconfig-build.json └── tsconfig.json /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ox18/DragonboundRe/15cd1b81093cd205d46103c5177e3835cf418fff/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | 132 | dist -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | REMAKE IN PROGRESS!! -------------------------------------------------------------------------------- /client/config/config.ini: -------------------------------------------------------------------------------- 1 | ; This comment is being ignored 2 | scope = global 3 | 4 | [app] 5 | port = 3000 -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "bin": "dist/index.js", 7 | "scripts": { 8 | "dev": "nodemon -L --quiet --watch ./src ./src/index.ts", 9 | "build": "rimraf dist && tsc -p tsconfig-build.json", 10 | "start": "node dist/index.js", 11 | "fetch": "git add . && git commit -m \"$MSG\" && git push", 12 | "pkg": "pkg -t node18-linux-x64 -o build/my-program ." 13 | }, 14 | "keywords": [], 15 | "author": "lnferno", 16 | "license": "ISC", 17 | "devDependencies": { 18 | "@types/express": "^4.17.21", 19 | "awilix": "^10.0.2", 20 | "express": "^4.19.2", 21 | "log4js": "^6.9.1", 22 | "nodemon": "^3.0.2", 23 | "pkg": "^5.8.1", 24 | "rimraf": "^5.0.0", 25 | "ts-node": "^10.9.1", 26 | "typescript": "^5.0.4" 27 | }, 28 | "_moduleAliases": { 29 | "@": "src" 30 | }, 31 | "dependencies": { 32 | "ini": "^4.1.2", 33 | "module-alias": "^2.2.3" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /client/readme.md: -------------------------------------------------------------------------------- 1 | - src/ 2 | - application/ 3 | - usecases/ # Aquí van los casos de uso de la aplicación 4 | - user/ 5 | - createUser.js 6 | - getUser.js 7 | - updateUser.js 8 | - deleteUser.js 9 | - services/ # Interfaces de servicios externos 10 | - emailService.js 11 | - paymentService.js 12 | - domain/ 13 | - entities/ # Aquí van las entidades del dominio 14 | - User.js 15 | - Product.js 16 | - repositories/ # Interfaces de repositorios 17 | - userRepository.js 18 | - productRepository.js 19 | - infrastructure/ 20 | - adapters/ # Adaptadores de la capa de infraestructura 21 | - controllers/ # Controladores HTTP 22 | - userController.js 23 | - databases/ # Implementaciones de bases de datos 24 | - mongodb.js 25 | - mysql.js 26 | - services/ # Implementaciones de servicios externos 27 | - emailService.js 28 | - paymentService.js 29 | - config/ # Configuración de la aplicación 30 | - index.js 31 | - middlewares/ # Middlewares de Express, etc. 32 | - authentication.js 33 | - logging.js 34 | - routes/ # Rutas de la API HTTP 35 | - userRoutes.js 36 | - utils/ # Utilidades compartidas 37 | - logger.js 38 | - validators.js -------------------------------------------------------------------------------- /client/src/index.ts: -------------------------------------------------------------------------------- 1 | import "module-alias/register"; 2 | import { configFactory } from "@/infra/dependencies/factories/config.factory"; 3 | import { env } from "./infra/dependencies/factories/env.factory"; 4 | (async () => { 5 | console.clear() 6 | await env.capture(); 7 | await configFactory().run(env.variables.config.app.port); 8 | })(); 9 | -------------------------------------------------------------------------------- /client/src/infra/adapters/controllers/test.controller.ts: -------------------------------------------------------------------------------- 1 | import { controllerFactory } from "@/infra/dependencies/factories/controller.factory"; 2 | 3 | const controller = controllerFactory().on(({ req, res, dependencies }) => { 4 | dependencies.logger.info("Test controller called"); 5 | }); 6 | 7 | export default controller; 8 | -------------------------------------------------------------------------------- /client/src/infra/config/index.ts: -------------------------------------------------------------------------------- 1 | import { DependenciesDTO } from "@/infra/dependencies/dto/dependencies.dto"; 2 | 3 | export default class Config { 4 | dependencies: DependenciesDTO; 5 | 6 | constructor(dependencies: DependenciesDTO) { 7 | this.dependencies = dependencies; 8 | } 9 | 10 | async run(port: number) { 11 | this.dependencies.logger.info(`Server is running on port ${port}`); 12 | this.dependencies.logger.debug("Compiled successfully!"); 13 | this.dependencies.logger.mark( 14 | "You can now call the server on the specified port" 15 | ); 16 | this.dependencies.logger.mark("Local: http://localhost:" + port); 17 | this.dependencies.logger.mark( 18 | "On Your Network: http://" + 19 | this.dependencies.cpu.captureIp() + 20 | ":" + 21 | port 22 | ); 23 | this.dependencies.logger.mark( 24 | "Note that the development build is not optimized." 25 | ); 26 | this.dependencies.logger.mark( 27 | "To create a production build, use npm run build." 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /client/src/infra/dependencies/container/index.ts: -------------------------------------------------------------------------------- 1 | import * as awilix from "awilix"; 2 | import { logger } from "@/infra/utils/logger"; 3 | import Config from "@/infra/config"; 4 | import { Controller } from "@/infra/utils/controller"; 5 | import { CaptureControllers } from "@/infra/utils/captureControllers"; 6 | import { Environment } from "@/infra/utils/env"; 7 | import { CPU } from "@/infra/utils/cpu"; 8 | 9 | export const container = awilix.createContainer({ 10 | injectionMode: awilix.InjectionMode.PROXY, 11 | }); 12 | 13 | const dependencies = { 14 | logger: awilix.asValue(logger), 15 | }; 16 | 17 | container.register({ 18 | ...dependencies, 19 | config: awilix.asClass(Config), 20 | controller: awilix.asClass(Controller), 21 | captureControllers: awilix.asClass(CaptureControllers).singleton(), 22 | env: awilix.asClass(Environment).singleton(), 23 | cpu: awilix.asClass(CPU).singleton(), 24 | }); 25 | -------------------------------------------------------------------------------- /client/src/infra/dependencies/dto/dependencies.dto.ts: -------------------------------------------------------------------------------- 1 | import { CaptureControllers } from "@/infra/utils/captureControllers"; 2 | import { CPU } from "@/infra/utils/cpu"; 3 | import { Environment } from "@/infra/utils/env"; 4 | import log4js from "log4js"; 5 | 6 | export type DependenciesDTO = { 7 | logger: log4js.Logger; 8 | captureControllers: CaptureControllers; 9 | env: Environment; 10 | cpu: CPU; 11 | }; 12 | -------------------------------------------------------------------------------- /client/src/infra/dependencies/factories/config.factory.ts: -------------------------------------------------------------------------------- 1 | import Config from "@/infra/config"; 2 | import { container } from "@/infra/dependencies/container"; 3 | 4 | export const configFactory = (): Config => { 5 | return container.resolve("config"); 6 | }; 7 | -------------------------------------------------------------------------------- /client/src/infra/dependencies/factories/controller.factory.ts: -------------------------------------------------------------------------------- 1 | import { container } from "@/infra/dependencies/container"; 2 | import { Controller } from "@/infra/utils/controller"; 3 | 4 | export const controllerFactory = (): Controller => { 5 | return container.resolve("controller"); 6 | }; 7 | -------------------------------------------------------------------------------- /client/src/infra/dependencies/factories/env.factory.ts: -------------------------------------------------------------------------------- 1 | import { container } from "@/infra/dependencies/container"; 2 | import { Environment } from "@/infra/utils/env"; 3 | 4 | export const env = container.resolve("env") as Environment; 5 | -------------------------------------------------------------------------------- /client/src/infra/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export interface EnvConfig { 2 | config: { 3 | app: { 4 | port: number; 5 | }; 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /client/src/infra/utils/captureControllers.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs"; 2 | import path from "path"; 3 | import { Controller } from "@/infra/utils/controller"; 4 | 5 | export class CaptureControllers { 6 | private controllers: Controller[] = []; 7 | 8 | async run(): Promise { 9 | const dir = path.join(__dirname, "../adapters/controllers"); 10 | 11 | return new Promise((resolve, reject) => { 12 | fs.readdir(dir, (err, files) => { 13 | if (err) { 14 | reject(err); 15 | } 16 | 17 | files.forEach((file) => { 18 | const controller = require(path.join(dir, file)); 19 | this.controllers.push(controller.default); 20 | }); 21 | 22 | resolve(this.controllers); 23 | }); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /client/src/infra/utils/controller.ts: -------------------------------------------------------------------------------- 1 | import { DependenciesDTO } from "../dependencies/dto/dependencies.dto"; 2 | import { NextFunction, Request, Response } from "express"; 3 | 4 | type ParamsHandle = { 5 | req: Request; 6 | res: Response; 7 | dependencies: DependenciesDTO; 8 | next: NextFunction; 9 | }; 10 | 11 | type ControllerHandle = (params: ParamsHandle) => Promise | void; 12 | 13 | export class Controller { 14 | dependencies: DependenciesDTO; 15 | handle: ControllerHandle; 16 | 17 | constructor(dependencies: DependenciesDTO) { 18 | this.dependencies = dependencies; 19 | } 20 | 21 | on(handle: ControllerHandle) { 22 | this.handle = handle; 23 | return this; 24 | } 25 | 26 | execute() { 27 | this.dependencies.logger.info("Controller called"); 28 | this.dependencies.logger.info(this.dependencies.env.variables.config.app.port) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /client/src/infra/utils/cpu.ts: -------------------------------------------------------------------------------- 1 | var address, 2 | os = require("os"), 3 | ifaces = os.networkInterfaces(); 4 | 5 | export class CPU { 6 | constructor() {} 7 | 8 | captureIp() { 9 | for (var dev in ifaces) { 10 | // ... and find the one that matches the criteria 11 | var iface = ifaces[dev].filter(function (details: any) { 12 | return details.family === 4 && details.internal === false; 13 | }); 14 | 15 | if (iface.length > 0) address = iface[0].address; 16 | } 17 | return address; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /client/src/infra/utils/env.ts: -------------------------------------------------------------------------------- 1 | import { readFile } from "node:fs/promises"; 2 | import { parse } from "ini"; 3 | import fs from "fs"; 4 | import { DependenciesDTO } from "../dependencies/dto/dependencies.dto"; 5 | import path from "path"; 6 | import { EnvConfig } from "../interfaces"; 7 | 8 | export class Environment { 9 | private dependencies: DependenciesDTO; 10 | variables: EnvConfig; 11 | 12 | constructor(dependencies: DependenciesDTO) { 13 | this.variables = {} as EnvConfig; 14 | this.dependencies = dependencies; 15 | } 16 | 17 | async capture(): Promise { 18 | this.dependencies.logger.info("Capturing environment variables"); 19 | const captured = await this.getKeys(); 20 | this.dependencies.logger.info("Environment variables captured"); 21 | this.variables = captured as unknown as EnvConfig; 22 | } 23 | private async getKeys(): Promise> { 24 | const dir = path.join(__dirname, "../../../config"); 25 | 26 | return new Promise((resolve, reject) => { 27 | fs.readdir(dir, async (err, filenames) => { 28 | if (err) { 29 | reject(err); 30 | } 31 | 32 | const variables = {}; 33 | 34 | const filesValid = filenames.filter((filename) => 35 | filename.endsWith(".ini") 36 | ); 37 | 38 | for (let file of filesValid) { 39 | const pathFile = path.join(dir, file); 40 | 41 | const r = await this.getDataFromFile( 42 | pathFile, 43 | file.replace(".ini", "") 44 | ); 45 | 46 | this.dependencies.logger.info( 47 | `Captured environment variable: ${r.key}` 48 | ); 49 | variables[r.key] = r.value; 50 | } 51 | resolve(variables); 52 | }); 53 | }); 54 | } 55 | 56 | async getDataFromFile( 57 | pathFile: string, 58 | filename: string 59 | ): Promise<{ 60 | key: string; 61 | value: Record; 62 | }> { 63 | const content = await readFile(pathFile, { 64 | encoding: "utf-8", 65 | }); 66 | 67 | const key = filename; 68 | const value = parse(content); 69 | 70 | return { key, value }; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /client/src/infra/utils/logger.ts: -------------------------------------------------------------------------------- 1 | import { getLogger, configure, Logger } from "log4js"; 2 | 3 | configure({ 4 | appenders: { 5 | out: { type: "stdout" }, 6 | file: { 7 | type: "file", 8 | filename: "logs/app.log", 9 | }, 10 | }, 11 | categories: { 12 | default: { appenders: ["out", "file"], level: "debug" }, 13 | }, 14 | }); 15 | 16 | const makeNamespace = (base: string): string => { 17 | return "[" + base + "]"; 18 | }; 19 | 20 | export const logger = getLogger(makeNamespace("app")) as Logger; 21 | -------------------------------------------------------------------------------- /client/tsconfig-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "module": "commonjs", 5 | "target": "es2019", 6 | "esModuleInterop": true, 7 | "sourceMap": false, 8 | "rootDir": "./src", 9 | "baseUrl": "src", 10 | "experimentalDecorators": true, 11 | "resolveJsonModule": true, 12 | "paths": { 13 | "@/*": ["*"] 14 | } 15 | }, 16 | "include": ["src"], 17 | "exclude": [] 18 | } 19 | --------------------------------------------------------------------------------