Project Structure
To keep your Noblex app organized and maintainable, it’s best practice to put your source code inside a src
folder.
Inside src
, create the following main files and folders:
index.ts
— Your app’s entry pointenv.ts
— Environment variables and config loaderdb.ts
— Database connection setupapp.ts
— Noblex application setup and middleware configurationmodules/
— Folder containing collection-specific code, organized by collection name
Example folder structure
noblex-project/
📁 ── src/
│ 📜 ── index.ts
│ 📜 ── env.ts
│ 📜 ── db.ts
│ 📜 ── app.ts
│ 📁 ── modules/
│ ├── 📁 ── users/
│ │ 📜── users.controller.ts
│ │ 📜── users.model.ts
│ │ 📜── users.methods.ts
│ │ 📜── users.hooks.ts
│ └── 📁 ── blogPosts/
│ 📜── blogPosts.controller.ts
│ 📜── blogPosts.model.ts
│ 📜── blogPosts.methods.ts
│ 📜── blogPosts.hooks.ts
├── package.json
├── .env.development
└── ...
Brief overview of each folder/file:
-
index.ts
Starts your app, imports app setup, and listens on your port. -
env.ts
Loads environment variables usingdotenv
and exports config constants. -
db.ts
Connects to MongoDB using Mongoose and exports the connection. -
app.ts
Configures Noblex app, middleware, routes, and error handlers. -
modules/
Organizes your MongoDB collections. Each collection gets its own folder containing its controller, model, and hooks.
This structure keeps your project clean and scalable, making it easy to add new collections without clutter.