Project Structure
A well-organized project structure makes applications easier to develop, maintain, and scale. Bejibun follows a convention-driven architecture that provides a predictable layout for application code. Whether you’re working on a personal project or collaborating with a large team, understanding the project structure will help you navigate the framework more efficiently. This guide explains the purpose of each directory and how the different parts of a Bejibun application work together.Overview
A freshly created Bejibun application may look similar to the following:The app Directory
The app directory contains the primary application code.
Controllers
Controllers handle incoming HTTP requests.- Processing requests
- Returning responses
- Calling services
- Coordinating application flow
Models
Models represent database entities.- Database interaction
- Relationships
- Query scopes
- Data serialization
Middleware
Middleware executes before or after a request reaches a controller.- Authentication
- Authorization
- Logging
- Rate limiting
- Request transformation
Validators
Validators define rules for incoming data.Services
Services contain business logic.Jobs
Jobs represent background tasks.- Email delivery
- Notifications
- Data processing
- Report generation
Events
Events describe actions that occur within the application.Listeners
Listeners respond to events.Policies
Policies define authorization rules.The routes Directory
The routes directory defines application endpoints.
The config Directory
The config directory stores framework and application configuration.
The database Directory
Database-related resources are stored here.
Migrations
Schema definitions live inside migrations.Seeders
Seeders populate the database with data.Factories
Factories generate realistic testing data.The bootstrap Directory
The bootstrap directory is responsible for starting the application.
- Framework initialization
- Service registration
- Application startup
- Dependency loading
The public Directory
Publicly accessible assets are stored here.
- Images
- Icons
- Static assets
- Generated documentation
The storage Directory
The storage directory contains runtime-generated files.
- Application logs
- Cached data
- Temporary files
- Uploaded content
The tests Directory
Automated tests belong in the tests directory.
Root Configuration Files
Several important files exist at the project root..env
Contains environment-specific variables.
.env.example
Provides a template for required environment variables.
package.json
Defines project metadata and scripts.
Example:
tsconfig.json
TypeScript compiler configuration.
Example:
bunfig.toml
Bun-specific configuration.
Example:
Recommended Organization
As your application grows, organize code by responsibility. Good:A Typical Request Journey
To understand how these directories work together, consider a request to create a user.What You Should Remember
The most important directories are:| Directory | Purpose |
|---|---|
| app | Application code |
| routes | Route definitions |
| config | Configuration |
| database | Migrations and seeders |
| public | Public assets |
| storage | Runtime files |
| tests | Automated tests |
“What responsibility does this code have?”The answer usually determines its location.
Next Steps
Now that you understand the structure of a Bejibun application, continue to:- Configuration
- Environment Variables
- Request Lifecycle
