-
-
Notifications
You must be signed in to change notification settings - Fork 521
refactor: split main file to pages #310
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
Conversation
Reviewer's GuideThis 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 ProcesssequenceDiagram
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
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"
Class Diagram for Core Data StructuresclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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
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 }) => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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.
| const id = ( | ||
| db | ||
| .query("SELECT id FROM jobs WHERE user_id = ? ORDER BY id DESC") | ||
| .get(user.id) as { id: number } | ||
| ).id; |
There was a problem hiding this comment.
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)
| 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 } | |
| ; | |
Explanation
Object 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 |
There was a problem hiding this comment.
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)
| if (!enabled) return | |
| if (!enabled) { |
Explanation
It 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).
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:
Build: