Skip to content

Refactor: Elysia best-practice service layer - #4

Draft
injoon5 wants to merge 5 commits into
mainfrom
cursor/elysia-service-refactor-3048
Draft

Refactor: Elysia best-practice service layer#4
injoon5 wants to merge 5 commits into
mainfrom
cursor/elysia-service-refactor-3048

Conversation

@injoon5

@injoon5 injoon5 commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary

Full Elysia best-practice alignment: feature modules, shared services, typed models, and a critical error-handling fix.

Structure

src/
  app.ts                    # onError first, then plugins + modules
  modules/{meta,school,classes,timetable,lunch,schedule}/
    index.ts   # Elysia controller (routes)
    service.ts # business logic
    model.ts   # schema re-exports
  shared/{school,neis}.ts
  schemas/{common,responses,mappers}.ts
  plugins/models.ts

Audit fixes

Item Fix
Feature folders src/modules/* per guide
handleRoute Removed — services throw; root onError handles
ApiErrorBody Static<typeof ApiErrorSchema>
SchoolSearchQuery Named schema for GET /school
Mapper casts Centralized in schemas/mappers.ts
Duplicate NEIS clients Single createNeisClient()
Service unit tests src/test/school-validation.ts
Error JSON regression ApiError.statushttpStatus; .onError must be registered before .use(modules)

Test plan

  • npm run build
  • npm test (school-validation + compare + yangjeong)
Open in Web Open in Cursor 

Move NEIS/Comcigan business logic out of app.ts into focused service
modules with a shared NEIS client factory. Query/response types derive from
Typebox schemas (SchoolQuery, composite query objects). Slim app.ts to
route wiring, model refs, and error handling. Tests use Static types from
response schemas.

Co-authored-by: Injoon Oh <injoon5@icloud.com>
@vercel

vercel Bot commented May 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
school-api Ready Ready Preview, Comment May 26, 2026 2:41pm

- Organize routes under src/modules/{meta,school,classes,timetable,lunch,schedule}
- Centralize NEIS mapping in schemas/mappers.ts; shared school/neis in src/shared/
- SchoolSearchQuery, ApiErrorBody from schema Static types; rename ApiError.status to httpStatus (Elysia bypass fix)
- modelsPlugin per module; register onError before .use(modules)
- Add school-validation unit test; remove handleRoute wrapper

Co-authored-by: Injoon Oh <injoon5@icloud.com>
Co-authored-by: Injoon Oh <injoon5@icloud.com>
Co-authored-by: Injoon Oh <injoon5@icloud.com>
Scalar needs servers in the spec to run Try-it requests. Add a relative
/current-host server, keep production and local entries, and enable
embedSpec so the spec (with servers) ships inline on /docs.

Co-authored-by: Injoon Oh <injoon5@icloud.com>
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