Skip to content

Commit ded0256

Browse files
davwysthommannJohann Schwabe
authored
feat: Modularity & base modules (#334)
* Folder structure * Setup flox helpers * Add flox config * Basic module helpers * Add frontend structure * Update user, baseentity * Add module status checker * Module options helper * Cleanup * Cleanup * Clean up i18n * Even more cleanup * Structure, cleanup * Minor folder changes * Auth/role/copypasta setup * update PR template * Cleanup, routes * Router fix * Add helper * Module structure * more structure * Helpers * Cleanup, rm shared * Cleanup * Structure, module separation * More cleanup, roles * auth module cleanup * More cleanup¨ * add helpers * User & role module * Backend stuff * Add FloxWrapper * Make wrapper nice * Restrict module components * Fix errors * Test module config, merge * role cleanup * Add index for each module * Cleanup * Module docs, even more cleanup * Add CognitoUuid * Module config cleanup, logging * Config changes * Add generic i18n * Auth cleanup * Config * Fix auth dialogs, adapt to configuration * Add flox demo data * Signup demo flow, cleanup * Password cleanup * Fix auth * Add nice label to QR code * Auth cleanup * DB User creation * Add email verification code * Notification added * Auth flow changes, jwt not working yet * Fix JWT * Update router service * Cleanup, entity helpers * More resolver stuff * Fix userPool * Finally fix auth * switch anyRole for loggedIn * Cleanup * Add role * Role mgmt * User role checking * Improved testing setup, still has issues * Rename files, testing setup * More test changes * Handle password reset force * Error handling, general cleanup * Auto-login after confirming e-mail * Cleanup * Auto-relogin * Fix auth flow, cleanup * Cleanup * remove sample form * Add user mapper sample * Cleanup * SampleForm added * Folder structure * Add module readme, structure2 * Remove unused test * Import cleanup * Fix frontend floxconfig * More cleanup * Remove readme, moved to wiki * BaseEntity in frontend * PR changes * More cleanup * Add new application checklist * Testing, make rolesguard use service * Testing stuff * More test * Make linter happy * fix: tests in front- and backend (#337) * rm user entity import user module * fix user resolver tests * rm role validation in user entity * fix frontend tests * fix validateRole * PR fix * fix-PR * fixed import * fix backend imports * fix Daves banane * fix Daves banane * fix Daves banane * fix Daves banane * fix Daves banane Co-authored-by: thommann <[email protected]> Co-authored-by: Johann Schwabe <[email protected]>
1 parent d37f5ef commit ded0256

File tree

152 files changed

+3430
-2376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+3430
-2376
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SERVER_PORT=3000
22
FRONTEND_PORT=3001
3-
DB_DATABASE=app_db
3+
DB_DATABASE=app_db # TODO: Application specific
44
DB_USER=db_user
55
DB_PASSWORD=db_user_pass
66
DB_PORT=5432

.github/pull_request_template.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
### Before submitting your PR, ensure the following points:
2-
- [ ] Your PR goes to the appropriate branch (especially if working on a project)
3-
- [ ] Set appropriate labels
2+
- [ ] Your PR goes to the appropriate branch
43
- [ ] Add descriptive title (not just the branch name)
54
- [ ] Add a short description below
6-
- [ ] Your code does not add any ESLint errors (make sure you have **ESLint** enabled!)
7-
- [ ] Your code runs locally without any errors
85
- [ ] Your code follows the code conventions in the Wiki
96

10-
[//]: <> (For the future: **Note:** If you do not check these items, your pull request may be closed automatically.)
11-
127
### What does your PR change?
138

149
Add a short description here, e.g.
1510

1611
This PR adds:
1712
1. Some feature
18-
2. Another feature
19-
20-
And fixes a bug in component ABC.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# compiled output
22
/dist
33
/node_modules
4+
/backend/src/schema.gql
45

56
# Logs
67
logs

CHECKLIST.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Checklist for new Projects
2+
3+
When creating a new Flox project, you should (at the very least) complete the following changes that are
4+
application-specific:
5+
6+
## Root
7+
- [ ] Adapt `.env` with database name
8+
- [ ] Adapt `sonar-project.properties` with project key & organization
9+
10+
## Frontend
11+
- [ ] Adapt `frontend/.env` with app name, AWS user pool & e-mail sender
12+
- [ ] Set up `frontend/flox.config.js` according to your application's needs
13+
- [ ] In `frontend/src/data/ENUM.ts`, add the list of user roles within your application.
14+
- [ ] In `frontend/src/boot/router.ts`, add the application specific paths for each user role's default view
15+
- [ ] In `frontend/src/router/routes.ts`, add the application's routes
16+
- [ ] In `frontend/src/flox/modules/auth/services/AuthService.ts`, add any non-standard attributes your users need
17+
- [ ] In `frontend/src/flox/modules/auth/services/AuthService.ts`, in `loginSuccess()`, choose the correct route to redirect to.
18+
- [ ] In `frontend/src/flox/modules/auth/services/AuthService.ts`, in `loginSuccess()`, choose the correct route to redirect to.
19+
20+
## Backend
21+
- [ ] Adapt `backend/.env` with database name, AWS keys & buckets
22+
- [ ] Set up `backend/flox.config.js` according to your application's needs
23+
- [ ] In `backend/src/flox/modules/file/file.resolver.ts`, add appropriate guards for private files depending on your application

backend/.env

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
# Ports
12
SERVER_PORT=3000
2-
DB_DATABASE=app_db
3-
DB_USER=db_user
4-
DB_PASSWORD=db_user_pass
53
DB_PORT=5432
6-
DB_HOST=database
74
NOCODB_PORT=8000
85

6+
# Entities
97
ENTITIES=dist/**/**.entity.js
108

9+
# PostgreSQL Database Variables
1110
DATABASE_URL=pg://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}
11+
DB_DATABASE=app_db # TODO: Application specific
12+
DB_USER=db_user
13+
DB_PASSWORD=db_user_pass
14+
DB_HOST=database
1215

16+
# AWS Variables
1317
AWS_REGION=eu-central-1
14-
AWS_ACCESS_KEY_ID=AKIA5OA2ITKTMTHDDABH
15-
AWS_SECRET_ACCESS_KEY=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
16-
AWS_PUBLIC_BUCKET_NAME=bootstrap-public-test-bucket
17-
AWS_PRIVATE_BUCKET_NAME=bootstrap-private-test-bucket
18+
AWS_ACCESS_KEY_ID=TODO # TODO: Application specific
19+
AWS_SECRET_ACCESS_KEY=TODO # TODO: Application specific
20+
AWS_PUBLIC_BUCKET_NAME=TODO # TODO: Application specific
21+
AWS_PRIVATE_BUCKET_NAME=TODO # TODO: Application specific
22+
USER_POOL_ID=eu-central-1_TODO # TODO: Application specific

backend/docker-compose.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ services:
3232
volumes:
3333
- dbdata:/var/lib/postgresql/data
3434

35-
nocodb:
36-
container_name: nocodb
37-
image: nocodb/nocodb:latest
38-
networks:
39-
- webnet
40-
ports:
41-
- ${NOCODB_PORT}:8080
42-
volumes:
43-
- nocodbdata:/usr/app/data
44-
depends_on:
45-
- database
35+
# nocodb:
36+
# container_name: nocodb
37+
# image: nocodb/nocodb:latest
38+
# networks:
39+
# - webnet
40+
# ports:
41+
# - ${NOCODB_PORT}:8080
42+
# volumes:
43+
# - nocodbdata:/usr/app/data
44+
# depends_on:
45+
# - database
4646

4747
networks:
4848
webnet:

backend/flox.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
// Flox modules to enable
3+
modules: {
4+
auth: true,
5+
roles: true,
6+
file: true,
7+
sharing: false,
8+
},
9+
moduleOptions: {
10+
auth: {
11+
emailAsUsername: true,
12+
},
13+
roles: {
14+
roles: ['ADMIN', 'SUPERUSER', 'USER'],
15+
},
16+
},
17+
};

backend/jest.config.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
module.exports = {
22
moduleFileExtensions: ['vue', 'js', 'json', 'ts'],
3+
moduleDirectories: ['node_modules'],
4+
// moduleNameMapper: {
5+
// '^src/(.*)$': '<rootDir>/../src/$1',
6+
// },
37
rootDir: 'src',
48
testRegex: '.*\\.spec\\.ts$',
59
transform: {
610
'^.+\\.(t|j)s$': 'ts-jest',
711
},
812
collectCoverageFrom: ['**/*.{(t|j)s,vue}', '!**/node_modules/**'],
913
coverageDirectory: '<rootDir>/../reports/coverage',
10-
coverageReporters: [
14+
coverageReporters: [['lcov', { projectRoot: '../' }]],
15+
testEnvironment: 'node',
16+
reporters: [
17+
'default',
1118
[
12-
"lcov",
13-
{ projectRoot: "../" },
19+
'jest-sonar',
20+
{
21+
outputDirectory: 'reports',
22+
outputName: 'test-reporter.xml',
23+
reportedFilePath: 'relative',
24+
relativeRootDir: '../',
25+
},
1426
],
1527
],
16-
testEnvironment: 'node',
17-
reporters: ['default', ['jest-sonar', {
18-
outputDirectory: 'reports',
19-
outputName: 'test-reporter.xml',
20-
reportedFilePath: 'relative',
21-
relativeRootDir: '../',
22-
}]],
2328
};

backend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test:unit:watch": "jest --watch",
2121
"test:unit:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
2222
"test:e2e": "jest --config ./test/jest-e2e.json",
23-
"docker:dev": "docker-compose up -V --build"
23+
"docker:dev": "docker-compose up --build -V"
2424
},
2525
"dependencies": {
2626
"@aws-sdk/client-s3": "^3.41.0",

backend/src/app.module.ts

+16-32
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
import { Module } from '@nestjs/common';
22
import { GraphQLModule } from '@nestjs/graphql';
33
import { join } from 'path';
4-
import { UserModule } from './user/user.module';
54
import { TypeOrmModule } from '@nestjs/typeorm';
65
import { ConfigModule, ConfigService } from '@nestjs/config';
76
import configuration from './config/configuration';
8-
import { Context } from 'vm';
9-
import { JwtAuthGuard } from './auth/auth.guard';
10-
import { APP_GUARD } from '@nestjs/core';
11-
import { JwtStrategy } from './auth/jwt.strategy';
12-
import { ItemModule } from './item/item.module';
137
import * as Joi from 'joi';
14-
import { FileModule } from './file/file.module';
15-
import { RolesGuard } from './auth/roles.guard';
8+
import { floxModules, floxProviders } from './flox/flox';
169

1710
@Module({
1811
imports: [
1912
GraphQLModule.forRoot({
2013
playground: true,
21-
//services: [ApolloServerPluginLandingPageLocalDefault()], // Use Apollo Sandbox instead of graphql-playground
2214
debug: true,
2315
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
2416
sortSchema: true,
25-
//disableHealthCheck: true //set true if using multiple GraphQL endpoints in a single application with fastify
26-
installSubscriptionHandlers: true,
27-
subscriptions: {
28-
// Could also use graphql-ws instead of default (subscriptions-transport-ws)
29-
'subscriptions-transport-ws': {
30-
path: '/graphql-websocket',
31-
onConnect: (context: Context) => {
32-
console.log('Client connected to GraphQL Websocket!', context);
33-
},
34-
},
35-
},
3617
}),
3718
ConfigModule.forRoot({
3819
isGlobal: true,
@@ -71,20 +52,23 @@ import { RolesGuard } from './auth/roles.guard';
7152
}),
7253
inject: [ConfigService],
7354
}),
74-
UserModule,
75-
ItemModule,
76-
FileModule,
55+
// TypeOrmModule.forFeature([ TODO check if needed
56+
// // Entities for Flox modules
57+
// ...floxEntities(),
58+
// // Add any custom entities here
59+
// ]),
60+
// Flox modules
61+
...floxModules(),
62+
// Add any custom modules here
7763
],
7864
providers: [
79-
JwtStrategy,
80-
{
81-
provide: APP_GUARD,
82-
useClass: JwtAuthGuard,
83-
},
84-
{
85-
provide: APP_GUARD,
86-
useClass: RolesGuard,
87-
},
65+
// Flox module Providers
66+
...floxProviders(),
67+
// Add any other custom module providers here
8868
],
8969
})
70+
71+
/**
72+
* Main Module
73+
*/
9074
export class AppModule {}

backend/src/auth/authorization.decorator.ts

-23
This file was deleted.

backend/src/auth/roles.guard.ts

-66
This file was deleted.

backend/src/base-entity/entities/base-entity.entity.ts

-11
This file was deleted.

backend/src/config/configuration.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export default (): Config => ({
1212
},
1313
});
1414

15-
export class serverConfig {
15+
export class ServerConfig {
1616
port: number;
1717
}
1818

19-
export class databaseConfig {
19+
export class DatabaseConfig {
2020
host: string;
2121
port: string;
2222
username: string;
@@ -25,7 +25,7 @@ export class databaseConfig {
2525
}
2626

2727
export class Config {
28-
server: serverConfig;
28+
server: ServerConfig;
2929
entities: string;
30-
database: databaseConfig;
30+
database: DatabaseConfig;
3131
}

backend/src/flox/MODULES.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Flox Modules
2+
export enum MODULES {
3+
AUTH = 'auth',
4+
ROLES = 'roles',
5+
FILE = 'file',
6+
SHARING = 'sharing',
7+
}

0 commit comments

Comments
 (0)