Skip to content

Commit 9b0dc1a

Browse files
committed
docs: Simplify CLAUDE.md and restructure settings (#3143)
1 parent 82171f1 commit 9b0dc1a

File tree

7 files changed

+262
-307
lines changed

7 files changed

+262
-307
lines changed

.claude/rules/auth.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
description: Authentication rules
3+
globs:
4+
- 'src/lib/server/auth/**'
5+
- 'src/routes/(auth)/**'
6+
- 'src/hooks.server.ts'
7+
---
8+
9+
# Authentication
10+
11+
## Lucia v2
12+
13+
- Session validation in `src/hooks.server.ts`
14+
- Session data attached to `event.locals.user`
15+
- User properties: `id`, `name`, `role`, `atcoder_name`, `is_validated`
16+
17+
## Protected Routes
18+
19+
- Validate `event.locals.user` in `+page.server.ts` load functions
20+
- Redirect unauthenticated users to `/login`
21+
- Validate `role` for admin-only routes
22+
23+
## Form Validation
24+
25+
- Use Superforms + Zod for auth forms
26+
- Server-side validation is authoritative
27+
- Return structured error responses
28+
29+
## Key Files
30+
31+
- `src/lib/server/auth.ts`: Lucia configuration
32+
- `src/hooks.server.ts`: Global request handler
33+
- `prisma/schema.prisma`: User, Session, Key models
34+
35+
## Security
36+
37+
- Never expose session secrets in client code
38+
- Use HTTPS in production
39+
- Validate all user inputs server-side

.claude/rules/prisma-db.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
description: Prisma and database rules
3+
globs:
4+
- 'prisma/**'
5+
- 'src/lib/server/**'
6+
- 'src/lib/services/**'
7+
---
8+
9+
# Prisma & Database
10+
11+
## Schema Changes
12+
13+
1. Edit `prisma/schema.prisma`
14+
2. Run `pnpm exec prisma migrate dev --name <description>` to create migration
15+
3. Run `pnpm exec prisma generate` to update client (auto-runs after migrate)
16+
17+
## Naming
18+
19+
- Model names: `PascalCase` (e.g., `User`, `TaskAnswer`)
20+
- Field names: `camelCase` (preferred) or `snake_case` (legacy)
21+
- Relation fields: Descriptive names matching the relation
22+
23+
## Key Models
24+
25+
- `User`: User accounts with AtCoder validation status
26+
- `Task`: Tasks with difficulty grades (Q11-D6)
27+
- `TaskAnswer`: User submission status per task
28+
- `WorkBook`: task collections
29+
- `Tag` / `TaskTag`: task categorization
30+
31+
## Server-Only Code
32+
33+
- Import database client only in `src/lib/server/`
34+
- Use `$lib/server/database` for Prisma client access
35+
- Never import server code in client components
36+
37+
## Transactions
38+
39+
- Use `prisma.$transaction()` for multi-step operations
40+
- Handle errors with try-catch and proper rollback

.claude/rules/svelte-components.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
description: Svelte component development rules
3+
globs:
4+
- 'src/**/*.svelte'
5+
- 'src/lib/components/**'
6+
- 'src/lib/stores/**/*.svelte.ts'
7+
---
8+
9+
# Svelte Components
10+
11+
## Runes Mode (Required)
12+
13+
- Use `$props()` for component props
14+
- Use `$state()` for reactive state
15+
- Use `$derived()` for computed values
16+
- Use `$effect()` for side effects
17+
18+
## Props Pattern
19+
20+
```svelte
21+
<script lang="ts">
22+
interface Props {
23+
title: string;
24+
count?: number;
25+
}
26+
27+
let { title, count = 0 }: Props = $props();
28+
</script>
29+
```
30+
31+
## Stores
32+
33+
- Place store files in `src/lib/stores/` with `.svelte.ts` extension
34+
- Use class-based stores with `$state()` for internal state
35+
- Export singleton instances
36+
37+
## Flowbite Svelte
38+
39+
- Import components from `flowbite-svelte`
40+
- Use Tailwind CSS v4 utility classes
41+
- Dark mode: Use `dark:` prefix for dark mode variants
42+
43+
## File Naming
44+
45+
- Components: `PascalCase.svelte`
46+
- Stores: `snake_case.svelte.ts`

.claude/rules/testing.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
description: Testing rules and patterns
3+
globs:
4+
- '**/*.test.ts'
5+
- '**/*.spec.ts'
6+
- 'tests/**'
7+
- 'src/test/**'
8+
---
9+
10+
# Testing
11+
12+
## Test Types
13+
14+
| Type | Tool | Location | Run Command |
15+
| ----------- | ---------- | ------------------ | ----------------------- |
16+
| Unit | Vitest | `src/**/*.test.ts` | `pnpm test:unit` |
17+
| Integration | Vitest | `src/test/` | `pnpm test:unit` |
18+
| E2E | Playwright | `tests/*.test.ts` | `pnpm test:integration` |
19+
20+
## Unit Tests
21+
22+
- Place tests in `src/test/` mirroring `src/lib/` structure
23+
- Use `@quramy/prisma-fabbrica` for test data factories
24+
- Mock external APIs with Nock
25+
26+
## E2E Tests
27+
28+
- Place in `tests/` directory
29+
- Use Playwright test utilities
30+
- Test user flows, not implementation details
31+
32+
## Patterns
33+
34+
```typescript
35+
import { describe, test, expect, vi } from 'vitest';
36+
37+
describe('functionName', () => {
38+
test('expects to do something', () => {
39+
// Arrange
40+
// Act
41+
// Assert
42+
});
43+
});
44+
```
45+
46+
## Coverage
47+
48+
- Run `pnpm coverage` for coverage report
49+
- Target: 80% lines, 70% branches
50+
51+
## HTTP Mocking
52+
53+
- Use Nock for mocking external HTTP calls
54+
- See `src/test/lib/clients/` for examples

AGENTS.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# AtCoder NoviSteps
2+
3+
A web service for tracking submissions on AtCoder and other competitive programming sites, which are graded by difficulty (Q11-D6).
4+
5+
## Tech Stack
6+
7+
SvelteKit 2 + Svelte 5 (Runes) + TypeScript | PostgreSQL + Prisma | Flowbite Svelte + Tailwind 4 | Vitest + Playwright
8+
9+
## Commands
10+
11+
```bash
12+
pnpm dev # Start dev server (localhost:5174)
13+
pnpm build # Build for production
14+
pnpm test # Run all tests
15+
pnpm test:unit # Vitest unit tests
16+
pnpm test:integration # Playwright E2E tests
17+
pnpm lint # ESLint check
18+
pnpm format # Prettier format
19+
pnpm check # Svelte type check
20+
pnpm exec prisma generate # Generate Prisma client
21+
pnpm exec prisma migrate dev --name # Create migration (with description)
22+
pnpm db:seed # Seed database
23+
```
24+
25+
## Project Structure
26+
27+
```md
28+
src/routes/ # SvelteKit file-based routing
29+
src/lib/
30+
├── actions/ # SvelteKit actions
31+
├── clients/ # External API clients (AtCoder Problems, AOJ)
32+
├── components/ # Svelte components
33+
├── constants/
34+
├── server/ # Server-only (auth.ts, database.ts)
35+
├── services/ # Business logic
36+
├── stores/ # Svelte stores (.svelte.ts with Runes)
37+
├── types/ # TypeScript types
38+
├── utils/ # Pure utility functions
39+
└── zod/ # Validation schemas
40+
src/test/ # Unit tests (mirrors src/lib/)
41+
tests/ # E2E tests (Playwright)
42+
prisma/schema.prisma # Database schema
43+
```
44+
45+
## Key Conventions
46+
47+
- **Svelte 5 Runes**: Use `$props()`, `$state()`, `$derived()` in all new components
48+
- **Server data**: `+page.server.ts``+page.svelte` via `data` prop
49+
- **Forms**: Superforms + Zod validation
50+
- **Tests**: Factories via `@quramy/prisma-fabbrica`, HTTP mocking via Nock
51+
- **Naming**: `camelCase` variables, `PascalCase` types/components, `snake_case` files/routes, `kebab-case` directories
52+
- **Pre-commit**: Lefthook runs Prettier + ESLint (bypass: `LEFTHOOK=0 git commit`)
53+
54+
## References
55+
56+
- See `package.json` for versions and scripts
57+
- See `prisma/schema.prisma` for database models
58+
- See `docs/guides/` for detailed documentation

0 commit comments

Comments
 (0)