Skip to content

Commit 55b5d36

Browse files
committed
Update readme for backend
1 parent 41da236 commit 55b5d36

File tree

1 file changed

+291
-0
lines changed

1 file changed

+291
-0
lines changed

backend/README.md

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
# Rent House BD - Backend
2+
3+
This is the backend service for the Rent House BD application, providing APIs for property rental management and user authentication.
4+
5+
## Tech Stack
6+
7+
- Node.js
8+
- Express.js
9+
- MongoDB
10+
- JWT for authentication
11+
- Multer for file uploads
12+
- Socket.IO for real-time chat
13+
14+
## Features
15+
16+
### Authentication & Authorization
17+
- [x] User registration with role-based access
18+
- [x] JWT-based authentication
19+
- [x] Token refresh mechanism
20+
- [x] Password reset functionality
21+
- [x] Email verification
22+
- [x] Role-based access control (User, Renter, Admin, SuperAdmin)
23+
24+
### Property Management
25+
- [x] CRUD operations for properties
26+
- [x] Property search with filters
27+
- [x] Image upload and management
28+
- [x] Property verification system
29+
- [x] Property reviews and ratings
30+
31+
### User Management
32+
- [x] User profile management
33+
- [x] Booking history
34+
- [x] Property owner dashboard
35+
- [x] Admin dashboard
36+
- [x] User activity logs
37+
38+
### Chat System
39+
- [x] Real-time messaging between users and property owners
40+
- [x] Message history
41+
- [x] Notification system
42+
- [x] Online status tracking
43+
44+
### Payment Integration
45+
- [x] Payment gateway integration
46+
- [x] Booking payment processing
47+
- [x] Payment history
48+
- [x] Refund management
49+
50+
## API Endpoints
51+
52+
### Authentication
53+
```
54+
POST /api/auth/register
55+
POST /api/auth/login
56+
POST /api/auth/refresh-token
57+
POST /api/auth/forgot-password
58+
POST /api/auth/reset-password
59+
GET /api/auth/verify-email/:token
60+
```
61+
62+
### Users
63+
```
64+
GET /api/users/profile
65+
PUT /api/users/profile
66+
GET /api/users/bookings
67+
GET /api/admin/users
68+
PUT /api/admin/users/:id
69+
DELETE /api/admin/users/:id
70+
```
71+
72+
### Properties
73+
```
74+
GET /api/properties
75+
GET /api/properties/:id
76+
POST /api/properties
77+
PUT /api/properties/:id
78+
DELETE /api/properties/:id
79+
POST /api/properties/:id/reviews
80+
GET /api/properties/:id/reviews
81+
```
82+
83+
### Bookings
84+
```
85+
POST /api/bookings
86+
GET /api/bookings
87+
GET /api/bookings/:id
88+
PUT /api/bookings/:id
89+
DELETE /api/bookings/:id
90+
```
91+
92+
### Chat
93+
```
94+
GET /api/chats
95+
GET /api/chats/:id
96+
POST /api/chats
97+
GET /api/chats/:id/messages
98+
POST /api/chats/:id/messages
99+
```
100+
101+
## Project Structure
102+
```
103+
backend/
104+
├── src/
105+
│ ├── config/
106+
│ │ ├── database.js # Database configuration
107+
│ │ ├── passport.js # Passport.js configuration
108+
│ │ └── roles.js # Role definitions and permissions
109+
│ ├── controllers/
110+
│ │ ├── auth.js # Authentication controllers
111+
│ │ ├── user.js # User management
112+
│ │ ├── property.js # Property operations
113+
│ │ ├── booking.js # Booking management
114+
│ │ ├── chat.js # Chat functionality
115+
│ │ └── payment.js # Payment processing
116+
│ ├── middleware/
117+
│ │ ├── auth.js # Authentication middleware
118+
│ │ ├── upload.js # File upload middleware
119+
│ │ ├── validate.js # Request validation
120+
│ │ └── error.js # Error handling
121+
│ ├── models/
122+
│ │ ├── User.js # User model
123+
│ │ ├── Property.js # Property model
124+
│ │ ├── Booking.js # Booking model
125+
│ │ ├── Chat.js # Chat model
126+
│ │ └── Message.js # Message model
127+
│ ├── routes/
128+
│ │ ├── auth.js # Authentication routes
129+
│ │ ├── user.js # User routes
130+
│ │ ├── property.js # Property routes
131+
│ │ ├── booking.js # Booking routes
132+
│ │ ├── chat.js # Chat routes
133+
│ │ └── payment.js # Payment routes
134+
│ ├── services/
135+
│ │ ├── email.js # Email service
136+
│ │ ├── storage.js # File storage service
137+
│ │ ├── payment.js # Payment service
138+
│ │ └── socket.js # WebSocket service
139+
│ ├── utils/
140+
│ │ ├── validation.js # Validation helpers
141+
│ │ ├── errors.js # Error classes
142+
│ │ ├── logger.js # Logging utility
143+
│ │ └── helpers.js # General helpers
144+
│ └── app.js # Express app setup
145+
├── tests/
146+
│ ├── integration/ # Integration tests
147+
│ │ ├── auth.test.js
148+
│ │ ├── property.test.js
149+
│ │ └── booking.test.js
150+
│ ├── unit/ # Unit tests
151+
│ │ ├── models/
152+
│ │ ├── controllers/
153+
│ │ └── services/
154+
│ └── setup.js # Test configuration
155+
├── uploads/ # Temporary file uploads
156+
├── logs/ # Application logs
157+
├── .env # Environment variables
158+
├── .env.example # Example environment variables
159+
├── .gitignore # Git ignore rules
160+
├── package.json # Project dependencies
161+
├── README.md # Project documentation
162+
└── server.js # Application entry point
163+
```
164+
165+
## Environment Variables
166+
167+
```env
168+
NODE_ENV=development
169+
PORT=5000
170+
MONGODB_URI=mongodb://localhost:27017/rent_house_bd
171+
JWT_SECRET=your_jwt_secret
172+
JWT_REFRESH_SECRET=your_refresh_secret
173+
SMTP_HOST=smtp.gmail.com
174+
SMTP_PORT=587
175+
SMTP_USER=your_email@gmail.com
176+
SMTP_PASS=your_email_password
177+
CLOUDINARY_CLOUD_NAME=your_cloudinary_name
178+
CLOUDINARY_API_KEY=your_cloudinary_key
179+
CLOUDINARY_API_SECRET=your_cloudinary_secret
180+
STRIPE_SECRET_KEY=your_stripe_secret_key
181+
```
182+
183+
## Getting Started
184+
185+
1. Clone the repository
186+
```bash
187+
git clone https://github.com/yourusername/rent_house_bd.git
188+
cd rent_house_bd/backend
189+
```
190+
191+
2. Install dependencies
192+
```bash
193+
npm install
194+
```
195+
196+
3. Set up environment variables
197+
```bash
198+
cp .env.example .env
199+
# Edit .env with your configuration
200+
```
201+
202+
4. Start MongoDB
203+
```bash
204+
# Make sure MongoDB is running locally or update MONGODB_URI in .env
205+
```
206+
207+
5. Run the development server
208+
```bash
209+
npm run dev
210+
```
211+
212+
## Database Schema
213+
214+
### User
215+
- _id: ObjectId
216+
- email: String
217+
- password: String (hashed)
218+
- role: String (enum: ['user', 'renter', 'admin', 'superadmin'])
219+
- name: String
220+
- phone: String
221+
- verified: Boolean
222+
- createdAt: Date
223+
- updatedAt: Date
224+
225+
### Property
226+
- _id: ObjectId
227+
- owner: ObjectId (ref: User)
228+
- title: String
229+
- description: String
230+
- price: Number
231+
- location: {
232+
address: String,
233+
city: String,
234+
coordinates: [Number]
235+
}
236+
- features: [String]
237+
- images: [String]
238+
- status: String (enum: ['available', 'rented', 'pending'])
239+
- createdAt: Date
240+
- updatedAt: Date
241+
242+
### Booking
243+
- _id: ObjectId
244+
- property: ObjectId (ref: Property)
245+
- user: ObjectId (ref: User)
246+
- startDate: Date
247+
- endDate: Date
248+
- status: String (enum: ['pending', 'confirmed', 'cancelled'])
249+
- paymentStatus: String
250+
- amount: Number
251+
- createdAt: Date
252+
- updatedAt: Date
253+
254+
### Chat
255+
- _id: ObjectId
256+
- participants: [ObjectId] (ref: User)
257+
- property: ObjectId (ref: Property)
258+
- lastMessage: Date
259+
- createdAt: Date
260+
- updatedAt: Date
261+
262+
### Message
263+
- _id: ObjectId
264+
- chat: ObjectId (ref: Chat)
265+
- sender: ObjectId (ref: User)
266+
- content: String
267+
- readBy: [ObjectId] (ref: User)
268+
- createdAt: Date
269+
- updatedAt: Date
270+
271+
## Testing
272+
273+
```bash
274+
# Run tests
275+
npm test
276+
277+
# Run tests with coverage
278+
npm run test:coverage
279+
```
280+
281+
## Contributing
282+
283+
1. Fork the repository
284+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
285+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
286+
4. Push to the branch (`git push origin feature/AmazingFeature`)
287+
5. Open a Pull Request
288+
289+
## License
290+
291+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

0 commit comments

Comments
 (0)