Understanding Project Structure
The app directory is the center of an App Router application. A folder becomes a route when it contains the appropriate special file such as page.tsx.
Common special files include layout.tsx, page.tsx, loading.tsx, error.tsx, not-found.tsx, and route.ts.
Other directories such as components, lib, services, and types are application conventions rather than mandatory Next.js requirements. A large application benefits from separating UI components from business logic and infrastructure code.
A useful architecture is to keep route-specific UI near the route while keeping shared business logic in reusable modules.
Example Application Structure
app/
layout.tsx
page.tsx
dashboard/
layout.tsx
page.tsx
loading.tsx
error.tsx
api/
users/
route.ts
components/
Button.tsx
UserCard.tsx
lib/
db.ts
auth.ts
services/
user-service.ts
types/
user.ts💡 This structure separates routing concerns from reusable UI, infrastructure, and business logic.
Key Takeaways
- Files inside
appdefine application routing and rendering behavior. - Special Next.js files have framework-defined meanings.
- Business logic should not become tightly coupled to page components.