0% found this document useful (0 votes)
0 views8 pages

Exp7 Oose

The document outlines the implementation of the IdeaForge system, detailing its layered architecture comprising UI, Domain, and Data layers. It includes specific components for each layer, such as user interfaces for project submission and classes for project management. Additionally, it provides code snippets for authentication, project idea generation, and database connection, concluding with a successful implementation result.

Uploaded by

tmadhumitha24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views8 pages

Exp7 Oose

The document outlines the implementation of the IdeaForge system, detailing its layered architecture comprising UI, Domain, and Data layers. It includes specific components for each layer, such as user interfaces for project submission and classes for project management. Additionally, it provides code snippets for authentication, project idea generation, and database connection, concluding with a successful implementation result.

Uploaded by

tmadhumitha24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Ex No: 7 IMPLEMENTATION OF IDEA FORGE SYSTEM

Date:

Aim:
To draw layered architectural diagrams and package diagrams for the IdeaForge
system and implement the same .

Procedure:
1. UI Layer

Purpose: Handles user interactions and displays data.​


Components:
●​ Login Interface​

●​ Project Submission Interface​

●​ Similarity Check Interface​

●​ Project History Interface​

●​ Staff Review Interface


2. Domain Layer

Purpose: Manages the core business logic and project validation.​


Components:

●​ User (Class to represent student or staff user)​

●​ Project (Class to represent project details)​

●​ ProjectSuggester (Class to suggest projects based on domain and tech stack)​

●​ SimilarityChecker (Class to calculate similarity percentage between projects)​

●​ ProjectStatusManager (Class to manage project acceptance/rejection statuses)


3. Data Layer

Purpose: Manages data storage and retrieval.​


Components:

●​ Database Connection​

●​ Data Access Object (DAO) for User, Project, and Status

Package Diagram:

Program:
Auth.ts:
import jwt from "jsonwebtoken";
import { type NextRequest, NextResponse } from "next/server";
import { type IUser } from "@/models/User"; // Import only the type, not the model directly
// Ensure JWT_SECRET is set in your environment variables
const JWT_SECRET = process.env.JWT_SECRET ||
"ad989da5e56528c46ceb00a81378a9f5fd90defd1a4fda7ab39dd1ca1d93ba02";
export async function signToken(user: IUser) {
const payload = {
id: user._id,
email: user.email,
role: user.role,
};
return jwt.sign(payload, JWT_SECRET, { expiresIn: "1d" });
}
export async function verifyToken(token: string) {
try { return jwt.verify(token, JWT_SECRET) as jwt.JwtPayload;}
catch (error) {return null;}
}
// This function should only be used in API routes or Server Components
export async function getCurrentUser(req: NextRequest) {
const token = req.cookies.get("token")?.value;
if (!token) return null;
const decoded = await verifyToken(token);
if (!decoded) return null;
try {
// Lazy-load Mongoose and User model
const mongoose = await import("mongoose");
const { default: User } = await import("@/models/User");
const user = await User.findById(decoded.id).select("-password");
return user;
} catch (error) {
console.error("Failed to fetch user:", error);
return null;
}
}
export async function requireAuth(req: NextRequest) {
const token = req.cookies.get("token")?.value;
if (!token) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 });}
const decoded = await verifyToken(token);
if (!decoded) { return NextResponse.json({ error: "Invalid token" }, { status: 401 }); }
return null; // Auth successful
}
export async function requireRole(req: NextRequest, role: string) {
const authError = await requireAuth(req);
if (authError) return authError;
const token = req.cookies.get("token")?.value;
const decoded = await verifyToken(token!);
if (!decoded || decoded.role !== role) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
return null; // Role check passed
}

ai-service.ts:
import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || "");
type IdeaFormData = {
areasOfInterest: string;
domainInterest: string;
languagesKnown: string;
additionalInfo?: string;
};
export async function generateProjectIdea(formData: IdeaFormData): Promise<string> {
try {
// Updated model name to the correct version
const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro" });
const prompt = `
Generate a unique project idea based on the following student details:
- Areas of Interest: ${formData.areasOfInterest}
- Domain Interest: ${formData.domainInterest}
- Programming Languages: ${formData.languagesKnown}
- Additional Info: ${formData.additionalInfo || "None"}

The project should include:


1. Title
2. Description
3. Key features
4. Technical details
5. Challenges

Format your response in Markdown.


`;
// For the newer Gemini models, we can use a simpler approach
// without necessarily needing a chat session
const result = await model.generateContent(prompt);
const response = await result.response;
return response.text();
} catch (error) {
console.error("Error generating idea:", error);
throw error;
}
}

db.ts:
import mongoose from "mongoose"
const MONGODB_URI = process.env.MONGODB_URI ||
"mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority&
appName=IdeaForge"
let cached = global.mongoose
if (!cached) { cached = global.mongoose = { conn: null, promise: null }}
async function connectToDatabase() {
if (cached.conn) { return cached.conn }
if (!cached.promise) {
const opts = { bufferCommands: false, }
cached.promise = mongoose.connect(MONGODB_URI, opts).then((mongoose) => {
return mongoose
})
}
try {
cached.conn = await cached.promise
} catch (e) {
cached.promise = null
throw e
}
return cached.conn
}

Output:
Result:
Thus the implementation for the IdeaForge system is successfully completed.

You might also like