2026-02-10 06:43:07 +07:00
|
|
|
# AGENTS.md - Coding Guidelines for CLQMS Frontend
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
SvelteKit frontend for Clinical Laboratory Quality Management System. Uses Svelte 5 runes, TailwindCSS 4, DaisyUI, and Lucide icons.
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Commands
|
2026-02-10 06:43:07 +07:00
|
|
|
|
|
|
|
|
```bash
|
2026-02-24 06:12:17 +07:00
|
|
|
pnpm run dev # Development server
|
|
|
|
|
pnpm run build # Production build
|
|
|
|
|
pnpm run preview # Preview production build
|
|
|
|
|
pnpm run prepare # Sync SvelteKit
|
|
|
|
|
```
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
**No test framework yet.** When adding: use Vitest (`vitest run src/path/to/test.js`), Playwright for E2E.
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Code Style
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
- **ES Modules**: `import`/`export` (type: "module")
|
|
|
|
|
- **Semicolons**: Required
|
|
|
|
|
- **Quotes**: Single quotes
|
|
|
|
|
- **Indentation**: 2 spaces
|
|
|
|
|
- **Trailing commas**: In multi-line objects/arrays
|
|
|
|
|
- **JSDoc**: Document all exported functions
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Naming Conventions
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
- **Components**: PascalCase (`LoginForm.svelte`)
|
|
|
|
|
- **Files/Routes**: lowercase with hyphens (`+page.svelte`)
|
|
|
|
|
- **Variables**: camelCase (`isLoading`, `userName`)
|
|
|
|
|
- **Constants**: UPPER_SNAKE_CASE (`API_URL`)
|
|
|
|
|
- **Stores**: camelCase (`auth`, `config`)
|
|
|
|
|
- **Handlers**: prefix with `handle` (`handleSubmit`)
|
|
|
|
|
- **Form state**: `formLoading`, `formError`
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Imports Order
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
1. Svelte (`svelte`, `$app/*`)
|
|
|
|
|
2. `$lib/*` (stores, api, components, utils)
|
|
|
|
|
3. External libraries (`lucide-svelte`)
|
|
|
|
|
4. Relative imports (minimize, prefer `$lib`)
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Svelte 5 Components
|
2026-02-10 06:43:07 +07:00
|
|
|
|
|
|
|
|
```svelte
|
|
|
|
|
<script>
|
2026-02-24 06:12:17 +07:00
|
|
|
// 1. Imports
|
2026-02-10 06:43:07 +07:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { auth } from '$lib/stores/auth.js';
|
2026-02-24 06:12:17 +07:00
|
|
|
import { User } from 'lucide-svelte';
|
2026-02-20 13:51:54 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
// 2. Props with $bindable
|
|
|
|
|
let { open = $bindable(false), title = '', children } = $props();
|
2026-02-20 13:51:54 +07:00
|
|
|
|
2026-02-10 06:43:07 +07:00
|
|
|
// 3. State
|
|
|
|
|
let loading = $state(false);
|
2026-02-24 06:12:17 +07:00
|
|
|
let formData = $state({ name: '' });
|
2026-02-20 13:51:54 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
// 4. Derived
|
|
|
|
|
let isValid = $derived(formData.name.length > 0);
|
2026-02-20 13:51:54 +07:00
|
|
|
|
2026-02-10 06:43:07 +07:00
|
|
|
// 5. Effects
|
2026-02-20 13:51:54 +07:00
|
|
|
$effect(() => { /* side effects */ });
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
// 6. Handlers
|
|
|
|
|
function handleSubmit() { /* impl */ }
|
2026-02-10 06:43:07 +07:00
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## API Patterns
|
2026-02-10 06:43:07 +07:00
|
|
|
|
|
|
|
|
```javascript
|
2026-02-24 06:12:17 +07:00
|
|
|
// src/lib/api/client.js - Use these helpers
|
|
|
|
|
import { get, post, put, patch, del } from '$lib/api/client.js';
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
// Feature endpoints (with JSDoc)
|
2026-02-20 13:51:54 +07:00
|
|
|
export async function fetchItems(params = {}) {
|
|
|
|
|
const query = new URLSearchParams(params).toString();
|
|
|
|
|
return get(query ? `/api/items?${query}` : '/api/items');
|
2026-02-10 06:43:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function createItem(data) {
|
|
|
|
|
return post('/api/items', data);
|
|
|
|
|
}
|
2026-02-20 13:51:54 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
export async function updateItem(id, data) {
|
|
|
|
|
return patch(`/api/items/${id}`, data);
|
2026-02-20 13:51:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteItem(id) {
|
|
|
|
|
return del(`/api/items/${id}`);
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Store Patterns
|
2026-02-20 13:51:54 +07:00
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
import { writable } from 'svelte/store';
|
|
|
|
|
import { browser } from '$app/environment';
|
|
|
|
|
|
|
|
|
|
function createStore() {
|
|
|
|
|
const getInitialState = () => {
|
|
|
|
|
if (!browser) return { data: null };
|
2026-02-24 06:12:17 +07:00
|
|
|
return JSON.parse(localStorage.getItem('key'));
|
2026-02-20 13:51:54 +07:00
|
|
|
};
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
const { subscribe, set } = writable(getInitialState());
|
2026-02-20 13:51:54 +07:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
subscribe,
|
|
|
|
|
setData: (data) => {
|
|
|
|
|
if (browser) localStorage.setItem('key', JSON.stringify(data));
|
2026-02-24 06:12:17 +07:00
|
|
|
set(data);
|
2026-02-20 13:51:54 +07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Component Patterns
|
2026-02-20 13:51:54 +07:00
|
|
|
|
|
|
|
|
```svelte
|
2026-02-24 06:12:17 +07:00
|
|
|
<!-- Modal with $bindable props -->
|
|
|
|
|
<Modal bind:open={showModal} title="Edit" size="lg">
|
|
|
|
|
{#snippet children()}
|
|
|
|
|
<form>...</form>
|
|
|
|
|
{/snippet}
|
|
|
|
|
{#snippet footer()}
|
|
|
|
|
<button class="btn btn-primary">Save</button>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
|
|
<!-- Dialog with backdrop -->
|
|
|
|
|
<dialog class="modal modal-open">
|
2026-02-20 13:51:54 +07:00
|
|
|
<div class="modal-box">
|
|
|
|
|
{@render children?.()}
|
|
|
|
|
</div>
|
|
|
|
|
<form method="dialog" class="modal-backdrop" onclick={handleBackdropClick}>
|
|
|
|
|
<button>close</button>
|
|
|
|
|
</form>
|
|
|
|
|
</dialog>
|
2026-02-10 06:43:07 +07:00
|
|
|
```
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Error Handling
|
2026-02-10 06:43:07 +07:00
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
try {
|
2026-02-20 13:51:54 +07:00
|
|
|
const result = await api.fetchData();
|
2026-02-24 06:12:17 +07:00
|
|
|
success('Operation successful');
|
2026-02-10 06:43:07 +07:00
|
|
|
} catch (err) {
|
2026-02-20 13:51:54 +07:00
|
|
|
const message = err.message || 'An unexpected error occurred';
|
2026-02-24 06:12:17 +07:00
|
|
|
error(message);
|
2026-02-20 13:51:54 +07:00
|
|
|
console.error('Operation failed:', err);
|
2026-02-10 06:43:07 +07:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Form Patterns
|
2026-02-20 13:51:54 +07:00
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
let formLoading = $state(false);
|
|
|
|
|
let formError = $state('');
|
|
|
|
|
let formData = $state({ username: '', password: '' });
|
|
|
|
|
|
|
|
|
|
function validateForm() {
|
|
|
|
|
formError = '';
|
|
|
|
|
if (!formData.username.trim()) {
|
|
|
|
|
formError = 'Username is required';
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
|
if (!validateForm()) return;
|
|
|
|
|
formLoading = true;
|
|
|
|
|
try {
|
|
|
|
|
await api.submit(formData);
|
2026-02-24 06:12:17 +07:00
|
|
|
success('Success');
|
2026-02-20 13:51:54 +07:00
|
|
|
} catch (err) {
|
|
|
|
|
formError = err.message;
|
|
|
|
|
} finally {
|
|
|
|
|
formLoading = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Styling (DaisyUI + Tailwind)
|
2026-02-20 13:51:54 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
- **Components**: `btn`, `card`, `alert`, `input`, `navbar`, `modal`, `dropdown`
|
|
|
|
|
- **Colors**: `primary` (emerald), `secondary` (dark blue), `accent` (royal blue)
|
|
|
|
|
- **Sizes**: `btn-sm`, `input-sm`, `select-sm` for compact forms
|
|
|
|
|
- **Custom**: `.compact-y`, `.compact-p`, `.compact-input`
|
2026-02-20 13:51:54 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Authentication
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
- Check `$auth.isAuthenticated` in layout `onMount`
|
|
|
|
|
- Redirect to `/login` if unauthenticated using `goto('/login')`
|
|
|
|
|
- API client auto-redirects on 401
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## LocalStorage
|
2026-02-10 06:43:07 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
- Only access in browser: check `browser` from `$app/environment`
|
|
|
|
|
- Use descriptive keys: `clqms_username`, `auth_token`
|
2026-02-16 15:58:06 +07:00
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
## Project Structure
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
src/
|
|
|
|
|
lib/
|
|
|
|
|
api/ # API clients per feature
|
|
|
|
|
stores/ # Svelte stores
|
|
|
|
|
components/ # Reusable components
|
|
|
|
|
utils/ # Utilities (toast, helpers)
|
|
|
|
|
routes/ # SvelteKit routes
|
|
|
|
|
(app)/ # Route groups (protected)
|
|
|
|
|
login/
|
|
|
|
|
dashboard/
|
|
|
|
|
```
|
2026-02-16 15:58:06 +07:00
|
|
|
|
2026-02-10 06:43:07 +07:00
|
|
|
## Important Notes
|
|
|
|
|
|
2026-02-24 06:12:17 +07:00
|
|
|
- Uses Svelte 5: `$props`, `$state`, `$derived`, `$effect`, `$bindable`
|
2026-02-20 13:51:54 +07:00
|
|
|
- Static adapter configured for static export
|
|
|
|
|
- Runtime config allows API URL changes without rebuild
|
2026-02-24 06:12:17 +07:00
|
|
|
- API proxy: `/api` → `http://localhost:8000` (dev)
|
|
|
|
|
- API Docs: https://clqms01-api.services-summit.my.id/swagger/
|