-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.cursorrules
More file actions
320 lines (237 loc) · 10 KB
/
.cursorrules
File metadata and controls
320 lines (237 loc) · 10 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# Ababil Studio - Cursor Rules
## Project Overview
Ababil Studio is a modern, high-performance API development and testing platform built as a Postman alternative. It combines Rust's performance with Electron's cross-platform capabilities and React's modern UI.
**Key Features:**
- HTTP request execution (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS)
- Collection management with nested collections support
- Environment variables with `{{variable}}` syntax
- Request/response history
- Postman import/export support
- Dark mode support
## Architecture
### Technology Stack
- **Frontend**: React 19 + TypeScript + Tailwind CSS
- **Desktop Framework**: Electron (v39.2.7)
- **Backend Core**: Rust (reqwest for HTTP, tokio for async)
- **FFI Bridge**: koffi (Node.js FFI library)
- **UI Components**: shadcn/ui + Radix UI + Lucide React icons
- **Storage**: localStorage (browser-based persistence)
### Architecture Flow
```
React UI (Renderer Process)
↓ IPC via contextBridge
preload.js (exposes ababilAPI)
↓ ipcRenderer.invoke
main.js (Electron Main Process)
↓ koffi FFI
libababil_core.dylib/.so/.dll (Rust Library)
↓ reqwest HTTP client
HTTP Response
```
### Key Files
- `main.js` - Electron main process, handles IPC and loads Rust library
- `preload.js` - Exposes safe API to renderer via contextBridge
- `src/App.tsx` - Root React component
- `src/components/layout/HomeLayout.tsx` - Main application layout
- `src/services/httpClient.ts` - HTTP request service (calls native library)
- `src/services/storage.ts` - localStorage operations for requests/collections
- `src/services/environmentService.ts` - Environment variable management
- `core/src/lib.rs` - Rust core library (HTTP execution)
- `core/Cargo.toml` - Rust dependencies
## File Structure
### Source Code (`src/`)
- `components/` - React components organized by feature
- `layout/` - Layout components (HomeLayout, ResizableLayout)
- `sidebar/` - Sidebar with collections and requests
- `request/` - Request builder UI
- `response/` - Response viewer with syntax highlighting
- `environment/` - Environment management UI
- `header/` - Top header with environment selector
- `navigation/` - Left navigation menu
- `ui/` - Reusable UI components (shadcn/ui based)
- `services/` - Business logic services
- `httpClient.ts` - HTTP request execution
- `storage.ts` - localStorage CRUD operations
- `environmentService.ts` - Environment variable resolution
- `postmanService.ts` - Postman import/export
- `types/` - TypeScript type definitions
- `collection.ts` - SavedRequest, Collection interfaces
- `environment.ts` - Environment, EnvironmentVariable interfaces
- `http.ts` - HttpRequest, HttpResponse interfaces
- `electron.d.ts` - Electron API type definitions
- `utils/` - Utility functions
- `variableReplacer.ts` - Variable replacement in URLs/headers/body
- `helpers.ts` - General helper functions
- `constants.ts` - Application constants
### Rust Core (`core/`)
- `src/lib.rs` - Main library entry point, FFI exports
- `src/models/` - Rust data models matching TypeScript types
- `src/postman.rs` - Postman collection/environment parsing
## Key Patterns & Conventions
### TypeScript/React
- Use functional components with hooks
- State management via React useState/useEffect
- Type safety: All components and services are typed
- Component organization: Feature-based folder structure
- Styling: Tailwind CSS with shadcn/ui components
- Path aliases: `@/*` maps to root (configured in tsconfig.json)
### Data Flow
1. User interacts with UI (e.g., clicks Send)
2. Component calls service function (e.g., `makeHttpRequest`)
3. Service serializes request to JSON
4. IPC call to Electron main process via `window.ababilAPI`
5. Main process calls Rust library via koffi FFI
6. Rust executes HTTP request using reqwest
7. Response flows back through IPC to React component
8. Component updates state and renders response
### Storage Keys
- `ababil_requests` - Saved requests array
- `ababil_collections` - Collections array
- `ababil_environments` - Environments array
- `ababil_active_environment` - Active environment ID
### ID Generation
- Requests: `req_{timestamp}_{random}`
- Collections: `col_{timestamp}_{random}`
- Environments: Similar pattern
### Variable Replacement
- Syntax: `{{variable_name}}`
- Replaced in: URLs, headers, request body
- Service: `environmentService.replaceVariables()`
- Active environment determines which variables are used
### HTTP Request Format
Requests use Postman-compatible format:
```typescript
{
method: "GET" | "POST" | ...,
url: { raw: "https://..." },
header: [{ key: "...", value: "..." }],
body: { mode: "raw", raw: "..." },
auth: { type: "bearer", bearer: [...] }
}
```
### Rust FFI Functions
- `make_http_request(request_json: *const c_char) -> *mut c_char`
- `free_string(ptr: *mut c_char)` - Memory cleanup
- `parse_postman_collection(json: *const c_char) -> *mut c_char`
- `parse_postman_environment(json: *const c_char) -> *mut c_char`
## Development Workflow
### Building Rust Core
```bash
npm run build:rust # Build for current platform
npm run build:rust:mac # Build for macOS (both archs)
npm run copy:rust:mac # Copy built library to services/
```
### Running Development
```bash
npm start # Start React dev server (port 3000)
npm run start:dev # Start Electron with React dev server
npm run electron:dev # Start Electron in dev mode
```
### Building for Production
```bash
npm run build # Build React app
npm run electron:build # Build Electron app
npm run electron:build:mac # Build macOS distribution
```
### Native Library Paths
The app searches for `libababil_core.dylib` in:
1. `__dirname/services/libababil_core.dylib`
2. `process.cwd()/services/libababil_core.dylib`
3. `__dirname/../services/libababil_core.dylib`
4. `$HOME/Developer/ababil_studio/services/libababil_core.dylib`
## Component Patterns
### Layout Structure
```
HomeLayout
├── TopHeader (environment selector, settings)
├── LeftNav (collections/environments/settings tabs)
└── ResizableLayout
├── Sidebar (collections/requests tree)
└── MainContent (request builder + response viewer)
```
### State Management
- Local state via useState for component-specific data
- localStorage for persistence (via storage service)
- No global state management library (Redux/Zustand) - keep it simple
### Component Props Pattern
- Use TypeScript interfaces for props
- Destructure props in function signature
- Pass callbacks for parent-child communication
- Use optional props with defaults where appropriate
## Important Services
### httpClient.ts
- `makeHttpRequest(request: HttpRequest): Promise<HttpResponse>`
- `makeSimpleRequest(method, url, headers?, body?): Promise<HttpResponse>`
- `isNativeLibraryAvailable(): Promise<boolean>`
- `getNativeLibraryStatus(): Promise<Status>`
### storage.ts
- `saveRequest(request): SavedRequest`
- `loadRequests(): SavedRequest[]`
- `updateRequest(id, updates): SavedRequest | null`
- `deleteRequest(id): boolean`
- `getRequestsByCollection(collectionId?): SavedRequest[]`
- Similar functions for collections
### environmentService.ts
- `loadEnvironments(): Environment[]`
- `saveEnvironment(env): Environment`
- `getActiveEnvironment(): Environment | null`
- `setActiveEnvironment(id): void`
- `replaceVariables(text, environment): string`
## UI Component Library
### shadcn/ui Components Used
- Button, Input, Textarea, Select
- Dialog, Tabs, Card, Badge
- Label, Separator, Table, Tooltip
### Styling
- Tailwind CSS with custom color scheme
- CSS variables for theming (dark mode support)
- Responsive design with Tailwind breakpoints
- Custom CSS in `src/styles/` for specific layouts
## Error Handling
### HTTP Errors
- Status code 0 = Error occurred
- Error message in response.body
- Check `isSuccessResponse()` or `isErrorResponse()` helpers
### Native Library Errors
- Check `isNativeLibraryAvailable()` before making requests
- Handle null responses from FFI calls
- Log errors to console in main process
### Storage Errors
- Try-catch around localStorage operations
- Return empty arrays/objects on parse errors
- Graceful degradation if storage unavailable
## Testing & Quality
### TypeScript
- Strict mode enabled
- No implicit any
- Path aliases configured (`@/*`)
- React JSX transform enabled
### Code Style
- ESLint with react-app config
- Prettier (if configured)
- Consistent naming: camelCase for variables, PascalCase for components
## Common Tasks
### Adding a New HTTP Method
1. Update TypeScript types in `src/types/http.ts`
2. Update Rust handler in `core/src/lib.rs` (execute_request_from_struct)
3. Update UI method selector if needed
### Adding a New Collection Field
1. Update `Collection` interface in `src/types/collection.ts`
2. Update storage functions in `src/services/storage.ts`
3. Update UI components that display collections
### Adding Environment Variable Types
1. Update `EnvironmentVariable` interface in `src/types/environment.ts`
2. Update variable replacement logic if needed
3. Update UI for variable editing
## Notes for AI Assistants
- Always check if native library is available before making HTTP requests
- Use TypeScript types from `src/types/` for consistency
- Follow existing patterns for state management (local state + localStorage)
- Rust library must be built and copied to `services/` directory
- Environment variables use `{{variable}}` syntax
- Collections support nesting via `collections` array property
- Requests are linked to collections via `collectionId`
- Dark mode is detected via `prefers-color-scheme` media query
- IPC communication uses `window.ababilAPI` (exposed via preload.js)
- All HTTP requests go through Rust library for performance
Note : If new things update this page for future updates and alwayse try with bun