The intelligent, headless API core for the Cortex CMS. Built with Node.js, Express, and TypeScript, it provides a robust foundation for content management, authentication, and integration.
Repository: https://github.com/umairrx/cortex-backend Frontend: https://github.com/umairrx/cortex
- Headless Architecture: Decoupled content delivery via REST API.
- Secure Authentication: JWT-based auth with access/refresh token rotation (httpOnly cookies).
- Dynamic Content Modeling: Create and manage custom collections with dynamic schemas.
- Integration System: (In Progress) Connectors for external databases and services.
- Type Safety: Fully typed with TypeScript.
- Performance: Optimized MongoDB queries and indexing.
- Runtime: Node.js
- Framework: Express.js
- Language: TypeScript
- Database: MongoDB (via Mongoose)
- Validation: Zod & Express-Validator
- Security: Helmet, bcrypt, CORS, Rate Limiting
-
Clone the repository
git clone https://github.com/umairrx/cortex-backend.git cd cortex-backend -
Install dependencies
pnpm install # or npm install -
Environment Configuration Create a
.envfile in the root directory:# Server Configuration PORT=3000 NODE_ENV=development # Database MONGODB_URI=mongodb://localhost:27017/cortex_db # Authentication JWT_SECRET=your_super_secret_jwt_key_here JWT_EXPIRY=15m REFRESH_TOKEN_SECRET=your_super_secret_refresh_key_here REFRESH_TOKEN_EXPIRY=7d # Email Service (for password reset) EMAIL_HOST=smtp.example.com EMAIL_PORT=587 EMAIL_USER=your_email@example.com EMAIL_PASS=your_email_password
-
Start Development Server
pnpm dev
| Script | Description |
|---|---|
pnpm dev |
Starts the development server with hot-reload (tsx). |
pnpm build |
Compiles TypeScript code to JavaScript. |
pnpm start |
Runs the compiled production code from dist/. |
The API is structured around resource-oriented endpoints.
POST /api/signup- Register a new admin/user.POST /api/signin- Authenticate and receive cookies.POST /api/refresh- Rotate access tokens.POST /api/logout- Clear session.
GET /api/collections- List all content models.POST /api/collections- Define a new content model.GET /api/collections/:id/items- Fetch items for a collection.POST /api/collections/:id/items- Create a new item.
- Build the project:
pnpm build - Set
NODE_ENV=productionin your environment. - Run the server:
pnpm start
Recommended to use a process manager like pm2 for production:
pm2 start dist/index.js --name cortex-backend