DSA Platform Self-Hosting Manual
Table of Contents
- Prerequisites
- Installation
- Firebase Setup
- Admin Configuration
- Security Rules
- Deployment
- Maintenance
1. Prerequisites
Before you begin the self-hosting process, ensure you have the following installed:
- Node.js (v18 or higher)
- npm (v9 or higher)
- Git
- A Firebase account
- A code editor (VS Code recommended)
2. Installation
Follow these steps to set up the development environment:
- Clone the repository:
git clone [your-repository-url]
cd [repository-name]
- Install dependencies:
npm install
- Create a `.env.local` file in the root directory with the following variables:
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_auth_domain
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_storage_bucket
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
3. Firebase Setup
To set up Firebase for your self-hosted instance:
- Go to the Firebase Console (https://console.firebase.google.com)
- Create a new project
- Enable Authentication:
- Go to Authentication > Sign-in method
- Enable Email/Password authentication
- Set up Firestore Database:
- Create a new database in production mode
- Choose a location closest to your target users
- Configure Firebase Security Rules (see Security Rules section)
4. Admin Configuration
The platform uses a role-based access control system. To set up an admin user:
- First, create a regular user account through the platform's registration process
- Access the Firebase Console
- Navigate to Firestore Database
- Find the user document in the `users` collection
- Update the user's role field to "admin":
{
"role": "admin",
"email": "admin@example.com",
"displayName": "Admin User",
"createdAt": "timestamp",
"joinedAt": "timestamp",
"settings": {
"theme": "light",
"notifications": true
}
}
Note: The admin user has full access to:
- Create, edit, and delete problems
- Manage user accounts
- Access all user solutions and statistics
- Modify platform settings
5. Security Rules
The platform uses Firebase Security Rules to control access to data. The rules are already configured in the `firestore.rules` file, but you should review and customize them based on your needs:
- Users can only read their own data unless they're an admin
- Only admins can create and modify problems
- Users can only submit solutions to their own account
- Daily stats are accessible to all authenticated users
Important: Always test your security rules thoroughly before deploying to production. Use the Firebase Emulator Suite for testing.
6. Deployment
To deploy the platform:
- Build the application:
npm run build
- Deploy to your preferred hosting platform (e.g., Vercel, Firebase Hosting):
- For Vercel:
vercel deploy
- For Firebase Hosting:
firebase deploy
7. Maintenance
Regular maintenance tasks include:
- Monitoring Firebase usage and costs
- Regular backups of Firestore data
- Updating dependencies:
npm update
- Checking for security updates
- Monitoring application performance
Best Practices:
- Keep your Firebase project credentials secure
- Regularly review and update security rules
- Monitor user activity and system logs
- Maintain regular backups of your database
- Keep all dependencies up to date
Additional Resources