Project Structure
Understand the standard directory layout and organization of an AxilJS application.
Directory layout
An AxilJS project uses a predictable structure that separates application configuration, modules, database migrations, and background jobs.
Note
The structure is a starting point rather than a restriction. AxilJS supports modular applications, MVC applications, monoliths, and distributed service architectures.
Source directory
The src/ directory contains the application source code.
src/main.ts
main.ts is the application entry point. It creates the AxilJS application and starts the HTTP server.
For applications that require middleware and additional configuration, the entry point can initialize those services before calling listen().
Configuration
src/config/app.config.ts
Application configuration can be centralized in the config/ directory.
Using defineConfig() gives application settings a consistent configuration boundary and allows environment values to be validated before the application starts.
Modules
The modules/ directory contains application features.
For example, a users module can be organized as:
Each layer has a specific responsibility.
| Directory | Responsibility |
|---|---|
controllers/ | HTTP request handling and route logic |
services/ | Business logic and application operations |
entities/ | Database entities and domain models |
*.test.ts | Tests for the module |
This structure keeps HTTP concerns separate from business logic and persistence concerns.
Controllers
Controllers handle incoming HTTP requests and return responses.
Controllers should remain focused on transport-level concerns. Business operations can be delegated to services.
Services
Services contain reusable application and business logic.
Keeping business logic in services makes it easier to reuse the same operations from HTTP handlers, jobs, event handlers, or other application modules.
Entities
Entities represent database-backed application models.
The exact entity organization depends on how your application uses @axiljs/orm.
Migrations
Database migrations live under:
A migration defines a database schema change and its rollback operation.
AxilJS ORM migrations are designed to work with the supported database drivers and their corresponding SQL syntax.
Jobs
The jobs/ directory is intended for background work and scheduled application tasks.
Jobs can be connected to the AxilJS queue and scheduler capabilities when background processing or scheduled execution is required.
Environment files
.env
Local environment-specific values belong in .env.
.env.example
The .env.example file documents the environment variables required by the application without exposing real credentials.
Warning
Never commit .env files containing secrets to version control. Commit .env.example with placeholder values instead.
package.json
package.json defines the project's dependencies, metadata, and npm scripts.
A typical project may include:
The exact generated configuration may vary with the AxilJS project setup.
tsconfig.json
AxilJS applications use TypeScript. The tsconfig.json file controls TypeScript compilation.
Use the generated configuration as the baseline for an AxilJS project and extend it only when your application requires additional compiler settings.
axil.lock
The axil.lock file records AxilJS package-management information used by the project.
Keep this file under version control so project installations remain consistent.
.gitignore
The generated .gitignore should exclude local and generated files such as:
Do not ignore source files, migrations, or other project files that are required to build and deploy the application.
Scaling the structure
As an application grows, modules can be expanded independently:
This structure works well for modular monoliths and can also provide a clear boundary for extracting services later.
Tip
Keep application code organized around business capabilities rather than allowing controllers/, services/, and database code to become unrelated global directories.
Next steps
- Quick Start — Create and run your first AxilJS application
- Installation — Set up the AxilJS CLI and development environment
- HTTP Server — Learn routing and middleware
- Database & ORM — Define entities and manage migrations
- Authentication — Add JWT authentication and RBAC