agentleFS
jhl-labsjhl-labs/vibe-project/.cursor/rules/architecture.mdc

vibe-project / rules

Cursor rule2 starsChanged 10 months agoMITView on GitHub

Clean Architecture rules

The file

Files
architecture.mdc
---
description: Clean Architecture rules
globs: ["**/domain/**", "**/application/**", "**/infrastructure/**", "**/presentation/**", "**/shared/**"]
alwaysApply: false
---

# Clean Architecture Rules

## Layer Structure

```
src/
├── domain/           # Core business logic (PURE)
├── application/      # Use cases, orchestration
├── infrastructure/   # External services, DB
└── presentation/     # HTTP, API, UI
```

## Dependency Rules (CRITICAL)

```
Presentation → Application → Domain
                    ↓
              Infrastructure
```

- Domain has NO external dependencies
- Application depends only on Domain
- Infrastructure implements Domain interfaces
- Presentation calls Application use cases

## Domain Layer

```typescript
// Entity - pure business logic
export class User {
  private constructor(private props: UserProps) {}

  static create(props: CreateUserProps): User {
    // Validation and business rules
    return new User({ ...props, id: generateId() });
  }

  // Business methods
  deactivate(): User {
    if (!this.isActive) throw new Error('Already inactive');
    return new User({ ...this.props, status: 'inactive' });
  }
}

// Repository interface (port)
export interface UserRepository {
  findById(id: string): Promise<User | null>;
  save(user: User): Promise<User>;
}
```

## Application Layer

```typescript
// Use case - orchestrates domain logic
export class CreateUserUseCase {
  constructor(
    private userRepo: UserRepository,
    private emailService: EmailService,
  ) {}

  async execute(input: CreateUserInput): Promise<CreateUserOutput> {
    const user = User.create(input);
    await this.userRepo.save(user);
    await this.emailService.sendWelcome(user.email);
    return { id: user.id };
  }
}
```

## Infrastructure Layer

```typescript
// Repository implementation (adapter)
export class PrismaUserRepository implements UserRepository {
  constructor(private prisma: PrismaClient) {}

  async findById(id: string): Promise<User | null> {
    const data = await this.prisma.user.findUnique({ where: { id } });
    return data ? this.toDomain(data) : null;
  }
}
```

## Presentation Layer

```typescript
// Controller/Route - thin, delegates to use case
router.post('/users', async (req, res) => {
  const result = await createUserUseCase.execute(req.body);
  res.status(201).json(result);
});
```

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.