Folder architecture
The problem
Service businesses, like barbershops and salons, manage staff, products and billing in scattered tools. The idea was to bring it all together, with team invites and a monthly subscription.
Three layers with one-way dependencies: application is the product and knows nothing about Fastify or Prisma; http is the edge; infrastructure implements the interfaces and factories wire each use case.
Decisions and why
- application imports no framework
- Use cases depend on interfaces. Swapping Prisma, Stripe or the mailer means swapping an implementation, not rewriting rules.
- One factory per use case
- Dependency injection without a container: the factory shows exactly what each action uses.
- Zod in the validator
- One schema validates input, types the handler and generates Swagger.
- One error per refusal
- MaxBusinessLimitReachedError, EmailNotVerifiedError: the global handler maps each to the right status.