Back to Guide
Project Structure
Learn about the clean, organized structure Bend creates for your projects.
Directory Overview
Bend follows a clean, scalable architecture that separates concerns and makes your codebase easy to navigate and maintain.
my-backend/
├── src/
├── config/ // Configuration files
├── controllers/ // Request handlers
├── models/ // Database models
├── routes/ // API routes
├── services/ // Business logic
├── middlewares/ // Custom middleware
├── utils/ // Helper functions
├── app.ts // Express/Fastify app
└── server.ts // Server entry point
├── .env
├── .gitignore
├── package.json
└── tsconfig.json
Layer Breakdown
Routes
Define your API endpoints and map them to controllers. Routes are the entry point for all HTTP requests.
// routes/users.ts
router.get('/users', userController.getAll)
router.post('/users', userController.create)
Controllers
Handle HTTP requests and responses. Controllers orchestrate the flow between routes and services.
// controllers/userController.ts
export const getAll = async (req, res) => {
const users = await userService.findAll()
res.json(users)
}
Services
Contain your business logic. Services interact with models and perform operations independent of HTTP.
// services/userService.ts
export const findAll = async () => {
return await User.find()
}
Models
Define your data structure and database schema. Models represent your application's data layer.
// models/User.ts
const userSchema = new Schema({
name: String,
email: String
})
Benefits of This Structure
- Separation of Concerns: Each layer has a single responsibility
- Testability: Easy to unit test services and controllers independently
- Scalability: Structure grows naturally as your application expands
- Maintainability: Easy to locate and modify specific functionality
