-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.cursorrules
More file actions
149 lines (106 loc) · 5.21 KB
/
.cursorrules
File metadata and controls
149 lines (106 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Zero In - AI Coding Agent Instructions
## Top Instructions
- Be extremely concise and sacrifice grammar for the sake of concision
- Following TDD when adding new features, ONE test → ONE implementation → repeat
- Avoid comments if code or function names are self-explanatory. Comment only for non-obvious logic.
## Project Overview
Zero In is a focus productivity tool with three platforms:
- **Browser Extension** (Chrome/Edge): Timer + website blocker using WXT framework (Vue 3, TypeScript)
- **Mobile App** (iOS/Android): React Native with Expo, native app blocking via Screen Time API (iOS) and UsageStats/Overlays (Android)
- **Firebase Backend**: Firestore for user data sync, Firebase Auth
This is a Yarn 4 monorepo with workspaces (`apps/*`, `packages/*`).
## Architecture Patterns
### Domain-Driven Design (Global)
The project follows DDD principles across all packages:
- **Domain Logic** (`src/domain/`): Pure business logic, framework-agnostic.
- Dependencies injected via constructor.
- `static createFake()` methods are MANDATORY for testing.
- NO platform-specific imports (e.g., no `chrome.*`, no `react-native`).
- **Infrastructure** (`src/infra/`): Platform adapters.
- format: `*Service` interface + `*Impl` or platform-specific implementation.
- `createFake()` methods for test isolation.
- **Entry Points/UI**:
- Extension: `apps/extension/src/entrypoints/`
- Mobile: `apps/mobile/app/`
### Shared Package (`@zero-in/shared`)
Located in `packages/shared/`, this package MUST be used for all logic shared between Extension and Mobile.
- **`domain/`**:
- `schedules/`: Scheduling logic (schema, serialization, validation).
- `time/`: `Time` class and helpers.
- `timer-based-blocking/`: Timer logic.
- **`infra/`**:
- `storage/`: Shared storage interfaces and Firebase implementations (`FirestoreAppStorage`).
- **`utils/`**: Shared helpers.
### Mobile App Structure (`apps/mobile`)
Expo-based React Native app:
- **Routing**: File-based routing in `app/`.
- **Modules**: Custom native modules in `modules/`.
- `modules/app-blocker`: Native implementation of app blocking (ScreenTime API / Android Native).
- **Domain/Infra**:
- Uses `@zero-in/shared` for core logic.
- `apps/mobile/domain/`: Mobile-specific domain logic not yet shared.
- `apps/mobile/infra/`: Mobile-specific adapters (e.g., `ReactNativeFirestoreAdapter`).
## Code Style & Conventions
### TypeScript
- **Strict Mode**: Enabled.
- **Explicit Types**: Prefer explicit types.
- **Async/Await**: properly await all promises.
- **Imports**:
- Extension: `@/*` -> `apps/extension/src/*`
- Shared: `@zero-in/shared/*` -> `packages/shared/src/*`
- Mobile: Relative imports or configured aliases.
### Dependency Injection (Strict)
All Domain Services MUST follow this pattern:
```typescript
export class MyService {
constructor(private deps: { dep1: Dep1; dep2: Dep2 }) {}
static createFake(overrides = {}) {
return new MyService({
dep1: new FakeDep1(),
dep2: new FakeDep2(),
...overrides
})
}
}
```
### Storage Service Pattern
All storage services implement `StorageService<T>`:
```typescript
export interface StorageService<T> {
get(): Promise<T | null>
save(data: T): Promise<void>
}
```
Implementations must handle serialization/deserialization internally.
## Testing Strategy
### Unit Tests
- **Location**: `*.spec.ts` alongside source files.
- **Tool**: Vitest.
- **Execution**: Run tests via terminal commands/scripts (e.g., `yarn test:unit`, `yarn test:integration`), NOT via VS Code Test Runner.
- **Mocks**: STRICTLY use `createFake()` implementations. NO MOCKING LIBRARIES (jest.mock, etc) for domain logic.
- **Timers**: Use `vi.useFakeTimers()` for time-dependent tests.
### Integration Tests
- **Location**: `*.integration.spec.ts`.
- **Environment**: Firebase Emulators.
- **Command**: `yarn test:integration` (in extension).
### E2E Tests (Extension)
- **Command**: `yarn build-and-e2e` (builds CI version then runs tests).
- **Note**: Always ensure the extension is built via `build:ci` (which sets emulator flags) before running `test:e2e`. The `build-and-e2e` script handles this safety.
## File Organization
### Extension (`apps/extension/src`)
- `domain/`: Business logic.
- `infra/`: Browser APIs (Storage, Alarms, Tabs).
- `entrypoints/`: UI (Popup, Options, Content Scripts).
- `service-workers/`: Background processes.
### Mobile (`apps/mobile`)
- `app/`: Expo Router pages.
- `modules/`: Native modules (Kotlin/Swift).
- `domain/`: Mobile-specific domain.
- `infra/`: React Native implementations of shared interfaces.
## Special Notes
1. **Shared Logic**: Logic should be moved to `@zero-in/shared` **only if** it is used (or expected to be used) by both Extension and Mobile. Platform-specific domain logic can stay in its respective package.
2. **No Direct Native Calls in Domain**: Domain code must never call `chrome.*` or `Module.*` directly. Wrap in an Interface in `domain/` and implement in `infra/`.
3. **Native Modules**: Changes to `modules/` require rebuilding the native app.
## Agent Behavior
- You are encouraged to set `SafeToAutoRun: true` for all read-only commands (ls, cat, grep, etc.) to minimize interruptions.
- NOTE: This file is symlinked by `.github/copilot-instructions.md`.