The Sansofe Project Server is a Node.js backend application built with Express.js and MongoDB. It provides a RESTful API for the Sansofe platform, handling authentication and data storage.
- RESTful API architecture
- JWT-based authentication and authorization
- MongoDB database integration with Mongoose ODM
- Secure password handling with bcrypt
- Environment configuration with dotenv
- Cross-Origin Resource Sharing (CORS) support
- Request logging with Morgan
- Node.js: Runtime environment
- Express.js: v4.21.2 - Web server and API framework
- MongoDB: Database (via Mongoose v8.11.0)
- JWT: v9.0.2 - For authentication
- bcrypt: v5.1.1 - For password hashing
- cors: v2.8.5 - For CORS support
- morgan: v1.10.0 - For HTTP request logging
- Node.js (v18 or later recommended)
- MongoDB (local installation or MongoDB Atlas account)
- npm package manager
-
Clone the repository:
git clone https://github.com/Jojocg/Sansofe-Project-backend.git cd Sansofe-Project-backend
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory with the following variables as examples:PORT=5005 MONGODB_URI=mongodb://127.0.0.1:27017/sansofe_db TOKEN_SECRET=your_jwt_secret_key ORIGIN=http://localhost:3000
-
Start the development server:
npm run dev
-
The API will be available at
http://localhost:5005
sansofe-project-server/
├── config/ # Configuration files for frontend connection
├── controllers/ # Request controllers
├── db/ # Database connection setup
├── middleware/ # Custom middleware
├── models/ # Mongoose models
├── routes/ # API routes
├── .env # Environment variables
├── package.json # Dependencies and scripts
└── server.js # Entry point
The project integrates with Google's Gemini AI to provide intelligent responses about local markets in Gran Canaria. This integration enhances user experience by offering:
- Natural language interactions about markets
- Context-aware responses based on specific markets or towns
- Intelligent filtering of market information
- 🤖 Smart Assistant: Provides detailed information about local markets
- 🔒 Rate Limiting: Protects the AI service with 20 requests per IP per 15 minutes
- ⚡ Response Caching: Improves performance for repeated queries
- 🔍 Context-Aware: Tailored responses based on specific market or town context
AI Request Flow
-
Request Validation
POST /api/ai/assistant { "query": "string", // Required: User's question "marketId": "string", // Optional: Specific market "townId": "string" // Optional: Specific town }
-
Response Format
{ "response": "string" // AI-generated response }
-
Error Handling
{ "error": true, "type": "ErrorType", "message": "Error description", "details": {} }
Security Measures
- Request validation and sanitization
- Rate limiting protection
- Input length restrictions
- Context-based response filtering
@google/generative-ai
: Gemini AI integrationexpress-rate-limit
: API request limitingexpress-validator
: Request validation
Add to your .env
:
GEMINI_API_KEY=your_gemini_api_key
- 20 AI requests per IP address per 15 minutes
- Maximum query length: 500 characters
- Response caching for queries under 5000 characters
For more details about the AI integration, check: