Skip to content

Conversation

@C4illin
Copy link
Owner

@C4illin C4illin commented Jun 3, 2025

Summary by Sourcery

Refactor project structure by extracting core route definitions from a single monolithic file into separate Elysia page modules, centralize environment and database setup, and modernize linting, styling, and dependencies.

Enhancements:

  • Modularize route handling by moving each endpoint into its own plugin under src/pages.
  • Centralize environment variable logic in a new src/helpers/env.ts helper.
  • Extract database initialization and migrations into src/db/db.ts.
  • Update ESLint configuration to switch from readable-tailwind to better-tailwindcss and adjust related rules.
  • Clean up main.css by removing legacy border-color compatibility styles.

Build:

  • Replace eslint-plugin-readable-tailwind with eslint-plugin-better-tailwindcss and remove unused PostCSS packages in package.json.
  • Adjust Docker Compose defaults to disable HTTP_ALLOWED and ALLOW_UNAUTHENTICATED for improved security.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 3, 2025

Reviewer's Guide

This PR refactors the monolithic src/index.tsx by extracting route handlers into dedicated page modules, centralizing environment and database setup, and updating lint and styling configurations.

Sequence Diagram for User Registration Process

sequenceDiagram
    actor User
    participant Browser
    participant IndexApp as "ElysiaApp (index.tsx)"
    participant UserPage as "UserPage (user.tsx)"
    participant DbModule as "Database (db.ts)"
    participant JWTService

    User->>Browser: Fills registration form & submits
    Browser->>IndexApp: POST /register (email, password)
    IndexApp->>UserPage: handleRegistration(data)
    UserPage->>DbModule: Query: SELECT * FROM users WHERE email = ?
    DbModule-->>UserPage: User not found
    UserPage->>Bun.password: hash(password)
    Bun.password-->>UserPage: hashedPassword
    UserPage->>DbModule: Query: INSERT INTO users (email, password)
    DbModule-->>UserPage: User created (returns user.id)
    UserPage->>JWTService: sign({ id: user.id })
    JWTService-->>UserPage: accessToken
    UserPage->>Browser: Set 'auth' cookie (accessToken)
    UserPage->>Browser: HTTP 302 Redirect to /
    Browser->>IndexApp: GET /
    IndexApp-->>Browser: Serve main page
Loading

Entity Relationship Diagram for Database Schema (Managed by src/db/db.ts)

erDiagram
    users {
        INTEGER id PK
        TEXT email
        TEXT password
    }
    jobs {
        INTEGER id PK
        INTEGER user_id FK
        TEXT date_created
        TEXT status
        INTEGER num_files
    }
    file_names {
        INTEGER id PK
        INTEGER job_id FK
        TEXT file_name
        TEXT output_file_name
        TEXT status
    }

    users ||--o{ jobs : "has"
    jobs ||--o{ file_names : "contains_files_for"
Loading

Class Diagram for Core Data Structures

classDiagram
    class User {
      +id: number
      +email: string
      +password: string
      <<src/pages/user.tsx>>
    }
    class Filename {
      +id: number
      +job_id: number
      +file_name: string
      +output_file_name: string
      +status: string
      <<Exported from src/index.tsx>>
    }
    class Jobs {
      +id: number
      +user_id: number
      +date_created: string
      +status: string
      +num_files: number
      +finished_files: number
      +files_detailed: Filename[]
      <<Exported from src/index.tsx>>
    }
    Jobs "1" o-- "*" Filename : contains
Loading

File-Level Changes

Change Details Files
Extracted route definitions into separate page modules
  • Created dedicated page modules for user, root, upload, history, convert, download, results, deleteFile, listConverters, and chooseConverter under src/pages
  • Replaced inline route implementations in src/index.tsx with .use(page) registrations
src/index.tsx
src/pages/user.tsx
src/pages/root.tsx
src/pages/upload.tsx
src/pages/history.tsx
src/pages/convert.tsx
src/pages/download.tsx
src/pages/results.tsx
src/pages/deleteFile.tsx
src/pages/listConverters.tsx
src/pages/chooseConverter.tsx
Centralized database initialization
  • Moved SQLite database setup and migrations into src/db/db.ts
  • Removed direct Database import and table creation logic from src/index.tsx
src/index.tsx
src/db/db.ts
Centralized environment variable definitions
  • Introduced src/helpers/env.ts exporting application settings
  • Replaced inline process.env reads in src/index.tsx and compose.yaml with env helper constants
src/index.tsx
src/helpers/env.ts
compose.yaml
Updated ESLint and Tailwind CSS configurations
  • Replaced eslint-plugin-readable-tailwind with eslint-plugin-better-tailwindcss and adjusted rules in eslint.config.ts
  • Removed custom Tailwind CSS compatibility overrides from src/main.css
  • Updated package.json dependencies to match new lint and styling plugins
eslint.config.ts
src/main.css
package.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@C4illin C4illin merged commit 82f0e14 into main Jun 3, 2025
3 checks passed
@C4illin C4illin deleted the refactor-elysia-router branch June 3, 2025 13:11
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @C4illin - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

.use(deleteFile)
.use(listConverters)
.use(chooseConverter)
.onError(({ error }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Enhance error logging with context

Include request method, URL, and status code in the error logs to improve production debugging.


const userUploadsDir = `${uploadsDir}${user.id}/${jobId.value}/`;

if (body?.file) {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Create upload directory before writing

Add await mkdir(userUploadsDir, { recursive: true }) before writing files to prevent runtime errors if the directory does not exist.

id!: number;
email!: string;
password!: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Defined isSignIn macro is never used

If sign-in enforcement is needed, apply the macro to relevant routes; otherwise, remove it to avoid unused code.

Comment on lines +84 to +88
const id = (
db
.query("SELECT id FROM jobs WHERE user_id = ? ORDER BY id DESC")
.get(user.id) as { id: number }
).id;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
const id = (
db
.query("SELECT id FROM jobs WHERE user_id = ? ORDER BY id DESC")
.get(user.id) as { id: number }
).id;
const {id} =
db
.query("SELECT id FROM jobs WHERE user_id = ? ORDER BY id DESC")
.get(user.id) as { id: number }
;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

})
.macro({
isSignIn(enabled: boolean) {
if (!enabled) return
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!enabled) return
if (!enabled) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

danmestas pushed a commit to danmestas/ConvertX-openAPI that referenced this pull request Jul 31, 2025
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.

2 participants