Files in the top-level directory from the latest check-in
- .git
- peptidescore
- PeptideScore-back
- smart contracts
- README.md
Finnrick Backend API
A complete Node.js backend with Express.js and MongoDB for the Finnrick application, featuring authentication and content delivery.
Features
🔐 Authentication Module
- Email/Password Authentication: Secure registration and login with bcrypt password hashing
- OAuth Integration: Accepts OAuth user data from frontend (Google, Facebook, Twitter, TikTok)
- JWT Token Management: Stateless authentication with JSON Web Tokens
- Protected Routes: Middleware to secure private endpoints
- User Profile Management: Get and update user information
📦 Content Delivery Module
- Category-based Content: Retrieve content by category (science, history, technology, ai, books)
- Admin Content Management: Create, update, and delete content (admin only)
- Structured JSON Response: Clean API responses with title, description, imageURL
- Content Analytics: View tracking and engagement metrics
API Endpoints
Authentication
POST /api/auth/register- Register with email/passwordPOST /api/auth/login- Login with email/passwordPOST /api/auth/oauth- OAuth login (from frontend)GET /api/auth/me- Get current user profile (protected)POST /api/auth/logout- Logout user (protected)
Content
GET /api/content/:category- Get content by category (public)GET /api/content/item/:id- Get single content item (public)GET /api/content- Get all content (admin only)POST /api/content- Create content (admin only)PUT /api/content/:id- Update content (admin only)DELETE /api/content/:id- Delete content (admin only)
Utility
GET /health- Health check endpointPOST /api/seed- Seed database with sample data (development only)
Setup Instructions
1. Install Dependencies
cd backend
npm install
2. Environment Configuration
Copy .env.example to .env and configure:
cp .env.example .env
Required environment variables:
MONGODB_URI- MongoDB connection stringJWT_SECRET- Secret key for JWT tokensPORT- Server port (default: 5000)FRONTEND_URL- Frontend URL for CORSADMIN_EMAIL- Admin user email for seedingADMIN_PASSWORD- Admin user password for seeding
3. Start MongoDB
Make sure MongoDB is running on your system or use a cloud MongoDB service.
4. Run the Server
# Development mode with auto-reload
npm run dev
# Production mode
npm start
5. Seed Database (Optional)
curl -X POST http://localhost:5000/api/seed
Project Structure
backend/
├── src/
│ ├── config/
│ │ └── database.js # MongoDB connection
│ ├── controllers/
│ │ ├── authController.js # Authentication logic
│ │ └── contentController.js # Content management logic
│ ├── middleware/
│ │ ├── auth.js # JWT authentication middleware
│ │ └── validation.js # Input validation middleware
│ ├── models/
│ │ ├── User.js # User model schema
│ │ └── Content.js # Content model schema
│ ├── routes/
│ │ ├── auth.js # Authentication routes
│ │ └── content.js # Content routes
│ ├── utils/
│ │ └── seedData.js # Database seeding utility
│ └── server.js # Main server file
├── package.json
├── .env.example
└── README.md
Security Features
- Helmet.js: Security headers
- Rate Limiting: Prevents abuse
- CORS: Configured for frontend integration
- Input Validation: Express-validator for request validation
- Password Hashing: bcrypt for secure password storage
- JWT Authentication: Stateless token-based auth
Sample Data
The seed script includes sample content across all categories:
- Science: Quantum physics, climate change
- History: Ancient Rome, Industrial Revolution
- Technology: AI evolution, blockchain
- AI: Machine learning, ethics
- Books: Classic literature, digital publishing
OAuth Integration
The backend accepts OAuth user data from the frontend:
POST /api/auth/oauth
{
"email": "user@example.com",
"provider": "google",
"socialId": "123456789",
"avatar": "https://example.com/avatar.jpg"
}
Error Handling
- Comprehensive error handling with proper HTTP status codes
- Validation errors with detailed field-level feedback
- Development vs production error responses
- Global error handler for unhandled exceptions
Development
- Nodemon: Auto-restart on file changes
- Morgan: HTTP request logging
- Compression: Response compression
- Environment-based configuration
Testing
Health check endpoint available at /health to verify server status.
License
MIT License