Skip to content

Latest commit

Β 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏒 Nexora Backend

Nexora Backend is a high-performance RESTful API server for the Nexora Apartment Management System. Built using Node.js, Express 5, Mongoose ORM, Better Auth, Zod validation, and Stripe payment integration, it follows an enterprise-grade Routes -> Controllers -> Services modular architecture.


Node.js Express Mongoose MongoDB Better Auth Zod Stripe License


✨ Features

βœ… Layered Modular Architecture (Routes, Controllers, Services)
βœ… Better Auth Integration (better-auth) for session & email/password authentication
βœ… Password Hashing via bcryptjs (salt rounds: 10)
βœ… Strict Request Body Validation using Zod schemas
βœ… Role-Based Authorization (Admin / Member / User)
βœ… Apartments Management with pagination, rent range filtering, and sorting
βœ… Agreements Workflow (Application request, admin accept/reject)
βœ… Coupons System (Create, update, delete, and discount validation)
βœ… Rent Payments integrated with Stripe PaymentIntents
βœ… Automated Monthly Rent Generation via node-cron
βœ… Announcements System for property notices
βœ… Admin Dashboard Statistics with MongoDB aggregation pipelines


πŸ› οΈ Tech Stack

Tech Purpose
⚑ Express.js (v5) High-performance Web Application Framework
πŸƒ Mongoose (v9) Object Data Modeling (ODM) for MongoDB
πŸ” Better Auth Authentication & Session Management
πŸ”‘ bcryptjs Password Hashing (Salt 10)
πŸ›‘οΈ Zod Type-safe Request Schema Validation
πŸ’³ Stripe Payment Intent Processing
πŸ•’ Node-cron Automated Scheduled Jobs

πŸ“ Directory & Module Structure

Nexora-server/
β”œβ”€β”€ app.js                           # Express application & global middleware
β”œβ”€β”€ server.js                        # Database connection & server listener
β”œβ”€β”€ index.js                         # Main entry point (Exports app for Vercel/Local)
β”œβ”€β”€ .env.example                     # Environment variables template
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ auth.js                      # Better Auth configuration & MongoDB adapter
β”‚   └── db.js                        # Mongoose database connection setup
β”œβ”€β”€ cron/
β”‚   └── rentCron.js                  # Monthly rent generation cron job
β”œβ”€β”€ middleware/
β”‚   └── auth.js                      # Better Auth session & role authorization
β”œβ”€β”€ validators/
β”‚   └── schemas.js                   # Zod request validation schemas & middleware
β”œβ”€β”€ models/                          # Mongoose Database Schemas
β”‚   β”œβ”€β”€ User.js
β”‚   β”œβ”€β”€ Apartment.js
β”‚   β”œβ”€β”€ Agreement.js
β”‚   β”œβ”€β”€ RentPayment.js
β”‚   β”œβ”€β”€ Announcement.js
β”‚   └── Coupon.js
└── modules/                         # Feature Modules (Route - Controller - Service)
    β”œβ”€β”€ apartment/                   # Apartment routes, controllers, services
    β”œβ”€β”€ agreement/                   # Agreement workflow routes & services
    β”œβ”€β”€ user/                        # User registration, login, role handlers
    β”œβ”€β”€ coupon/                      # Coupon creation & validation
    β”œβ”€β”€ rentPayment/                 # Stripe payment intent & rent recording
    β”œβ”€β”€ announcement/                # Announcement management
    └── admin/                       # Admin statistics & member management

βš™οΈ Environment Variables Setup

Copy .env.example to .env and fill in your credentials:

cp .env.example .env
PORT=5000
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/Nexora?retryWrites=true&w=majority
STRIPE_SECRET_KEY=sk_test_51...

BETTER_AUTH_SECRET=your_super_secret_better_auth_key_here
BETTER_AUTH_URL=http://localhost:5000

πŸ“¦ Installation & Local Development

Using npm:

# 1. Install dependencies
npm install

# 2. Run in development mode
npm run dev

# 3. Start production server
npm start

Using bun:

# 1. Install dependencies
bun install

# 2. Run in development mode
bun dev

🌐 API Reference

πŸ” Authentication (Better Auth)

Method Endpoint Description Auth
ALL /api/auth/* Better Auth handlers (Sign In, Sign Up, Sign Out, Session) Public
POST /users/login Email & password login (returns JWT/Session) Public

πŸ‘€ Users

Method Endpoint Description Auth
POST /users Create or update user account Public (Zod)
GET /users/:email/role Get user role (user, member, admin) Session

🏒 Apartments

Method Endpoint Description Auth
GET /apartments Paginated apartments list (page, limit, minRent, maxRent, sortBy, sortOrder) Public

πŸ“„ Agreements

Method Endpoint Description Auth
POST /agreements Apply for an apartment agreement Session (Zod)
GET /agreements?status=pending Get agreements by status Admin
PATCH /agreements/:id Accept or reject agreement request Admin
GET /agreements/user/:email Get user's agreements list Session

🎟️ Coupons

Method Endpoint Description Auth
GET /coupons List all available coupons Public
POST /coupons/validate Validate coupon code and get discount Member
POST /coupons Add a new coupon Admin (Zod)
PUT /coupons/:id Update existing coupon details Admin (Zod)
DELETE /coupons/:id Delete coupon by ID Admin

πŸ’³ Rent Payments & Stripe

Method Endpoint Description Auth
POST /create-payment-intent Create Stripe PaymentIntent with optional coupon discount Member (Zod)
POST /rent-payments Record successful rent payment Session (Zod)
GET /rent-payments/:email Get rent payments history for user Session
PATCH /rent-payments/:id Update rent payment status Session

πŸ“’ Announcements

Method Endpoint Description Auth
GET /announcements Get list of announcements Session
POST /announcements Create new announcement Admin (Zod)
PATCH /announcements/:id Update announcement by ID Admin (Zod)
DELETE /announcements/:id Delete announcement by ID Admin

πŸ“Š Admin Dashboard

Method Endpoint Description Auth
GET /members Get all members with agreement & apartment info Admin
PATCH /members/:email/remove Downgrade member role & release apartment Admin
GET /members/:email/due-months Get unpaid rent months for a member Admin
GET /admin/stats Aggregate stats (Total rooms, availability %, total users, members) Admin

⏰ Cron Jobs

Schedule Description
0 1 1 * * Runs on the 1st of every month at 01:00 AM to automatically generate unpaid rent records for active members and advance their nextRentDate.

πŸ“œ License

This project is licensed under the MIT License.

Built with ❀️ by Taj Uddin
πŸ“§ Contact: tajuddin.cse.dev@gmail.com

About

NEXORA-Server is the secure and scalable backend API powering the Nexora web application. Built with Node.js, Express, and MongoDB, it handles authentication, user roles, data management, and seamless communication between the client and database. Designed for performance, security, and flexibility in a modern full-stack environment.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages