Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change folder structure to add Vertical Slice Architecture (VSA) #438

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ module.exports = {
},
overrides: [
{
files: ['src/!(presentation|types)/**/*.ts'],
files: ['src/!(contract|types)/**/*.ts'],
rules: {
'hexagonal-architecture/enforce': ['error']
}
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {

/* Bootstrap settings */
// Set initial config and enable jest-extended features
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.ts', 'jest-extended/all'],
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.ts'],

/* Global test settings */
// Automatically clear mock calls and instances between every test
Expand Down
674 changes: 337 additions & 337 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@
"dependencies": {
"@ngneat/falso": "^7.2.0",
"@prisma/client": "^5.10.2",
"@tsed/ajv": "^7.62.2",
"@tsed/common": "^7.62.2",
"@tsed/components-scan": "^7.62.2",
"@tsed/core": "^7.62.2",
"@tsed/di": "^7.62.2",
"@tsed/exceptions": "^7.62.2",
"@tsed/ioredis": "^7.62.2",
"@tsed/json-mapper": "^7.62.2",
"@tsed/ajv": "^7.62.3",
"@tsed/common": "^7.62.3",
"@tsed/components-scan": "^7.62.3",
"@tsed/core": "^7.62.3",
"@tsed/di": "^7.62.3",
"@tsed/exceptions": "^7.62.3",
"@tsed/ioredis": "^7.62.3",
"@tsed/json-mapper": "^7.62.3",
"@tsed/logger": "^6.6.3",
"@tsed/openspec": "^7.62.2",
"@tsed/platform-express": "^7.62.2",
"@tsed/prisma": "^7.62.2",
"@tsed/schema": "^7.62.2",
"@tsed/swagger": "^7.62.2",
"@tsed/openspec": "^7.62.3",
"@tsed/platform-express": "^7.62.3",
"@tsed/prisma": "^7.62.3",
"@tsed/schema": "^7.62.3",
"@tsed/swagger": "^7.62.3",
"ajv": "^8.12.0",
"argon2": "^0.40.1",
"body-parser": "^1.20.2",
Expand Down Expand Up @@ -134,18 +134,18 @@
"@types/luxon": "^3.4.2",
"@types/method-override": "^0.0.35",
"@types/multer": "^1.4.11",
"@types/node": "^20.11.24",
"@types/node": "^20.11.25",
"@types/node-emoji": "^1.8.2",
"@types/source-map-support": "^0.5.10",
"@types/supertest": "^6.0.2",
"@types/swagger-schema-official": "^2.0.25",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"commitizen": "^4.3.0",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"cspell": "^8.5.0",
"cspell": "^8.6.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand All @@ -159,7 +159,7 @@
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jest-extended": "^2.0.0",
"eslint-plugin-jsonc": "^2.13.0",
"eslint-plugin-markdown": "^3.0.1",
"eslint-plugin-markdown": "^4.0.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-prefer-arrow": "^1.2.3",
Expand Down Expand Up @@ -198,15 +198,15 @@
"tsc-alias": "^1.8.8",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"yaml-eslint-parser": "^1.2.2"
},
"engines": {
"node": ">=20.9.0",
"npm": ">=6.7.0"
},
"prisma": {
"schema": "src/infrastructure/shared/persistence/prisma/schema.prisma",
"seed": "tsx src/infrastructure/shared/persistence/prisma/seed.ts"
"schema": "src/shared/infrastructure/persistence/prisma/schema.prisma",
"seed": "tsx src/shared/infrastructure/persistence/prisma/seed.ts"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sync as readPackageJsonSync } from 'read-pkg';

import { getEnvironmentNumber, getEnvironmentString } from '@infrastructure/shared/config/environment';
import { getEnvironmentNumber, getEnvironmentString } from '@shared/infrastructure/config/environment';

const AppInfo = Object.freeze({
APP_VERSION: getEnvironmentString('APP_VERSION', readPackageJsonSync().version),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Default, Email, Enum, Format, Property } from '@tsed/schema';

import { UserResponse } from '@application/users';
import { UserGenders, UserRoles } from '@domain/users';
import { UserResponse } from '@modules/users/application';
import { UserGenders, UserRoles } from '@modules/users/domain';

class AuthenticatedUserApiResponse {
@Property()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { BodyParams, Context, Req, Res } from '@tsed/common';
import { Delete, Description, Example, Get, Post, Returns, Status, Summary, Tags, Title } from '@tsed/schema';
import { StatusCodes } from 'http-status-codes';

import { SessionResponse } from '@application/sessions';
import { EndSessionRequest, EndSessionUseCase } from '@application/sessions/end';
import { RefreshSessionRequest, RefreshSessionUseCase } from '@application/sessions/refresh';
import { StartSessionRequest, StartSessionUseCase } from '@application/sessions/start';
import { UserResponse } from '@application/users';
import { AuthenticateUserRequest, AuthenticateUserUseCase } from '@application/users/authentication';
import { FindUserRequest, FindUserUseCase } from '@application/users/find';
import { Logger } from '@domain/shared';
import { TriggeredBy, TriggeredByUser } from '@domain/shared/entities/triggered-by';
import { Authentication } from '@infrastructure/shared/authentication';
import { AuthenticationUtils } from '@infrastructure/shared/authentication/authentication-utils';
import { AppConfig } from '@presentation/rest/config';
import { NoCredentialsProvidedException } from '@presentation/rest/exceptions';
import { RequestUtils } from '@presentation/rest/shared/request.utils';
import { ResponseUtils } from '@presentation/rest/shared/response.utils';
import { RestController } from '@presentation/rest/shared/rest-controller.decorator';
import { WithAuth } from '@presentation/rest/shared/with-auth.decorator';
import { AppConfig } from '@contract/rest/config';
import { NoCredentialsProvidedException } from '@contract/rest/exceptions';
import { RequestUtils } from '@contract/rest/shared/request.utils';
import { ResponseUtils } from '@contract/rest/shared/response.utils';
import { RestController } from '@contract/rest/shared/rest-controller.decorator';
import { WithAuth } from '@contract/rest/shared/with-auth.decorator';
import { SessionResponse } from '@modules/sessions/application';
import { EndSessionRequest, EndSessionUseCase } from '@modules/sessions/application/end';
import { RefreshSessionRequest, RefreshSessionUseCase } from '@modules/sessions/application/refresh';
import { StartSessionRequest, StartSessionUseCase } from '@modules/sessions/application/start';
import { UserResponse } from '@modules/users/application';
import { AuthenticateUserRequest, AuthenticateUserUseCase } from '@modules/users/application/authentication';
import { FindUserRequest, FindUserUseCase } from '@modules/users/application/find';
import { Logger } from '@shared/domain';
import { TriggeredBy, TriggeredByUser } from '@shared/domain/entities/triggered-by';
import { Authentication } from '@shared/infrastructure/authentication';
import { AuthenticationUtils } from '@shared/infrastructure/authentication/authentication-utils';

import { AuthenticatedUserApiResponse } from './authenticated-user.api-response';
import { UserSuccessfullyAuthenticatedApiResponse } from './user-successfully-authenticated.api-response';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CollectionOf, Email, Property } from '@tsed/schema';

import { SessionResponse } from '@application/sessions';
import { SessionResponse } from '@modules/sessions/application';

class UserSuccessfullyAuthenticatedApiResponse {
@Property()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Default, Property } from '@tsed/schema';

import { HealthStatusResponse } from '@application/health';
import { AppInfo } from '@presentation/rest/config';
import { AppInfo } from '@contract/rest/config';
import { HealthStatusResponse } from '@modules/health/application';

class HealthStatusApiResponse {
@Property()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Context, Get } from '@tsed/common';
import { Description, Returns, Status, Summary, Tags, Title } from '@tsed/schema';
import { StatusCodes } from 'http-status-codes';

import { CheckHealthStatusRequest, CheckHealthStatusUseCase } from '@application/health';
import { TriggeredBy } from '@domain/shared/entities/triggered-by';
import { AppConfig, AppInfo } from '@presentation/rest/config';
import { RestController } from '@presentation/rest/shared/rest-controller.decorator';
import { AppConfig, AppInfo } from '@contract/rest/config';
import { RestController } from '@contract/rest/shared/rest-controller.decorator';
import { CheckHealthStatusRequest, CheckHealthStatusUseCase } from '@modules/health/application';
import { TriggeredBy } from '@shared/domain/entities/triggered-by';

import { HealthStatusApiResponse } from './health-status.api-response';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Default, Email, Enum, Format, Property } from '@tsed/schema';

import { UserResponse } from '@application/users';
import { UserGenders, UserRoles } from '@domain/users';
import { UserResponse } from '@modules/users/application';
import { UserGenders, UserRoles } from '@modules/users/domain';

class UserApiResponse {
@Property()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Context, Get, PathParams } from '@tsed/common';
import { Description, Returns, Status, Summary, Tags, Title } from '@tsed/schema';
import { StatusCodes } from 'http-status-codes';

import { FindUserRequest, FindUserUseCase } from '@application/users/find';
import { SearchAllUsersRequest, SearchAllUsersUseCase } from '@application/users/search-all';
import { TriggeredBy } from '@domain/shared/entities/triggered-by';
import { UserRoles } from '@domain/users';
import { AppConfig } from '@presentation/rest/config';
import { RestController } from '@presentation/rest/shared/rest-controller.decorator';
import { WithAuth } from '@presentation/rest/shared/with-auth.decorator';
import { AppConfig } from '@contract/rest/config';
import { RestController } from '@contract/rest/shared/rest-controller.decorator';
import { WithAuth } from '@contract/rest/shared/with-auth.decorator';
import { FindUserRequest, FindUserUseCase } from '@modules/users/application/find';
import { SearchAllUsersRequest, SearchAllUsersUseCase } from '@modules/users/application/search-all';
import { UserRoles } from '@modules/users/domain';
import { TriggeredBy } from '@shared/domain/entities/triggered-by';

import { UserApiResponse } from './user.api-response';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Default, Enum, Integer, Property } from '@tsed/schema';
import { ReasonPhrases, StatusCodes } from 'http-status-codes';
import * as emoji from 'node-emoji';

import { AppInfo } from '@presentation/rest/config';
import { AppInfo } from '@contract/rest/config';

import { ApiException } from './api.exception';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Catch, ExceptionFilterMethods, PlatformContext, Res } from '@tsed/common';
import { Exception, Exception as TsEdException } from '@tsed/exceptions';

import { Logger } from '@domain/shared';
import {
ApiException,
BadRequestException,
ExceptionApiResponse,
InternalServerErrorException,
ResourceNotFoundException,
UnauthorizedException
} from '@presentation/rest/exceptions';
} from '@contract/rest/exceptions';
import { Logger } from '@shared/domain';

