-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject Structure Organization
271 lines (229 loc) · 7.12 KB
/
Project Structure Organization
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
# إنشاء المجلدات الأساسية
mkdir -p MetaConnect/backend/models MetaConnect/backend/routes MetaConnect/frontend/src/components MetaConnect/frontend/pages MetaConnect/frontend/styles
# إنشاء ملف .env في backend
echo -e "MONGO_URI=your_mongodb_connection_string\nPORT=5000" > MetaConnect/backend/.env
# إنشاء ملف server.js في backend
cat <<EOL > MetaConnect/backend/server.js
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
require('dotenv').config();
const app = express();
app.use(cors({
origin: 'http://localhost:3000' // استبدل هذا بالنطاق الصحيح لتطبيقك
}));
app.use(express.json());
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("MongoDB connected"))
.catch(err => console.error("MongoDB connection error:", err));
app.use('/api/transactions', require('./routes/transactions'));
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(\`Server running on port \${PORT}\`));
EOL
# إنشاء ملف User.js في backend/models
cat <<EOL > MetaConnect/backend/models/User.js
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const UserSchema = new mongoose.Schema({
username: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
balance: { type: Number, default: 0 },
referrals: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }]
});
// تشفير كلمة المرور قبل حفظ المستخدم
UserSchema.pre('save', async function(next) {
if (!this.isModified('password')) return next();
this.password = await bcrypt.hash(this.password, 10);
next();
});
// دالة للتحقق من كلمة المرور
UserSchema.methods.comparePassword = function(password) {
return bcrypt.compare(password, this.password);
};
module.exports = mongoose.model('User', UserSchema);
EOL
# إنشاء ملف Transaction.js في backend/models
cat <<EOL > MetaConnect/backend/models/Transaction.js
const mongoose = require('mongoose');
const TransactionSchema = new mongoose.Schema({
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
amount: { type: Number, required: true },
type: { type: String, enum: ['deposit', 'withdrawal'], required: true },
date: { type: Date, default: Date.now }
});
module.exports = mongoose.model('Transaction', TransactionSchema);
EOL
# إنشاء ملف transactions.js في backend/routes
cat <<EOL > MetaConnect/backend/routes/transactions.js
const express = require('express');
const router = express.Router();
const Transaction = require('../models/Transaction');
const User = require('../models/User');
// Deposit route
router.post('/deposit', async (req, res) => {
try {
const { userId, amount } = req.body;
const newTransaction = new Transaction({ user: userId, amount, type: 'deposit' });
await newTransaction.save();
await User.findByIdAndUpdate(userId, { \$inc: { balance: amount } });
res.status(200).json({ message: 'Deposit successful', transaction: newTransaction });
} catch (error) {
res.status(500).json({ message: 'Error processing deposit', error });
}
});
// Withdrawal route
router.post('/withdraw', async (req, res) => {
try {
const { userId, amount } = req.body;
const user = await User.findById(userId);
if (!user) {
return res.status(404).json({ message: 'User not found' });
}
if (user.balance < amount) {
return res.status(400).json({ message: 'Insufficient balance' });
}
const newTransaction = new Transaction({ user: userId, amount, type: 'withdrawal' });
await newTransaction.save();
await User.findByIdAndUpdate(userId, { \$inc: { balance: -amount } });
res.status(200).json({ message: 'Withdrawal successful', transaction: newTransaction });
} catch (error) {
res.status(500).json({ message: 'Error processing withdrawal', error });
}
});
module.exports = router;
EOL
# إنشاء package.json في backend
cat <<EOL > MetaConnect/backend/package.json
{
"name": "backend",
"version": "1.0.0",
"description": "Backend for MetaConnect",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.18.2",
"mongoose": "^8.9.5",
"dotenv": "^10.0.0",
"cors": "^2.8.5",
"bcrypt": "^5.0.1"
}
}
EOL
# إنشاء package.json في frontend
cat <<EOL > MetaConnect/frontend/package.json
{
"name": "frontend",
"version": "1.0.0",
"description": "Frontend for MetaConnect",
"main": "index.js",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "latest",
"react-dom": "latest"
}
}
EOL
# إنشاء ملف next.config.js في frontend
cat <<EOL > MetaConnect/frontend/next.config.js
module.exports = {
reactStrictMode: true,
};
EOL
# إنشاء ملف index.js في frontend/pages
cat <<EOL > MetaConnect/frontend/pages/index.js
import Header from '../src/components/Header';
import Footer from '../src/components/Footer';
const Home = () => {
return (
<div>
<Header />
<h2>Welcome to MetaConnect!</h2>
<Footer />
</div>
);
};
export default Home;
EOL
# إنشاء ملف profile.js في frontend/pages
cat <<EOL > MetaConnect/frontend/pages/profile.js
import Header from '../src/components/Header';
import Footer from '../src/components/Footer';
const Profile = () => {
return (
<div>
<Header />
<h2>Your Profile</h2>
<Footer />
</div>
);
};
export default Profile;
EOL
# إنشاء ملف Header.js في frontend/src/components
cat <<EOL > MetaConnect/frontend/src/components/Header.js
import React from 'react';
const Header = () => {
return (
<header>
<h1>MetaConnect</h1>
{/* Navigation links */}
</header>
);
};
export default Header;
EOL
# إنشاء ملف Footer.js في frontend/src/components
cat <<EOL > MetaConnect/frontend/src/components/Footer.js
import React from 'react';
const Footer = () => {
return (
<footer>
<p>© 2024 MetaConnect</p>
</footer>
);
};
export default Footer;
EOL
# إنشاء ملف globals.css في frontend/src/styles
echo -e "/* Global styles here */" > MetaConnect/frontend/src/styles/globals.css
# إنشاء README.md
cat <<EOL > MetaConnect/README.md
# MetaConnect
MetaConnect is an application that integrates the metaverse and virtual reality, supporting various digital payment methods.
## System Requirements
- Node.js (>= 14.x)
- MongoDB
## Setup Instructions
### Backend
1. Navigate to the \`backend\` folder.
2. Install dependencies:
\`\`\`bash
npm install
\`\`\`
3. Create a \`.env\` file with your MongoDB connection string.
4. Start the server:
\`\`\`bash
npm start
\`\`\`
### Frontend
1. Navigate to the \`frontend\` folder.
2. Install dependencies:
\`\`\`bash
npm install
\`\`\`
3. Start the development server:
\`\`\`bash
npm run dev
\`\`\`
EOL
# طباعة رسالة نجاح
echo "Project MetaConnect has been created successfully!"