A full-featured backend API for real estate management, built with Express.js, Prisma (PostgreSQL), JWT authentication, role-based access (Admin, Landlord, Tenant), Zod validation, and global error handling. Features user management, property/unit CRUD with ownership checks, and relationships for secure data isolation. Ideal for broker-style apps where admins oversee, landlords manage properties/tenants, and tenants book/pay.
- User authentication (register/login with roles, password hashing)
- Admin-only user CRUD with pagination, status toggle, tenant assignment
- Landlord-owned property/unit CRUD with filters, availability checks
- Relationships: Landlords own properties/units; tenants assigned to units
- Validation and error handling (Zod, AppError)
- Swagger docs for API endpoints
- Secure: Ownership filters, role restrictions
- Node.js / Express.js
- Prisma ORM with PostgreSQL
- JWT & bcrypt for auth
- Zod for validation
- Swagger for docs
- Clone the repo:
git clone https://github.com/yourusername/RealApi.git - Install deps:
npm install - Copy
.env.exampleto.envand fill in (DATABASE_URL, JWT_SECRET) - Prisma setup:
npx prisma generateandnpx prisma migrate dev - Start server:
npm start(or nodemon for dev)
- Register admin first (no token needed).
- Use Postman/Swagger at /docs for testing endpoints.
- Example: POST /api/v1/auth/registry with body { "name": "Admin", "email": "admin@example.com", "password": "securepass", "role": "ADMIN" }
- Auth: /auth/registry (POST), /auth/login (POST)
- Users: /users (GET list/filter), /users/{id} (GET/PUT/DELETE)—admin only
- Properties: /properties (POST/GET list/filter), /properties/{id} (PUT/DELETE)—landlord own/admin all
- Units: /units (POST/GET list/filter), /units/{id} (PUT/DELETE)—landlord own/admin all (See Swagger for full details/responses)
See CONTRIBUTING.md for guidelines. Pull requests welcome!
MIT License—see LICENSE for details.
PRs are welcome!
If you'd like to contribute, please read the CONTRIBUTING.md for guidelines.
Bug fixes, features, improvements, and documentation updates are appreciated.