@Catch(Exception)
@Catch(Error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Catch, ExceptionFilterMethods, PlatformContext, ResourceNotFound } from '@tsed/common';

import { PathNotFoundException } from '@presentation/rest/exceptions';
import { PathNotFoundException } from '@contract/rest/exceptions';

@Catch(ResourceNotFound)
class ResourceNotFoundFilter implements ExceptionFilterMethods {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Context, Middleware, MiddlewareMethods, Req, Res } from '@tsed/common';

import { ValidateSessionRequest, ValidateSessionUseCase } from '@application/sessions/validate';
import { ValidatedSessionResponse } from '@application/sessions/validate/validated-session.response';
import { TriggeredByUser } from '@domain/shared/entities/triggered-by';
import { UserRoles } from '@domain/users';
import { Authentication } from '@infrastructure/shared/authentication/authentication';
import { AuthenticationUtils } from '@infrastructure/shared/authentication/authentication-utils';
import { AppConfig } from '@presentation/rest/config';
import { ForbiddenException } from '@presentation/rest/exceptions';
import { RequestUtils } from '@presentation/rest/shared/request.utils';
import { ResponseUtils } from '@presentation/rest/shared/response.utils';
import { AppConfig } from '@contract/rest/config';
import { ForbiddenException } from '@contract/rest/exceptions';
import { RequestUtils } from '@contract/rest/shared/request.utils';
import { ResponseUtils } from '@contract/rest/shared/response.utils';
import { ValidateSessionRequest, ValidateSessionUseCase } from '@modules/sessions/application/validate';
import { ValidatedSessionResponse } from '@modules/sessions/application/validate/validated-session.response';
import { UserRoles } from '@modules/users/domain';
import { TriggeredByUser } from '@shared/domain/entities/triggered-by';
import { Authentication } from '@shared/infrastructure/authentication/authentication';
import { AuthenticationUtils } from '@shared/infrastructure/authentication/authentication-utils';

