feat: experiment with nestjs and plugin system, separate backend and frontend

Signed-off-by: Jo <jo@thevoid.cafe>
This commit is contained in:
Jo 2024-06-27 18:21:33 +02:00
parent ff07220058
commit 8eeddf4d25
32 changed files with 485 additions and 5 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.devenv
.devenv.flake.nix
.idea

8
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/Engine.iml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
.idea/discord.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="ASK" />
<option name="description" value="" />
</component>
</project>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="-32c605a5:19059151b4d:-7da1" />
</MTProjectMetadataState>
</option>
</component>
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Engine.iml" filepath="$PROJECT_DIR$/.idea/Engine.iml" />
</modules>
</component>
</project>

19
.idea/php.xml Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project>

7
.idea/vcs.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/engine" vcs="Git" />
</component>
</project>

View file

@ -1,5 +0,0 @@
# Engine
The Void Engine :3 (very cool name, and stuff)
(This is for a secret project I'm working on :3)

58
apps/backend/README.md Normal file
View file

@ -0,0 +1,58 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
<p align="center">A progressive <a href="https://bun.sh" target="_blank">Bun</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript repository with Bun.
## Installation
```bash
$ bun install
```
## Running the app
```bash
# watch mode
$ bun run start:dev
# production mode
$ bun run start:prod
```
## Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
- Bun adaption - [@letstri](https://github.com/letstri)
## License
Nest is [MIT licensed](LICENSE).

BIN
apps/backend/bun.lockb Executable file

Binary file not shown.

View file

@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}

36
apps/backend/package.json Normal file
View file

@ -0,0 +1,36 @@
{
"name": "homespace-backend",
"version": "0.0.1",
"author": "Johannes Reckers",
"type": "module",
"license": "MIT",
"scripts": {
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start:dev": "bun --watch ./src/main.ts",
"start:debug": "nest start --debug --watch",
"start:prod": "bun ./src/main.ts",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.1",
"mongodb": "^6.7.0",
"pg": "^8.11.3",
"typeorm": "^0.3.17"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@types/express": "^4.17.17",
"@types/node": "^20.9.4",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.0",
"typescript": "^5.1.3"
}
}

View file

@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
createUser() {
return this.appService.createUser();
}
}

View file

@ -0,0 +1,27 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { User } from './entities/user.entity';
const userForFeature = TypeOrmModule.forFeature([User]);
@Module({
imports: [
TypeOrmModule.forRoot({
type: "mongodb",
host: "localhost",
port: 27017,
username: "homespace",
password: "homespace",
database: "homespace",
synchronize: true,
logging: false,
entities: [User],
}),
userForFeature,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}

View file

@ -0,0 +1,23 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import type { Repository } from 'typeorm';
import { User } from './entities/user.entity';
@Injectable()
export class AppService {
constructor(
@InjectRepository(User)
private readonly userRepository: Repository<User>,
) {}
async createUser() {
const user = this.userRepository.create({
firstName: 'Johannes',
lastName: 'Reckers',
age: 18,
});
const entity = await this.userRepository.save(user);
return entity;
}
}

View file

@ -0,0 +1,3 @@
export interface Plugin {
register(): void
}

View file

@ -0,0 +1,15 @@
import { Injectable, OnModuleInit } from "@nestjs/common";
import { type Plugin } from './plugin.interface';
@Injectable()
export class PluginService implements OnModuleInit {
private plugins: Plugin[] = [];
public registerPlugin(plugin: Plugin) {
this.plugins.push(plugin);
}
onModuleInit() {
this.plugins.forEach((plugin) => plugin.register());
}
}

View file

@ -0,0 +1,16 @@
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
age: number;
}

14
apps/backend/src/main.ts Normal file
View file

@ -0,0 +1,14 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { PluginService } from './common/plugins/plugin.service';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const pluginService = app.get(PluginService);
pluginService.onModuleInit(); // Initialize plugins
await app.listen(4300);
}
bootstrap();

View file

@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}

View file

@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}

View file

@ -0,0 +1,4 @@
{
"name": "homespace-frontend",
"version": "0.0.1"
}

View file

BIN
bun.lockb Executable file

Binary file not shown.

View file

@ -0,0 +1 @@
// Todo: create example plugin

View file

@ -0,0 +1,7 @@
{
"name": "blmedia-example",
"version": "0.0.1",
"workspaces": [
"apps/*"
]
}

122
devenv.lock Normal file
View file

@ -0,0 +1,122 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1719323427,
"owner": "cachix",
"repo": "devenv",
"rev": "f810f8d8cb4e674d7e635107510bcbbabaa755a3",
"treeHash": "165ad401b1788985cdaa07483f9ed110cc848958",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"treeHash": "6d9f1f7ca0faf1bc2eeb397c78a49623260d3412",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1719234068,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "90bd1b26e23760742fdcb6152369919098f05417",
"treeHash": "c87db871f241e42f31db9fb9936b61cb60f127ae",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1719259945,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07",
"treeHash": "1a76ff89a9d4017b48abbb1bad8837b35d604ffc",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
}
},
"root": "root",
"version": 7
}

15
devenv.nix Normal file
View file

@ -0,0 +1,15 @@
{ pkgs, config, ... }: {
env.GREET = "Welcome to your dev environment <3\nNestJS + Bun";
packages = [
pkgs.nest-cli
pkgs.bun
];
enterShell = ''
echo "Installing packages"
bun i
clear
echo "${config.env.GREET}"
'';
}

22
docker-compose.yml Normal file
View file

@ -0,0 +1,22 @@
services:
homespace:
build:
context: ./
dockerfile: Dockerfile
ports:
- "4300:4300"
restart: always
mongo:
image: mongo
container_name: homespace-db
ports:
- "27017:27017"
restart: always
logging:
driver: "json-file"
options:
max-size: 1g
environment:
- MONGO_INITDB_ROOT_USERNAME=homespace
- MONGO_INITDB_ROOT_PASSWORD=homespace

7
package.json Normal file
View file

@ -0,0 +1,7 @@
{
"name": "homespace",
"private": true,
"workspaces": [
"apps/*"
]
}