Skip to content

refactor: split shared into packages #50

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

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

tomast1337
Copy link
Member

@tomast1337 tomast1337 commented Jul 25, 2025

This pull request introduces several structural and configuration changes to the whole project, primarily focused on spiting the project server, web and shared packages into separate @nbw/backend, @nbw/frontend, @nbw/database, @nbw/song, @nbw/thumbnail, @nbw/sounds and @nbw/config.

The following diagram shows the new structure of the project:

graph TD
    subgraph "Applications"
        Backend["@nbw/backend<br/>(Backend App)"]
        Frontend["@nbw/frontend<br/>(Frontend App)"]
    end
    
    subgraph "Workspace Packages"
        Config["@nbw/config<br/>(Configuration)"]
        Database["@nbw/database<br/>(Database Entities & DTOs)"]
        Song["@nbw/song<br/>(Song Processing)"]
        Sounds["@nbw/sounds<br/>(Sound Management)"]
        Thumbnail["@nbw/thumbnail<br/>(Thumbnail Generation)"]
    end
    
    %% Workspace package dependencies
    Database --> Config
    Song --> Database
    Thumbnail --> Song
    
    %% Backend dependencies
    Backend --> Database
    Backend --> Song
    Backend --> Thumbnail
    Backend --> Sounds
    
    %% Frontend dependencies (through workspace)
    Frontend -.-> Config
    Frontend -.-> Database
    Frontend -.-> Song
    Frontend -.-> Thumbnail
    
    %% Styling
    classDef appStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
    classDef pkgStyle fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
    classDef leafStyle fill:#e8f5e8,stroke:#388e3c,stroke-width:2px
    
    class Backend,Frontend appStyle
    class Database,Song,Thumbnail pkgStyle
    class Config,Sounds leafStyle
Loading

Bun and Testing Improvements

  • Refined test scripts in package.json to run tests specifically on src/**/*.spec.ts and e2e/**/*.spec.ts, improving test targeting and coverage.

  • Added .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc to document and enforce the use of Bun over Node.js, npm, pnpm, or vite, including recommendations for APIs, testing, and frontend workflows.

@tomast1337 tomast1337 self-assigned this Jul 25, 2025
@tomast1337 tomast1337 added enhancement New feature or request help wanted Extra attention is needed labels Jul 25, 2025
Copy link
Member

@Bentroen Bentroen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for working on these changes =)

Some extra things (besides the review comments) we gotta make sure are working before merging:

  • Update VSCode workspace file, test running etc. to reflect the new project structure
  • Update GitHub Actions to reflect the new project structure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had originally decided to leave build.ts in the root of the project, as it was depended upon by both the frontend and the backend. With the new project structure, doesn't it belong in one of the different packages we created?
(Adding @nbw/sounds as the one single global workspace dependency looks a bit weird to me, haha :) )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, could we rename the build commands to use frontend and backend too, like the package names?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a result of introducing separate packages, first-party package imports have been grouped with third-party ones (see this file as an example). The @nbw/ group should be added as a local package group in ESLint - I'll look up how we can do this again :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the rest of the project's structure, this file could be moved to the source file's path, and renamed to stats.spec.ts (as we'll likely add test files for the other modules in there)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid all the repetition, would it be possible to use a shared tsconfig.json using extends with these common package configurations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separate .gitignore files may not be necessary, in case the root's package.json already takes care of them

@Bentroen Bentroen mentioned this pull request Aug 13, 2025
21 tasks
@tomast1337 tomast1337 requested review from Bentroen and Copilot August 14, 2025 13:50
@tomast1337 tomast1337 linked an issue Aug 14, 2025 that may be closed by this pull request
21 tasks
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR restructures the monorepo by splitting the original server, web, and shared packages into focused workspace packages and applications. It creates a more modular architecture with separate packages for configuration, database entities, song processing, thumbnail generation, and sound management, while establishing clear dependency relationships between components.

  • Splits the monolithic structure into focused packages (@nbw/config, @nbw/database, @nbw/song, @nbw/thumbnail, @nbw/sounds)
  • Creates dedicated application packages (@nbw/backend, @nbw/frontend)
  • Updates all import paths throughout the codebase to use the new package structure

