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

refactor: use NestJS design patterns #37

Merged
merged 17 commits into from
Sep 25, 2023
Merged

Conversation

yamcodes
Copy link
Contributor

@yamcodes yamcodes commented Sep 25, 2023

Applies a patch to @Hajbo's drizzle + postgres setup.

Changes

The biggest change here is refactoring the code to match NestJS principles as much as possible, while still taking the ElysiaJS docs seriously.

Since this is balance is subtle and groundbreaking* (see note below), I left comments in the code explaining the considerations. Please review and feel free to take them out before merge or in a dedicated PR.

The best way to review this PR is to pull it into your IDE, run the code, and play around with the file structure, maybe try to add a feature or two to the users service.

See commits for full details

  • Refactor
  • Add convenience scripts
  • Make migrate.ts work from anywhere, including project root

Groundbreaking

This balance (between NestJS best practices and ElysiaJS best practices) is groundbreaking since it is not the same as projects that try to mimic NestJS in Express are different. Elysia strongly encourages method-chaining which is not a common Express/Fastify practice.

Follow-up Considerations

  • Consider changing ./db to ./drizzle to avoid confusion with ./src/database.providers.ts. I didn't do it here because I'm not a big fan of vendor-locking by naming files by technology.
  • We need to still add more structures to each resource, potentially *.module.ts, *.entity.ts, etc. Let's carefully add them as needed, but let's try to avoid put everything in *.schema.ts just because we don't know where else to put it. See references for the users folder in other RealWorld apps: 1 - busy example 2 - lean example. Naturally, this will also depend on the way we infer types and schemas (using drizzle-typebox and the likes)
  • Swagger endpoint #36 - we need to understand how to apply an OpenAPI schema to this structure.

@yamcodes yamcodes changed the title feat: drizzle + postgress + patch refactor: borrow NestJS design patterns Sep 25, 2023
@yamcodes yamcodes changed the title refactor: borrow NestJS design patterns refactor: use NestJS design patterns Sep 25, 2023
@yamcodes yamcodes requested a review from Hajbo September 25, 2023 16:20
@yamcodes yamcodes marked this pull request as ready for review September 25, 2023 16:25
Base automatically changed from feature/drizzle-postgres to main September 25, 2023 16:41
@yamcodes yamcodes linked an issue Sep 25, 2023 that may be closed by this pull request
@Hajbo Hajbo merged commit f4e73fb into main Sep 25, 2023
2 checks passed
@Hajbo Hajbo deleted the feature/drizzle-postgres-patch branch September 25, 2023 21:01
This was referenced Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add user model
2 participants