@Middleware()
class AuthenticationMiddleware implements MiddlewareMethods {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Err, Middleware, MiddlewareMethods, Next, Req, Res } from '@tsed/common';
import { Exception as TsEdException } from '@tsed/exceptions';

import { Logger } from '@domain/shared';
import {
ApiException,
BadRequestException,
ExceptionApiResponse,
ResourceNotFoundException,
UnauthorizedException
} from '@presentation/rest/exceptions';
import { InternalServerErrorException } from '@presentation/rest/exceptions/internal-server-error.exception';
} from '@contract/rest/exceptions';
import { InternalServerErrorException } from '@contract/rest/exceptions/internal-server-error.exception';
import { Logger } from '@shared/domain';

@Middleware()
class ErrorHandlerMiddleware implements MiddlewareMethods {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context, Middleware, MiddlewareMethods, Req, Res } from '@tsed/common';

import { GlobalConfig } from '@infrastructure/shared/config';
import { PINO_LOGGER } from '@infrastructure/shared/logger/pino-logger';
import { GlobalConfig } from '@shared/infrastructure/config';
import { PINO_LOGGER } from '@shared/infrastructure/logger/pino-logger';

@Middleware()
class LoggerMiddleware implements MiddlewareMethods {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Context, Middleware, MiddlewareMethods, OnResponse, Req } from '@tsed/common';

