Cursor rule
.cursor/rules/astro-component-structure.mdcAstro component structure and organization best practices
Cursor rules
Quality
58/100
Scores the file, not the repository.Length
378 words
9 headings · 3 code blocksRepository
0
— · pushed 262 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Astro Component Structure78## Standard Component Structure910Follow this order for Astro component sections:1112```astro13---14// 1. Imports first15import { SomeService } from '../services/someService';16import type { ComponentProps } from '../types/component';1718// 2. Interface definitions19interface Props {20 symbol: string;21 forceRefresh?: boolean;22}2324// 3. Props destructuring25const { symbol, forceRefresh = false } = Astro.props;2627// 4. Runtime/environment setup28const db = (Astro.locals.runtime?.env?.DB as D1Database) || null;2930// 5. Data fetching and business logic31let data: { items: any[]; error?: string } = { items: [] };3233if (db) {34 try {35 const service = SomeService.getInstance(db);36 const items = await service.fetchData(symbol, forceRefresh);37 data = { items };38 } catch (err) {39 data = { items: [], error: err instanceof Error ? err.message : 'Error' };40 }41}42---4344<!-- 6. HTML template -->45<div class="component-container">46 <!-- Component content here -->47</div>4849<!-- 7. Scoped styles -->50<style>51 .component-container {52 /* Styles here */53 }54</style>5556<!-- 8. Client-side scripts (only when necessary) -->57<script>58 // Minimal client-side enhancement only59</script>60```6162## Component Best Practices6364### Props Interface65- Always define a `Props` interface for type safety66- Use optional properties with defaults where appropriate67- Keep props simple and focused6869### Data Structure70- Use consistent data structure pattern: `{ items: any[]; error?: string }`71- Separate concerns: one data object per logical data source72- Always include error states7374### Template Patterns75- Use conditional rendering with ternary operators76- Provide meaningful fallbacks for empty states77- Keep templates readable with proper indentation7879### Error Handling in Templates80```astro81<div>82 {data.error ? (83 <p class="text-red-500">Error: {data.error}</p>84 ) : data.items.length > 0 ? (85 <div>86 {data.items.map((item) => (87 <div class="item">{item.name}</div>88 ))}89 </div>90 ) : (91 <p class="text-gray-500">No data available</p>92 )}93</div>94```9596## File Naming97- Use snake_case for component files (following project convention)98- Be descriptive: `historical_data_view.astro` not `history.astro`99- Group related components in appropriate directories100101## Import Organization102```astro103---104// 1. External libraries105import { z } from 'zod';106107// 2. Internal services108import { OptionsService } from '../services/optionsService';109110// 3. Internal utilities111import { formatDate } from '../utils/dateUtils';112113// 4. Internal components114import SearchForm from './searchForm.astro';115116// 5. Types (last)117import type { OptionData } from '../types/option';118---119```
Also in sferg989/fergfo.om
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| sferg989/fergfo.om.cursor/rules/astro-database-integration.mdc · 0 | Cursor rules | database | 50/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-error-handling.mdc · 0 | Cursor rules | styledatabaseui | 58/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-performance-patterns.mdc · 0 | Cursor rules | buildstyledatabaseperformance | 62/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/astro-ssr-patterns.mdc · 0 | Cursor rules | style | 49/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/ts-typecheck.mdc · 0 | Cursor rules | do-not | 23/100 | 3 days ago | |
| sferg989/fergfo.om.cursor/rules/ts.mdc · 0 | Cursor rules | styletypesdo-notdocs | 55/100 | 3 days ago | |
| sferg989/fergfo.om.cursorrules · 0 | .cursorrules | do-not | 49/100 | 3 days ago | |
| sferg989/fergfo.omCLAUDE.md · 0 | CLAUDE.md | setupbuildteststyle+7 | 89/100 | 3 days ago |
Diff against .cursor/rules/astro-database-integration.mdc Diff against .cursor/rules/astro-error-handling.mdc Diff against .cursor/rules/astro-performance-patterns.mdc Diff against .cursor/rules/astro-ssr-patterns.mdc Diff against .cursor/rules/ts-typecheck.mdc Diff against .cursor/rules/ts.mdc Diff against .cursorrules Diff against CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
