You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Description
<!-- Provide a comprehensive description here about what your PR aims to
solve. -->
<!-- You may also add additional context -->
Misc refactor to Layered Architecture
Closes#168
---
### PR Checklist
<!-- Please do not remove this section -->
<!-- Mark each item with an "x" ([ ] becomes [x]) -->
- [x] Read the Developer's Guide in
[CONTRIBUTING.md](https://github.com/agnyz/bedstack/blob/main/CONTRIBUTING.md)
- [x] Use a concise title to represent the changes introduced in this PR
- [x] Provide a detailed description of the changes introduced in this
PR, and, if necessary, some screenshots
- [x] Reference an issue or discussion where the feature or changes have
been previously discussed
- [x] Add a failing test that passes with the changes introduced in this
PR, or explain why it's not feasible
- [x] Add documentation for the feature or changes introduced in this PR
to the docs; you can run them with `bun docs`
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced standardized error handling with a new `RealWorldError`
class and structured error responses.
- Added utility modules for error formatting, date operations, and
validation tasks.
- Added reusable interface types for API responses, pagination, and
common entities.
- Centralized and expanded constants for pagination and error messages.
- **Refactor**
- Unified and simplified error handling across services, replacing
custom error classes with standardized errors and HTTP status codes.
- Updated import paths throughout the codebase for consistency using a
single alias pattern.
- Reorganized and clarified project structure documentation and code
organization.
- Improved and centralized constants and utility exports for easier
access.
- **Bug Fixes**
- Fixed broken Markdown links and standardized code block formatting in
documentation.
- **Chores**
- Simplified TypeScript path aliases in configuration.
- Cleaned up whitespace and improved formatting in all documentation
files.
- **Documentation**
- Expanded and clarified project structure, usage guidelines, and added
new documentation for utilities and interfaces.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,9 @@ Hey there! We're thrilled that you'd like to contribute to this project. Your he
9
9
10
10
This project uses [Bun](https://bun.sh) as a runtime as well as a package manager. It's a modern, fast, and lightweight alternative to [Node.js](https://nodejs.org/en/) and [npm](https://www.npmjs.com/). To install Bun on POSIX systems (like Ubuntu or macOS), run the following command:
11
11
12
-
```sh
13
-
curl -fsSL https://bun.sh/install | bash
14
-
```
12
+
```sh
13
+
curl -fsSL https://bun.sh/install | bash
14
+
```
15
15
16
16
Otherwise, visit the [Bun installation page](https://bun.sh/docs/installation) for installation options.
17
17
@@ -27,7 +27,7 @@ Build the project for production. The result is under `dist/`.
27
27
28
28
### `bun check`
29
29
30
-
We use [Biome](https://biomejs.dev/) for **both linting and formatting**. It is an ultra-fast, Rust based linter and formatter.
30
+
We use [Biome](https://biomejs.dev/) for **both linting and formatting**. It is an ultra-fast, Rust based linter and formatter.
31
31
It also lints JSON.
32
32
33
33
You can also run `bun fix` to apply any safe fixes automatically.
@@ -69,8 +69,9 @@ Where the template is:
69
69
```
70
70
71
71
Replacing:
72
-
*`<keyword>` with one of `close`, `closes`, `closed`, `fix`, `fixes`, `fixed`, `resolve`, `resolves`, `resolved`
73
-
*`<issue-number>`: the issue number you are fixing
72
+
73
+
-`<keyword>` with one of `close`, `closes`, `closed`, `fix`, `fixes`, `fixed`, `resolve`, `resolves`, `resolved`
74
+
-`<issue-number>`: the issue number you are fixing
74
75
75
76
This will let GitHub know the issues are linked, and automatically close them once the PR gets merged. Learn more at [the guide](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword).
Copy file name to clipboardExpand all lines: GOVERNANCE.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,31 +4,31 @@
4
4
5
5
To understand the scope of this document, please read:
6
6
7
-
*[*What is governance?* by Adobe](https://github.com/adobe/open-development-template/blob/master/Governance.md#meritocracy)
8
-
*[*Jenkins Governance Document* for an inspiration](https://www.jenkins.io/project/governance/)
7
+
-[_What is governance?_ by Adobe](https://github.com/adobe/open-development-template/blob/master/Governance.md#meritocracy)
8
+
-[_Jenkins Governance Document_ for an inspiration](https://www.jenkins.io/project/governance/)
9
9
10
10
## Who we are
11
11
12
12
We are a group of open-source developers who develop, use, promote the Elysia RealWorld example app, software around it, and other related activities for our mutual benefit.
13
13
14
14
## Core Philosophy
15
15
16
-
***Lower barrier to entry**
16
+
-**Lower barrier to entry**
17
17
18
-
Everyone is welcome to contribute, regardless of their background, experience, or identity. We value all contributions, and we are committed to providing a friendly, safe, and welcoming environment for all. Everyone gets a voice, and everyone is listened to.
18
+
Everyone is welcome to contribute, regardless of their background, experience, or identity. We value all contributions, and we are committed to providing a friendly, safe, and welcoming environment for all. Everyone gets a voice, and everyone is listened to.
19
19
20
-
***Seeking consensus**
20
+
-**Seeking consensus**
21
21
22
-
We seek consensus among contributors, and we are open to new ideas and approaches. When consensus cannot be reached after giving the stage to all parties, we will use a majority-wins voting process. We will strive to resolve conflicts in a constructive manner.
22
+
We seek consensus among contributors, and we are open to new ideas and approaches. When consensus cannot be reached after giving the stage to all parties, we will use a majority-wins voting process. We will strive to resolve conflicts in a constructive manner.
23
23
24
-
***Meritocracy**
24
+
-**Meritocracy**
25
25
26
-
We value contributions based on their technical merit, and we welcome new contributors based on their demonstrated ability to contribute. Valuable contributers will be granted access to private channels and will be able to participate in the decision-making process.
27
-
28
-
***Transparency**
29
-
30
-
While the decision-making process is not always public, the results of the decision making process must be public. Decisions will be made after thoughtful consideration of the community's input through [Discord](https://discord.gg/8UcP9QB5AV) and [GitHub Discussions](https://github.com/agnyz/bedstack/discussions).
26
+
We value contributions based on their technical merit, and we welcome new contributors based on their demonstrated ability to contribute. Valuable contributers will be granted access to private channels and will be able to participate in the decision-making process.
31
27
32
-
***Automation**
28
+
-**Transparency**
33
29
34
-
We rely on automation to make our processes more efficient and to reduce the burden on contributors. We will automate as much as possible, and we will strive to make our automation tools accessible to all contributors. The goal is to abstract away the mundane tasks and let contributors focus on the fun stuff.
30
+
While the decision-making process is not always public, the results of the decision making process must be public. Decisions will be made after thoughtful consideration of the community's input through [Discord](https://discord.gg/8UcP9QB5AV) and [GitHub Discussions](https://github.com/agnyz/bedstack/discussions).
31
+
32
+
-**Automation**
33
+
34
+
We rely on automation to make our processes more efficient and to reduce the burden on contributors. We will automate as much as possible, and we will strive to make our automation tools accessible to all contributors. The goal is to abstract away the mundane tasks and let contributors focus on the fun stuff.
> The `app.module.ts` file is named in the spirit of NestJS, where the app module is the device in charge of putting together all the pieces of the application. See [NestJS Modules](https://docs.nestjs.com/modules) for more details.
22
32
23
-
Each feature (e.g. `articles/`, `comments/`) uses this layout:
│ └── feature-row.interface.ts# Drizzle-inferred DB shape
52
+
│ ├── resource.interface.ts # Domain model
53
+
│ └── resource-row.interface.ts# Drizzle-inferred DB shape
40
54
```
41
55
42
-
## Folder-Level Purpose
56
+
> [!NOTE]
57
+
> Note the filename is written in plural form (`resources.controller.ts`, e.g. `articles.controller.ts`) in the spirit of NestJS.
58
+
59
+
### Other Folders Inside `src/`
43
60
44
-
###`/db/`
61
+
#### `database/`
45
62
46
-
- Drizzle config and init
47
-
- Exports the db instance
63
+
- Exports the db instance through `database.providers.ts`
48
64
- Does **not** export db tables, these are found as schemas inside feature folders
65
+
- Does **not** export Drizzle config and migrations, these are found in `drizzle.config.ts` and `drizzle/` (from the root of the project) respectively
49
66
50
-
###`/shared/`
67
+
#### `common/`
51
68
52
-
Global utilities, middleware, and shared concerns.
69
+
Global utilities, middleware, and common concerns.
53
70
54
71
```plaintext
55
-
shared/
56
-
├── auth-middleware.ts # Extracts auth context
57
-
├── http-errors.ts # Shared error classes
58
-
├── slugify.ts # Utility for slug generation
72
+
common/
73
+
├── constants/ # All global constants, grouped by domain
74
+
│ ├── auth.constants.ts
75
+
│ ├── validation.constants.ts
76
+
│ └── realworld.constants.ts
77
+
├── errors/ # Global error types and helpers
78
+
│ ├── realworld.error.ts # RealWorld API-compliant base error class
79
+
│ └── error.factory.ts # Helpers for throwing structured errors
80
+
├── interfaces/ # Global interfaces (not feature-specific)
81
+
│ └── pagination.interface.ts
82
+
├── utils/ # Pure utility functions used app-wide
83
+
│ ├── slugify.ts
84
+
│ └── date.utils.ts
59
85
```
60
86
87
+
> [!NOTE]
88
+
> The `common/` folder is a catch-all for things that are not specific to a single feature. It's organized by purpose, not by type/domain. That's why it can have both `errors/` (domain) and `utils/` (type) folders.
89
+
90
+
> [!WARNING]
91
+
> Avoid dumping everything into `common/` by default. If a util, constant, or interface is only used in one feature - keep it inside that feature's folder. Promote it to `common/` only when it's reused.
92
+
93
+
> [!TIP]
94
+
> Only one `constants/` folder exists across the project - do not spread constants into individual features unless strictly private to that feature.
95
+
61
96
## Naming Conventions
62
97
63
98
### DTO Naming
@@ -80,7 +115,7 @@ shared/
80
115
- May also define `relations()` in the same file unless very large
81
116
- If split, name the second file `feature-relations.schema.ts`
82
117
83
-
## See also
118
+
## See Also
84
119
85
120
- More on **Architecture** - see [Architecture](ARCHITECTURE.md)
86
121
-**Contributing** - see [Developer's Guide](CONTRIBUTING.md)
Copy file name to clipboardExpand all lines: README.md
+33-32Lines changed: 33 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,52 +7,53 @@
7
7
8
8
[RealWorld](https://realworld-docs.netlify.app/) example app for [Bun](https://bun.sh/) + [ElysiaJS](https://elysiajs.com/) + [Drizzle](https://orm.drizzle.team/)
9
9
10
-
[](https://github.com/agnyz/bedstack/actions/workflows/tests.yml?query=branch%3Amain)[](https://realworld-docs.netlify.app/specifications/backend/endpoints)[](https://codebase.show/projects/realworld?category=backend&language=typescript)[](https://github.com/agnyz/bedstack/blob/main/LICENSE)[](https://github.com/agnyz/bedstack)
10
+
[](https://github.com/agnyz/bedstack/actions/workflows/tests.yml?query=branch%3Amain)[](https://realworld-docs.netlify.app/specifications/backend/endpoints)[](https://codebase.show/projects/realworld?category=backend&language=typescript)[](https://github.com/agnyz/bedstack/blob/main/LICENSE)[](https://github.com/agnyz/bedstack)
11
11
12
-
## Let's share a BED - join our [Discord server](https://discord.gg/8UcP9QB5AV)
12
+
## Let's share a BED - join our [Discord server](https://discord.gg/8UcP9QB5AV)
13
13
14
14
</div>
15
15
16
16
### Quickstart
17
17
18
18
1.**Clone and install dependencies**
19
19
20
-
```sh
21
-
gh repo clone agnyz/bedstack
22
-
cd bedstack
23
-
bun i
24
-
```
20
+
```sh
21
+
gh repo clone agnyz/bedstack
22
+
cd bedstack
23
+
bun i
24
+
```
25
25
26
26
2.**Create a `.env` file**
27
27
28
-
```sh
29
-
cp .env.example .env
30
-
```
28
+
```sh
29
+
cp .env.example .env
30
+
```
31
31
32
-
Use the provided example values or replace them with your own.
32
+
Use the provided example values or replace them with your own.
33
33
34
34
3.**Ensure Docker daemon is running and spin up the Postgres container**
0 commit comments