Hi everyone,
I’m currently working on a serverless project using the Serverless Framework with TypeScript, and I’m looking for advice and best practices on how to organize the project’s structure and architecture.
Here are some key points about the project:
Project Overview
- Serverless Framework: I plan to deploy all my infrastructure as code.
- TypeScript: I’m using TypeScript for type safety and code structure.
- Prisma ORM: I’ll be using Prisma to interact with a centralized database, as all parts of the system will share this same database.
Questions I Need Help With
1.Services Organization:
- Should I split my project into multiple services (each handling a specific domain of the business logic, e.g.,
user-management
,inventory
, etc.)? - Or should I keep everything within a single service and organize by domains (e.g.,
src/modules/<domain>
)?
I’m interested in the trade-offs between these two approaches in terms of scalability, maintainability, and overall best practices.
2.Prisma ORM Centralization:
- Given that all services or domains will need to interact with the same database, is it better to centralize Prisma (e.g., as a shared layer), or should I create individual Prisma instances for each domain/module/service?
- What’s the best way to manage Prisma with Serverless functions to ensure database connection efficiency and reuse the Prisma client across services if they are separated?
3.Directory Structure:
- If I go with a single service approach, what would be the most effective directory structure for organizing modules/domains?
- If I opt for multiple services, how should I structure those services to maintain code reuse, especially for common utilities like Prisma, middlewares, and error handling?
Current Setup
- I’m considering centralizing Prisma since all parts of the system will interact with the same database.
- I’ve started building the system with multiple modules (domains), but they’re all within one service for now.
Any advice on how to structure the project for clean separation of concerns, scalability, and ease of maintenance would be greatly appreciated! If you’ve worked on similar setups or have any best practices to share for a TypeScript and Prisma-based serverless app, I’d love to hear your thoughts.
Thank you in advance for your help!