Project Structure
Xacos generates a well-organized project structure following industry best practices for Express.js applications.
Directory Overview
my-api/
├── src/
│ ├── config/ # Configuration files
│ │ ├── database.ts
│ │ ├── redis.ts
│ │ └── env.ts
│ ├── controllers/ # Request handlers
│ │ └── user.controller.ts
│ ├── middleware/ # Express middleware
│ │ ├── auth.middleware.ts
│ │ ├── error.middleware.ts
│ │ └── validation.middleware.ts
│ ├── models/ # Database models
│ │ └── user.model.ts
│ ├── routes/ # API routes
│ │ ├── index.ts
│ │ └── user.routes.ts
│ ├── services/ # Business logic
│ │ └── user.service.ts
│ ├── utils/ # Helper functions
│ │ ├── logger.ts
│ │ └── response.ts
│ ├── validators/ # Input validation schemas
│ │ └── user.validator.ts
│ ├── types/ # TypeScript types
│ │ └── index.ts
│ ├── app.ts # Express app setup
│ └── server.ts # Server entry point
├── tests/ # Test files
│ ├── unit/
│ └── integration/
├── .env.example # Environment variables template
├── .gitignore
├── tsconfig.json # TypeScript configuration
├── package.json
└── README.mdKey Directories
controllers/
Contains request handlers that receive HTTP requests and return responses. Controllers should be thin and delegate business logic to services.
services/
Contains business logic and data processing. Services interact with models and external APIs, keeping your controllers clean and focused.
models/
Database models and schemas. If using Prisma, this will contain your Prisma schema and generated types. For MongoDB, it contains Mongoose schemas.
routes/
API route definitions. Routes are automatically loaded and registered with the Express application.
middleware/
Custom Express middleware for authentication, validation, error handling, logging, and more.
config/
Configuration files for database connections, Redis, environment variables, and other application settings.
validators/
Input validation schemas using libraries like Zod or Joi to ensure data integrity before processing requests.
utils/
Utility functions and helpers that can be reused across the application, such as logger, response formatters, and custom error classes.
Auto-wiring Routes
Xacos automatically discovers and registers all routes in the routes/ directory. Simply create a new file with your route definitions, and it will be automatically loaded when the server starts.
TypeScript Support
When using the --ts flag, Xacos sets up a complete TypeScript configuration with proper types for Express, your database ORM, and all other dependencies.