Reviewed Changes

Copilot reviewed 124 out of 398 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/configs/ New configuration package with shared constants and types
packages/database/ New database package setup with gitignore and eslint config
apps/frontend/ Updated frontend with new import paths and package structure
apps/backend/ Updated backend with new import paths and dependency references
package.json Root package updated with new workspace structure and exports
build.ts Updated build script to use new package imports

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -22,16 +22,9 @@ Full list of colors is available at:
https://tailwindcss.com/docs/customizing-colors

*/
import colors from 'tailwindcss/colors';
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement has changed from a complex import with type casting to a direct import. Ensure that 'tailwindcss/colors' exports are compatible with the expected format and that the removal of the type casting doesn't break the color object structure.

Suggested change
import colors from 'tailwindcss/colors';
import * as colors from 'tailwindcss/colors';

Copilot uses AI. Check for mistakes.

@@ -1,8 +1,6 @@
import { bgColors } from '@shared/features/thumbnail/colors';
import { BG_COLORS } from './colors';
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import references './colors' but the file being modified is 'song.ts' and the colors are defined in 'colors.ts'. This import should work correctly, but verify that the BG_COLORS export is properly available from the colors module.

Copilot uses AI. Check for mistakes.

@@ -156,14 +156,17 @@ export const SongThumbnailInput = ({
/>

{song && notes && (
<ThumbnailRendererCanvas notes={notes} formMethods={formMethods} />
<ThumbnailRendererCanvas
notes={notes as unknown as NoteQuadTree} //TODO: fix this bizarre type cast
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type cast 'as unknown as NoteQuadTree' with a TODO comment indicates a type mismatch that should be resolved properly rather than using a double cast. This suggests the types between packages may not be properly aligned.

Suggested change
notes={notes as unknown as NoteQuadTree} //TODO: fix this bizarre type cast
notes={notes}

Copilot uses AI. Check for mistakes.

song = await parseSongFromBuffer(await file.arrayBuffer());
song = (await parseSongFromBuffer(
await file.arrayBuffer(),
)) as unknown as SongFileType; // TODO: Investigate this weird type error
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another 'as unknown as' type cast with a TODO comment. This pattern appears multiple times and suggests that the type definitions between packages may need to be reconciled to avoid these unsafe casts.

Suggested change
)) as unknown as SongFileType; // TODO: Investigate this weird type error
const parsedSong = await parseSongFromBuffer(
await file.arrayBuffer(),
);
if (!isSongFileType(parsedSong)) {
throw new Error('Parsed song does not match SongFileType');
}
song = parsedSong;

Copilot uses AI. Check for mistakes.

@@ -259,7 +259,7 @@ export const EditSongProvider = ({
setInstrumentSounds(songInstruments);
formMethods.setValue('customInstruments', songInstruments);

setSong(song);
setSong(song as unknown as SongFileType); // TODO: Investigate this weird type error
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of the same type casting issue. This pattern suggests a systematic problem with type compatibility that should be addressed at the package level rather than with individual casts.

Suggested change
setSong(song as unknown as SongFileType); // TODO: Investigate this weird type error
setSong(song as SongFileType);

Copilot uses AI. Check for mistakes.

"typescript": "^5"
},
"peerDependencies": {
"typescript": "^5"
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package includes 'tailwindcss' as an implicit dependency through the colors import but doesn't declare it as a dependency or peerDependency. This could cause issues if tailwindcss is not available in consuming packages.

Suggested change
"typescript": "^5"
"typescript": "^5",
"tailwindcss": "^3.0.0"

Copilot uses AI. Check for mistakes.

@@ -13,7 +13,7 @@ function writeJSONFile(
writeFileSync(path, jsonString);
}

const dataDir = resolve(__dirname, 'server', 'public', 'data');
const dataDir = resolve(__dirname, 'packages', 'backend', 'public', 'data');
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path references 'packages/backend' but according to the new structure, the backend should be in 'apps/backend'. This path should be updated to match the new directory structure.

Suggested change
const dataDir = resolve(__dirname, 'packages', 'backend', 'public', 'data');
const dataDir = resolve(__dirname, 'apps', 'backend', 'public', 'data');

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Project structure refactor
2 participants