Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AdibSadman192 committed Nov 23, 2024
0 parents commit 888cbc8
Show file tree
Hide file tree
Showing 141 changed files with 40,086 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Adib Sadman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# rent_house_bd
House Rental Platrom for Bangladesh
26 changes: 26 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/house_rental

# JWT Configuration
JWT_SECRET=your_jwt_secret_here
JWT_EXPIRES_IN=7d

# Server Configuration
PORT=5000
NODE_ENV=development

# Google Cloud / Dialogflow Configuration
DIALOGFLOW_PROJECT_ID=your-project-id
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/credentials.json

# Email Configuration (if needed)
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your-email@example.com
SMTP_PASS=your-email-password

# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:3000

# Redis Configuration (if needed)
REDIS_URL=redis://localhost:6379
64 changes: 64 additions & 0 deletions backend/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const mongoose = require('mongoose');

const connectDB = async () => {
try {
const mongoURI = process.env.MONGODB_URI || 'mongodb://localhost:27017/house-rental';
console.log(`Attempting to connect to MongoDB at: ${mongoURI}`);

const conn = await mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 30000,
socketTimeoutMS: 45000,
connectTimeoutMS: 30000,
keepAlive: true,
keepAliveInitialDelay: 300000
});

console.log(`MongoDB Connected: ${conn.connection.host}`);

// Handle MongoDB connection errors after initial connection
mongoose.connection.on('error', err => {
console.error(`MongoDB connection error: ${err}`);
// Attempt to reconnect
setTimeout(() => {
console.log('Attempting to reconnect to MongoDB...');
mongoose.connect(mongoURI);
}, 5000);
});

mongoose.connection.on('disconnected', () => {
console.warn('MongoDB disconnected. Attempting to reconnect...');
setTimeout(() => {
console.log('Attempting to reconnect to MongoDB...');
mongoose.connect(mongoURI);
}, 5000);
});

mongoose.connection.on('reconnected', () => {
console.info('MongoDB reconnected successfully');
});

// Handle application termination
process.on('SIGINT', async () => {
try {
await mongoose.connection.close();
console.log('MongoDB connection closed through app termination');
process.exit(0);
} catch (err) {
console.error('Error closing MongoDB connection:', err);
process.exit(1);
}
});

} catch (error) {
console.error(`Error connecting to MongoDB: ${error.message}`);
// Log more details about the error
if (error.name === 'MongooseServerSelectionError') {
console.error('MongoDB server selection error. Please check if MongoDB is running.');
}
process.exit(1);
}
};

module.exports = connectDB;
12 changes: 12 additions & 0 deletions backend/config/dialogflow-credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "your-private-key-id",
"private_key": "your-private-key",
"client_email": "your-client-email",
"client_id": "your-client-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "your-cert-url"
}
108 changes: 108 additions & 0 deletions backend/config/dialogflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const dialogflow = require('@google-cloud/dialogflow');
const { v4: uuidv4 } = require('uuid');

// Initialize Dialogflow client
const sessionClient = new dialogflow.SessionsClient({
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
});

const projectId = process.env.DIALOGFLOW_PROJECT_ID;

const detectIntent = async (text, sessionId = uuidv4()) => {
const sessionPath = sessionClient.projectAgentSessionPath(projectId, sessionId);

const request = {
session: sessionPath,
queryInput: {
text: {
text,
languageCode: 'en-US',
},
},
};

try {
const [response] = await sessionClient.detectIntent(request);
const result = response.queryResult;

return {
text: result.fulfillmentText,
intent: result.intent.displayName,
confidence: result.intentDetectionConfidence,
parameters: result.parameters.fields,
action: result.action,
allRequiredParamsPresent: result.allRequiredParamsPresent,
};
} catch (error) {
console.error('Error detecting intent:', error);
throw error;
}
};

const trainModel = async (examples) => {
const intentsClient = new dialogflow.IntentsClient({
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
});

const formattedParent = intentsClient.projectAgentPath(projectId);

try {
const [response] = await intentsClient.listIntents({
parent: formattedParent,
});

const trainingPromises = examples.map(async (example) => {
const matchingIntent = response.find(
(intent) => intent.displayName === example.intent
);

if (matchingIntent) {
// Update existing intent
matchingIntent.trainingPhrases.push({
parts: [{ text: example.text }],
});

const request = {
intent: matchingIntent,
};

await intentsClient.updateIntent(request);
} else {
// Create new intent
const intent = {
displayName: example.intent,
trainingPhrases: [
{
parts: [{ text: example.text }],
},
],
messages: [
{
text: {
text: [example.response],
},
},
],
};

const request = {
parent: formattedParent,
intent,
};

await intentsClient.createIntent(request);
}
});

await Promise.all(trainingPromises);
return { success: true, message: 'Training completed successfully' };
} catch (error) {
console.error('Error training model:', error);
throw error;
}
};

module.exports = {
detectIntent,
trainModel,
};
Loading

0 comments on commit 888cbc8

Please sign in to comment.