···11# Architectural Issues & Tasks
2233## High Priority (Stability & Performance)
44-- [ ] **Fix Critical Memory Usage in `FlacService`**
55- - **Location**: `src/flac/service.ts`
66- - **Issue**: `readMetadata` uses `fs.readFile` to load entire audio files (often 20-100MB) into memory just to read headers.
77- - **Task**: Implement partial reads (open file descriptor -> read buffer) to parse headers and Vorbis comments without loading the binary audio data.
44+- [ ] **Improve cover art logic**
55+ - **Issue**: Right now we base our cover art loading on musicbrainzReleaseId using cover art api, but we should cache it on server. and use multiple fallbacks
66+ - **Task**: Implement cover art fetching/fallbacking.
77+ 1. Loading from database / local cover art folder.
88+ - If we have releasegroupid - try fetching from coverart api;
99+ - Try parsing coverart from file.
1010+ 2. If not - use link to coverart api based on relaseId
1111+ 3. If not - use placeholder
81299-- [ ] **Implement Pagination for API Endpoints**
1010- - **Location**: `src/api.ts`
1111- - **Issue**: `getAlbumList` and `getAllSongs` fetch the entire database table in a single query.
1212- - **Task**: Add limit/offset or cursor-based pagination parameters to these endpoints and updated the database queries accordingly.
1313+ Cover art fetcher should be running on schedule to load this shit in background rather then block user flow.
1414+13151414-- [ ] **Optimize Library Synchronization**
1515- - **Location**: `src/file-parser.ts` & `src/sync-library.ts`
1616- - **Issue**: `readDirectory` and the sync stream load all file paths into memory before processing. `alreadyIndexed` loads the entire file table.
1717- - **Task**: Refactor to use a streaming directory iterator and batched database lookups to handle large libraries (50k+ songs) without OOM.
18161917## Medium Priority (Reliability & Maintainability)
2018- [ ] **Standardize API Error Handling**
···2220 - **Issue**: Inconsistent error handling. Some endpoints map errors explicitly, others rely on `runtime.runPromise` which may cause unhandled promise rejections or generic 500s for domain errors.
2321 - **Task**: Create a standardized wrapper or middleware that executes Effects and maps specific `TaggedError` types to HTTP status codes (404, 400, etc.).
24222525-- [ ] **Decouple API from Database Logic**
2626- - **Location**: `src/api.ts`
2727- - **Issue**: API handlers contain `db.query` and `db.select` calls directly ("Active Record" pattern in controllers).
2828- - **Task**: Extract database queries into a dedicated Repository layer or specific Service methods to enable unit testing without a database connection.
2323+- [ ] **Optimize Library Synchronization**
2424+ - **Location**: `src/file-parser.ts` & `src/sync-library.ts`
2525+ - **Issue**: `readDirectory` and the sync stream load all file paths into memory before processing. `alreadyIndexed` loads the entire file table.
2626+ - **Task**: Refactor to use a streaming directory iterator and batched database lookups to handle large libraries (50k+ songs) without OOM.
2727+29283029## Low Priority (Code Quality)
3130- [ ] **Refactor Effect <-> Elysia Adapter**
···3736 - **Location**: `src/index.ts`
3837 - **Issue**: Server port `3003` is hardcoded.
3938 - **Task**: Use Effect's `Config` module to make the port configurable via environment variables.
3939+4040+- [ ] **Implement Pagination for API Endpoints**
4141+ - **Location**: `src/api.ts`
4242+ - **Issue**: `getAlbumList` and `getAllSongs` fetch the entire database table in a single query.
4343+ - **Task**: Add limit/offset or cursor-based pagination parameters to these endpoints and updated the database queries accordingly.