300-angular-services

Angular service guidelines for organizing shared application logic and communication with APIs.

In plain words
What is it for?
Creating application-wide services, validating data, calling APIs, and updating a separate state store after successful operations.
Why use it?
They help prevent components from becoming overloaded and keep business rules separate from stored application state.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/jrpribs/smarterstarter/300-angular-services
Clone the repo
git clone --depth 1 https://github.com/JrPribs/SmarterStarter

Made for: Cursor.

Per session 4 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,299 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00004 $0.02299
Opus 5 $0.00002 $0.01149
Sonnet 5 $0.00001 $0.00460
Haiku 4.5 $0.00000 $0.00230

Measured 2d ago against content hash a3b9b1465e5b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

300-angular-services scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/300-angular-services.mdc · 381 lines

How it starts

The opening of the file, as written. The whole thing — 381 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Angular Services Best Practices

  • Injectable Services: Always use the @Injectable() decorator with providedIn: 'root' for singleton services.
@Injectable({
  providedIn: 'root'
})
export class DataService {
  // Service implementation
}
  • State Management Role: Services should act as mediators between components and global state. They should contain business logic but not store state themselves.
@Injectable({
  providedIn: 'root'
})
export class OrderService {
  constructor(private orderStore: OrderStore, private http: HttpClient) {}
  
  // Handle business logic and API communication before updating state
  submitOrder(orderData: OrderData): Observable<Order> {
    // Validate data
    if (!this.validateOrder(orderData)) {
      return throwError(() => new Error('Invalid order data'));
    }
    
    // Call API
    return this.http.post<Order>('/api/orders', orderData).pipe(
      tap(newOrder => {
        // Update store on success
        this.orderStore.addOrder(newOrder);
      })
    );
  }
  
  private validateOrder(order: OrderData): boolean {
    // Business logic validation
    return !!order.items.length && !!order.shippingAddress;
  }
}
  • Stateless Services: Services should be stateless and not maintain their own state - delegate state management to stores.
// ❌ AVOID: Service with internal state
@Injectable({ providedIn: 'root' })
export class BadCartService {
  private items: CartItem[] = []; // Don't store state here
  
  addItem(item: CartItem): void {
    this.items.push(item); // State in service is bad
  }
}

// ✅ GOOD: Stateless service that updates store
@Injectable({ providedIn: 'root' })
export class GoodCartService {
  constructor(private cartStore: CartStore) {}
  
  addItem(item: CartItem): void {
    // Business logic, validation, etc.
    if (!item.quantity) item.quantity = 1;
    
    // Update state in store, not service
    this.cartStore.addItem(item);
  }
}
  • Business Logic: Place all business logic in services, not in components or stores.
@Injectable({
  providedIn: 'root'
})
export class PaymentService {
  constructor(
    private paymentStore: PaymentStore,
    private http: HttpClient,
    private authService: AuthService
  ) {}
  
  processPayment(paymentInfo: PaymentInfo): Observable<PaymentResult> {
    // Business logic
    const enrichedPayment = this.enrichPaymentData(paymentInfo);
    
    // Start processing - update UI state
    this.paymentStore.setProcessing(true);
    
    // Call API
    return this.http.post<PaymentResult>('/api/payments', enrichedPayment).pipe(
      tap(result => {
        if (result.success) {
          // Update multiple states based on business rules
          this.paymentStore.addPayment(result);
        } else {
          this.paymentStore.setError(result.error);
        }
      }),
      finalize(() => {
        this.paymentStore.setProcessing(false);
      })
    );
  }
  
  private enrichPaymentData(paymentInfo: PaymentInfo): EnrichedPaymentInfo {
    // Complex business logic
    return {
      ...paymentInfo,
      userId: this.authService.getCurrentUserId(),
      timestamp: new Date().toISOString(),
      // Add other derived properties
    };
  }
}
  • Signal/Observable Interop: Use toSignal() and toObservable() for interop between RxJS observables and signals.
@Injectable({
  providedIn: 'root'
})
export class ProductService {
  constructor(
    private http: HttpClient,
    private productStore: ProductStore
  ) {}

  // Load products and update store
  loadProducts(): Observable<Product[]> {
    return this.http.get<Product[]>('/api/products').pipe(
      tap(products => {
        this.productStore.setProducts(products);
      })
    );
  }
  
  // Perform business logic before updating store
  addProduct(product: Product): Observable<Product> {
    // Enrichment and validation
    const enrichedProduct = this.prepareProductData(product);
    
    return this.http.post<Product>('/api/products', enrichedProduct).pipe(
      tap(newProduct => {
        this.productStore.addProduct(newProduct);
      })
    );
  }
  
  private prepareProductData(product: Product): Product {
    // Business logic to prepare data
    return {
      ...product,
      createdAt: new Date().toISOString(),
      // Other transformations
    };
  }
}

Read the full file on GitHub · 381 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 381 lines · 4 tokens per session scan A a3b9b1465e5b

Subscribe to this mod's changes

300-angular-services is a cursor rule published in the GitHub repository JrPribs/SmarterStarter (2 stars, last pushed 1y ago), licensed MIT. It adds 4 tokens to every session and 2,299 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.