Skip to content

Commit d4338f7

Browse files
committed
refactor(backend): use import map instead of ts alias, reduce file count
1 parent a88021b commit d4338f7

18 files changed

Lines changed: 25 additions & 50 deletions

File tree

apps/backend/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
## Structuring cookbook:
1616
#### Root level:
17-
Things like 3rd party APIs, DBs, Storages connectors, etc, should be placed in `~/providers` folder, grouped by their purpose if possible, e.g: `~/providers/auth/kinde-main.ts`, `~/providers/db/neon-main.ts`.
17+
Things like 3rd party APIs, DBs, Storages connectors, etc, should be placed in `#src/providers` folder, grouped by their purpose if possible, e.g: `#src/providers/auth/kinde-main.ts`, `#src/providers/db/neon-main.ts`.
1818

19-
Things that interact with `~/providers` should be placed in `~/services` folder. (like an `user` service)
19+
Things that interact with `#src/providers` should be placed in `#src/services` folder. (like an `user` service)
2020

21-
Other globally reuseable code should be placed in `~/helpers` folder. (like `error`, `logger` utils)
21+
Other globally reuseable code should be placed in `#src/helpers` folder. (like `error`, `logger` utils)
2222

2323
Locally reusable code should be placed in the same folder as the file that uses it, its name should be its usable scope, suffixing the file name with `.helper`, e.g: `/api/dummy/hello.helper.ts`, `/api/$.helper.ts`.
2424

apps/backend/build.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
22
import { defineBuildConfig } from 'unbuild'
3-
import sharedConfig from './shared.config'
43

54
export default defineBuildConfig({
65
entries: [
@@ -29,5 +28,4 @@ export default defineBuildConfig({
2928
options.plugins = [options.plugins, dynamicImportVars()]
3029
},
3130
},
32-
...sharedConfig,
3331
})

apps/backend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"type": "module",
44
"version": "0.0.0",
55
"private": true,
6+
"imports": {
7+
"#src/*": "./src/*"
8+
},
69
"scripts": {
710
"lint": "eslint .",
811
"test": "vitest",

apps/backend/shared.config.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

apps/backend/src/api/$$.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { appFactory } from '~/helpers/factory'
1+
import { appFactory } from '#src/helpers/factory.js'
22

33
export const apiRouteApp = appFactory.createApp()
44
.get('', async c => c.text('OK'))

apps/backend/src/api/$.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { appFactory } from '~/helpers/factory'
1+
import { appFactory } from '#src/helpers/factory.js'
22
import { apiRouteApp } from './$$'
33
import { authApp } from './auth/$'
44
import { dummyGreetRouteApp } from './dummy/greet'

apps/backend/src/api/auth/$.routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { ClaimTokenType, FlagType } from '@kinde-oss/kinde-typescript-sdk'
2+
import { appFactory } from '#src/helpers/factory.js'
3+
import { getSessionManager } from '#src/helpers/kinde.js'
4+
import { getKindeClient } from '#src/providers/auth/kinde-main.js'
25
import { env } from 'std-env'
3-
import { appFactory } from '~/helpers/factory'
4-
import { getSessionManager } from '~/helpers/kinde'
5-
import { getKindeClient } from '~/providers/auth/kinde-main'
66

77
export const authRoutesApp = appFactory.createApp()
88
.get('/health', async (c) => {

apps/backend/src/api/auth/$.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { appFactory } from '~/helpers/factory'
1+
import { appFactory } from '#src/helpers/factory.js'
22
import { authRoutesApp } from './$.routes'
33

44
export const authApp = appFactory.createApp()

apps/backend/src/api/dummy/greet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { customArktypeValidator } from '#src/helpers/arktype.js'
2+
import { appFactory } from '#src/helpers/factory.js'
3+
import { i18nComposer } from '#src/helpers/i18n.js'
14
import { type } from 'arktype'
25
import { describeRoute } from 'hono-openapi'
36
import { resolver } from 'hono-openapi/arktype'
4-
import { customArktypeValidator } from '~/helpers/arktype'
5-
import { appFactory } from '~/helpers/factory'
6-
import { i18nComposer } from '~/helpers/i18n'
77

88
export const dummyGreetRouteApp = appFactory.createApp()
99
.get(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { i18nComposer } from '~/helpers/i18n'
1+
import { i18nComposer } from '#src/helpers/i18n.js'
22

33
// This isa sample for structuring guide
44
export const getHelloMessage = () => `${i18nComposer.t('hello-from-/x', { x: 'i18n and Hono' })}! - ${Date.now()}`

0 commit comments

Comments
 (0)