Lithia

Project Structure

Understanding how to organize a Lithia project

Lithia.js uses a file-based routing system that automatically creates API routes based on your file structure. Understanding the project structure is essential for building scalable applications.

Basic Project Structure

A typical Lithia project follows this structure:

example
my-lithia-app/
├── src/
│   └── routes/           # API routes (file-based routing)
├── lithia.config.ts      # Lithia configuration
├── package.json          # Dependencies and scripts
└── tsconfig.json         # TypeScript configuration

As long as the routes are in the src/routes directory, they will be automatically converted into API routes.

Configuration Files

lithia.config.ts

See Configuration for detailed information about the configuration file.

Core Directories

src/routes - API Routes

The routes directory contains your API endpoints. Each file automatically becomes a route based on its location and name.

See Routing for detailed information about the file-based routing system, including:

  • Route naming conventions
  • Dynamic routes with [param]
  • Route priority and organization

Environment Variables

Lithia automatically loads environment variables from .env and .env.local files.

.env
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
.env.local
DATABASE_URL=mysql://user:password@localhost:3306/mydb

If you provide a .env.local and a .env file, both will be loaded and the .env.local file will override common variables.

In the example above, the DATABASE_URL variable provided in the .env.local file will override the DATABASE_URL provided in the .env file.

Please do not commit or use .env files in production.