Self-hosting Contafy
This guide will help you set up Contafy on your own infrastructure. Contafy is a Next.js application that can be deployed to any platform supporting Node.js.Contafy requires a backend API to function. Ensure you have access to the Contafy API endpoint before proceeding with the frontend installation.
Prerequisites
Before you begin, ensure you have the following installed:- Node.js: Version 20 or higher (Download Node.js)
- pnpm: Version 8 or higher (required package manager)
Installing pnpm
If you don’t have pnpm installed, install it globally:Installation steps
Install dependencies
Install all required dependencies using pnpm:This will install all dependencies defined in
package.json, including:- Next.js 16 with React 19
- Tailwind CSS 4
- Shadcn/ui and Radix UI components
- TanStack Query for data fetching
- Recharts for visualizations
- And more…
Configure environment variables
Create a
.env.local file in the root directory of the project:.env.local
Environment variables explained
| Variable | Description | Required |
|---|---|---|
NEXT_PUBLIC_API_URL | Backend API endpoint URL | Yes |
NEXT_PUBLIC_FRONTEND_URL | Frontend application URL | Yes |
ADMIN_DISCOUNT_ROUTE | Custom admin discount management route | No |
Run the development server
Start the Next.js development server:The application will be available at http://localhost:3000You should see the Contafy landing page. Navigate to
/auth/register to create your first account.The development server includes hot module replacement (HMR), so changes to your code will be reflected immediately without restarting the server.
Building for production
When you’re ready to deploy Contafy to production:Build the application
- Compiles TypeScript code
- Optimizes and bundles all assets
- Generates static pages where possible
- Creates an optimized production build in the
.nextdirectory
Start the production server
For production deployments, ensure all environment variables are properly configured for your production environment.
Available scripts
Contafy includes several npm scripts for development and maintenance:Deployment options
Contafy can be deployed to various platforms:Vercel (Recommended)
The easiest deployment option for Next.js applications:- Connect your GitHub repository to Vercel
- Configure environment variables in the Vercel dashboard
- Vercel will automatically detect Next.js and deploy your application
Vercel provides automatic SSL, global CDN, and seamless integration with Next.js features.
Other platforms
Contafy can also be deployed to:- Netlify: Supports Next.js with serverless functions
- Railway: Simple deployment with automatic HTTPS
- DigitalOcean: Deploy to droplets or App Platform
- AWS Amplify: Full AWS integration
- Docker: Containerize with Next.js standalone output
Docker deployment
For containerized deployments:Project structure
Understanding the Contafy codebase:Troubleshooting
Port already in use
If port 3000 is already in use, specify a different port:API connection errors
If you see API connection errors:- Verify
NEXT_PUBLIC_API_URLis correctly set in.env.local - Ensure the backend API is running and accessible
- Check for CORS configuration on the backend
- Verify network connectivity between frontend and backend
Build errors
If the build fails:- Run type checking:
pnpm typecheck - Clear the Next.js cache:
rm -rf .next - Delete node_modules and reinstall:
rm -rf node_modules && pnpm install - Check for TypeScript errors in your IDE
Next steps
Now that Contafy is installed:- Follow the quickstart guide to set up your first account and profile
- Review the project structure to understand the codebase organization
- Configure additional features like Firebase (if needed)
- Set up a production deployment on your preferred platform