import { Token, TokenProviderDomainService } from '@domain/sessions/tokens';
import { Nullable } from '@domain/shared';
import { TriggeredByAnonymous, TriggeredByUser } from '@domain/shared/entities/triggered-by';
import { Authentication } from '@infrastructure/shared/authentication';
import { AuthenticationUtils } from '@infrastructure/shared/authentication/authentication-utils';
import { AppConfig } from '@presentation/rest/config';
import { RequestUtils } from '@presentation/rest/shared/request.utils';
import { AppConfig } from '@contract/rest/config';
import { RequestUtils } from '@contract/rest/shared/request.utils';
import { Token, TokenProviderDomainService } from '@modules/sessions/domain/tokens';
import { Nullable } from '@shared/domain';
import { TriggeredByAnonymous, TriggeredByUser } from '@shared/domain/entities/triggered-by';
import { Authentication } from '@shared/infrastructure/authentication';
import { AuthenticationUtils } from '@shared/infrastructure/authentication/authentication-utils';

@Middleware()
class MetadataMiddleware implements MiddlewareMethods, OnResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Middleware, MiddlewareMethods, Next, Req, Res } from '@tsed/common';

import { PathNotFoundException } from '@presentation/rest/exceptions';
import { PathNotFoundException } from '@contract/rest/exceptions';

@Middleware()
class NotFoundMiddleware implements MiddlewareMethods {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@tsed/ajv';
import '@tsed/platform-express';
import '@tsed/swagger';
import '@tsed/ajv';
import './filters';

import { PlatformApplication } from '@tsed/common';
Expand All @@ -15,31 +15,33 @@ import figlet from 'figlet';
import methodOverride from 'method-override';
import * as emoji from 'node-emoji';

import { Logger } from '@domain/shared';
import { CacheConfig, GlobalConfig } from '@infrastructure/shared/config';
import { Logger } from '@shared/domain';
import { CacheConfig, GlobalConfig } from '@shared/infrastructure/config';

import { AppConfig, AppInfo } from './config';
import { ErrorHandlerMiddleware, LoggerMiddleware, MetadataMiddleware, NotFoundMiddleware } from './middlewares';

const ROOT_DIRECTORY = __dirname;

class Server {
@Inject()
private app: PlatformApplication;

public static async getConfiguration(): Promise<Partial<TsED.Configuration>> {
const baseConfiguration: Partial<TsED.Configuration> = {
rootDir: __dirname,
rootDir: ROOT_DIRECTORY,
acceptMimes: ['application/json'],
httpPort: AppConfig.PORT,
httpsPort: false
};

const providersConfiguration: Partial<TsED.Configuration> = await importProviders({
mount: {
[AppConfig.BASE_PATH]: [`${__dirname}/controllers/**/*.controller.ts`]
[AppConfig.BASE_PATH]: [`${ROOT_DIRECTORY}/controllers/**/*.controller.ts`]
},
imports: [
`${__dirname}/../../infrastructure/**/*.domain-service.ts`,
`${__dirname}/../../infrastructure/**/*.repository.ts`
`${ROOT_DIRECTORY}/../../modules/**/infrastructure/**/*.domain-service.ts`,
`${ROOT_DIRECTORY}/../../modules/**/infrastructure/**/*.repository.ts`
]
});

Expand Down
Loading