Skip to Content
GuidesFolder Structure

Folder Structure

NeatNode provides different folder structures for JavaScript and TypeScript templates, each optimized for clarity and scalability.


JavaScript Templates - Typical Structure

Used by Basic (JS), REST API (JS), and Socket.IO (JS) templates.

<project-root>/ ├── package.json ├── server.js └── src/ ├── app.js ├── config/ ├── controllers/ ├── models/ ├── routes/ ├── services/ ├── middleware/ └── utils/

This structure follows a layer-based architecture, separating concerns clearly.


JavaScript Template Folders /src

controllers/

Request handlers mapped to routes.

routes/

Defines API endpoints.

services/

Business logic and database interactions.

models/

Mongoose schemas or DB models.

middleware/

Auth, validation, and error handling.

utils/

Shared helpers like ApiError, ApiResponse, CatchAsync.


TypeScript Templates - Layered + Modular Patterns

NeatNode TypeScript templates currently use two patterns:

  • Basic (TS) uses a clean layer-based structure
  • REST API (TS) uses a modular feature-based structure
<project-root>/ ├── package.json ├── tsconfig.json └── src/ ├── app.ts ├── server.ts ├── config/ ├── middlewares/ ├── modules/ └── auth/ ├── auth.controller.ts ├── auth.route.ts ├── auth.service.ts ├── auth.validation.ts └── user.model.ts ├── routes/ ├── types/ └── utils/

This keeps TypeScript projects strongly typed while still easy to evolve.


Root Files

FilePurpose
package.jsonDependencies and scripts
server.js / server.tsApplication entry point
app.js / app.tsExpress configuration
tsconfig.jsonTypeScript compiler configuration
.env / .env.exampleEnvironment variables

TypeScript Template Folders /src

modules/ (REST API TS)

Feature-based modules that group domain logic.

Example:

modules/auth/ ├── auth.controller.ts ├── auth.service.ts ├── auth.route.ts ├── auth.validation.ts └── user.model.ts

config/

Database, logger, and typed environment setup.

middlewares/

Typed middleware (auth, validation, errors).

utils/

Typed helpers, error classes, response wrappers.


Template Variations

TemplateStructure TypeNotes
Basic (JS)Layer-basedMinimal Express setup
REST API (JS)Layer-basedAuth + validation
Socket.IO (JS)Layer-basedAdds socket config
Basic (TS)Layer-basedStrict typing
REST API (TS)Module-basedJWT + Zod + typed middleware
Socket.IO (TS)PlannedNot shipped yet

Extending the Structure

You can safely add new folders in both JS and TS templates:

src/ jobs/ # Background jobs validators/ # Custom schema validation scripts/ # Seeding or CLI scripts

Request Flow Comparison

JavaScript (Layer-Based)

Route → Controller → Service → Model → Response

TypeScript (Module-Based)

Route → Controller → Service → Model → Response (all inside one module)

✅ Summary

  • JS templates → layer-based structure
  • TS templates → layer-based (Basic) and module-based (REST API)
  • Same concepts, different organization
  • Easy to scale, easy to understand

[!TIP] Once you understand one template, switching between JS and TS is straightforward.