Project Structure
Optimized Architecture for Modern Node.js Applications

Directory | Purpose | Implementation Notes |
---|
src | Business logic & domain modules | Optional TypeScript/JS organization |
routes | API endpoint definitions | Zero-config routing system |
File | Role |
---|
lithia.config.js | Framework behavior customization |
package.json | Dependency management & scripts |
tsconfig.json | TypeScript compilation rules |
File | Environment Scope |
---|
.env | Base variables |
.env.local | Developer overrides |
.env.production | Cloud deployment config |
.env.development | Dev-specific settings |
Pattern | URL Structure | Use Case |
---|
index.ts | / | Root endpoint |
user.ts | /user | Static resource |
[id].ts | /:id | Dynamic identifiers |
[slug].ts | /:slug | SEO-friendly paths |
Structure | Example Path | Implementation Benefit |
---|
api/v1/users | /api/v1/users | Versioned endpoints |
products/[id]/reviews | /products/123/reviews | Nested resources |
(admin)/dashboard | /dashboard | Route grouping without URL prefix |
- Keep route handlers focused on HTTP layer
- Store business logic in
src/modules
- Maintain shared types in
src/types
- Place middleware in
src/middlewares
- Use route groups for permission-based endpoints
- Implement dynamic segments for CRUD operations
- Leverage nested folders for complex API structures
Pro Tip: Generate route visualization with ###npx lithia routes analyze### to optimize your API structure.