Skip to content

Commit a8da5b4

Browse files
authored
Merge pull request #3144 from AtCoder-NoviSteps/#3143
feat: Introduce claude code and setting files (#3143)
2 parents 434cbe7 + 7bb5ee4 commit a8da5b4

File tree

10 files changed

+550
-3
lines changed

10 files changed

+550
-3
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.ts'
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/**/*.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

.devcontainer/devcontainer.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"workspaceFolder": "/usr/src/app",
77
// Use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
88
"dockerComposeFile": ["../compose.yaml"],
9-
"mounts": ["source=${localEnv:HOME}/.ssh,target=/home/node/.ssh,type=bind,consistency=cached"],
9+
"mounts": [
10+
"source=${localEnv:HOME}/.ssh,target=/home/node/.ssh,type=bind,consistency=cached",
11+
"source=${localEnv:HOME}/.claude,target=/home/node/.claude,type=bind,consistency=cached"
12+
],
1013
// Features to add to the dev container. More info: https://containers.dev/features.
1114
// "features": {},
1215
//
@@ -18,8 +21,11 @@
1821
],
1922
// "shutdownAction": "none",
2023
//
24+
// Use 'initializeCommand' to run commands before the container is created.
25+
"initializeCommand": "mkdir -p ~/.claude",
26+
//
2127
// Use 'postCreateCommand' to run commands after the container is created.
22-
// "postCreateCommand": "yarn install",
28+
"postCreateCommand": "npm install -g @anthropic-ai/claude-code && pnpm install",
2329
//
2430
// Configure tool-specific properties.
2531
"customizations": {
@@ -72,6 +78,7 @@
7278
"svelte.enable-ts-plugin": true
7379
},
7480
"extensions": [
81+
"anthropic.claude-code",
7582
"bradlc.vscode-tailwindcss",
7683
"christian-kohler.path-intellisense",
7784
"csstools.postcss",
@@ -85,6 +92,10 @@
8592
"vscode-icons-team.vscode-icons"
8693
]
8794
}
95+
},
96+
"containerEnv": {
97+
"NODE_OPTIONS": "--max-old-space-size=4096 --dns-result-order=ipv4first",
98+
"CLAUDE_CONFIG_DIR": "/home/node/.claude"
8899
}
89100
//
90101
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.

AGENTS.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 coverage # Report test coverage
18+
pnpm lint # ESLint check
19+
pnpm format # Prettier format
20+
pnpm check # Svelte type check
21+
pnpm exec prisma generate # Generate Prisma client
22+
pnpm exec prisma migrate dev --name # Create migration (with description)
23+
pnpm db:seed # Seed database
24+
```
25+
26+
## Project Structure
27+
28+
```md
29+
src/routes/ # SvelteKit file-based routing
30+
src/lib/
31+
├── actions/ # SvelteKit actions
32+
├── clients/ # External API clients (AtCoder Problems, AOJ)
33+
├── components/ # Svelte components
34+
├── constants/
35+
├── server/ # Server-only (auth.ts, database.ts)
36+
├── services/ # Business logic
37+
├── stores/ # Svelte stores (.svelte.ts with Runes)
38+
├── types/ # TypeScript types
39+
├── utils/ # Pure utility functions
40+
└── zod/ # Validation schemas
41+
src/test/ # Unit tests (mirrors src/lib/)
42+
tests/ # E2E tests (Playwright)
43+
prisma/schema.prisma # Database schema
44+
```
45+
46+
## Key Conventions
47+
48+
- **Svelte 5 Runes**: Use `$props()`, `$state()`, `$derived()` in all new components
49+
- **Server data**: `+page.server.ts``+page.svelte` via `data` prop
50+
- **Forms**: Superforms + Zod validation
51+
- **Tests**: Factories via `@quramy/prisma-fabbrica`, HTTP mocking via Nock
52+
- **Naming**: `camelCase` variables, `PascalCase` types/components, `snake_case` files/routes, `kebab-case` directories
53+
- **Pre-commit**: Lefthook runs Prettier + ESLint (bypass: `LEFTHOOK=0 git commit`)
54+
55+
## References
56+
57+
- See `package.json` for versions and scripts
58+
- See `prisma/schema.prisma` for database models
59+
- See `docs/guides/` for detailed documentation

CLAUDE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CLAUDE.md
2+
3+
@AGENTS.md
4+
5+
## Claude Code Specific
6+
7+
- Path-specific rules are in `.claude/rules/`
8+
- Run `pnpm format` before committing
9+
- When uncertain about project conventions, see existing code in `src/lib/`

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ RUN apt-get update \
1212
ENV NODE_PATH=/node_modules
1313
ENV PATH=$PATH:/node_modules/.bin
1414

15-
RUN pnpm install --frozen-lockfile
15+
RUN pnpm install
1616

1717
CMD ["pnpm", "dev"]

0 commit comments

Comments
 (0)