- Express.js - Fast, unopinionated web framework
- TypeScript - Type safety and modern JavaScript features
- Prisma ORM - Modern database toolkit
- Layered Architecture - Clean separation of concerns (Controllers, Services, Repositories)
- Middleware Support - Authentication, validation, error handling
- Environment Variables - Configuration management with dotenv
- Code Quality - ESLint, Prettier, Husky pre-commit hooks
- Security - Helmet, CORS, rate limiting
- Logging - Morgan HTTP request logger
src/
├── app.ts # Express app configuration
├── server.ts # Server entry point
├── common/ # Shared constants, enums, responses
├── config/ # Configuration files (database, env)
├── controllers/ # Request handlers
├── middlewares/ # Custom middleware (auth, validation, error)
├── repositories/ # Database access layer
├── routes/ # API route definitions
├── services/ # Business logic layer
├── types/ # TypeScript type definitions
└── utils/ # Helper functions
- Clone the repository
git clone <your-repo-url> cd <your-prj>
- Install dependencies
npm install
- Setup environment variables
# Create .env file cp .env.example .env # Edit .env with your configuration DATABASE_URL="postgresql://user:password@localhost:5432/mydb" PORT=3000 NODE_ENV=development
- Setup Prisma
# Generate Prisma Client npm run db:generate # Run migrations npm run db:migrate # (Optional) Open Prisma Studio npm run db:studio
Development mode
npm run dev
Build for production
npm run build npm start
Linting and formatting
npm run lint npm run lint:fix npm run format
This boilerplate includes a simple User API example:
Endpoints:
GET /api/users- Get all usersGET /api/users/:id- Get user by IDPOST /api/users- Create new userPUT /api/users/:id- Update userDELETE /api/users/:id- Delete user
Architecture Flow:
Request → Route → Middleware → Controller → Service → Repository → Database
↓
Response ← Controller ← Service ← Repository ← Database
- Define types in
src/types/ - Create repository in
src/repositories/for database operations - Create service in
src/services/for business logic - Create controller in
src/controllers/for request handling - Define routes in
src/routes/ - Add middleware if needed in
src/middlewares/ - Register routes in
src/app.ts
- Node.js v18+
- Express.js v5
- TypeScript v5
- Prisma ORM v5
- Zod (Validation)
- JWT (Authentication)
- Helmet (Security)
- Morgan (Logging)
**Happy Coding! **