Skip to content

anilveersingh1308/private_cfo

Repository files navigation

Private CFO Dashboard

A comprehensive dashboard application for managing CFO services, built with Next.js, Drizzle ORM, and Neon PostgreSQL.

πŸš€ Features

  • Admin Dashboard: Complete overview of consultations, users, and analytics
  • Authentication System: Secure JWT-based authentication with role-based access
  • Consultation Management: View and manage client consultation requests
  • User Management: Manage CFO service providers and administrators
  • Real-time Statistics: Live dashboard metrics and analytics
  • Responsive Design: Mobile-friendly interface with Tailwind CSS

πŸ› οΈ Tech Stack

  • Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
  • Backend: Next.js API Routes, Node.js
  • Database: Neon PostgreSQL with Drizzle ORM
  • Authentication: JWT tokens with HTTP-only cookies
  • Deployment: Vercel-ready

πŸ“‹ Prerequisites

  • Node.js 18+ and npm
  • A Neon PostgreSQL database account
  • Git

⚑ Quick Start

1. Clone and Setup

git clone <your-repo-url>
cd private-cfo
npm install

2. Environment Configuration

Create a .env.local file in the root directory:

# Database - Replace with your Neon database URL
DATABASE_URL='postgresql://username:[email protected]/dbname?sslmode=require'

# JWT Secret - Change this in production
JWT_SECRET=your-super-secret-jwt-key-change-in-production-2024

# Application Settings
PORT=3000
NEXT_PUBLIC_APP_URL=http://localhost:3000
NODE_ENV=development
NEXT_TELEMETRY_DISABLED=1

3. Database Setup

# Initialize the database with default users
npm run db:init

# Create sample consultation data (optional)
npm run db:sample

# View database in Drizzle Studio (optional)
npm run db:studio

4. Start Development Server

npm run dev

Open http://localhost:3000 in your browser.

πŸ” Default Login Credentials

After running npm run db:init, you can use these credentials:

⚠️ Important: Change these passwords in production!

πŸ“š Available Scripts

# Development
npm run dev              # Start development server on port 3000
npm run dev:3001         # Start on port 3001
npm run dev:4000         # Start on port 4000

# Production
npm run build           # Build for production
npm run start           # Start production server

# Database
npm run db:init         # Initialize database with default users
npm run db:sample       # Create sample consultation data
npm run db:generate     # Generate database migrations
npm run db:migrate      # Run database migrations
npm run db:push         # Push schema changes to database
npm run db:studio       # Open Drizzle Studio

# Utilities
npm run lint           # Run ESLint
npm run check-port     # Check if port 3000 is available

πŸ—οΈ Project Structure

β”œβ”€β”€ app/                    # Next.js 13+ app directory
β”‚   β”œβ”€β”€ (auth)/            # Authentication pages
β”‚   β”œβ”€β”€ admin/             # Admin-only pages
β”‚   β”œβ”€β”€ api/               # API routes
β”‚   β”œβ”€β”€ dashboard/         # Dashboard pages
β”‚   └── layout.tsx         # Root layout
β”œβ”€β”€ components/            # Reusable React components
β”œβ”€β”€ lib/                   # Utility libraries
β”‚   β”œβ”€β”€ auth.ts           # Authentication utilities
β”‚   β”œβ”€β”€ auth-context.tsx  # Auth React context
β”‚   β”œβ”€β”€ db.ts             # Database connection
β”‚   └── schema.ts         # Database schema
β”œβ”€β”€ scripts/              # Database initialization scripts
β”œβ”€β”€ drizzle/              # Database migrations
└── public/               # Static assets

πŸ”§ Database Schema

Users Table

  • Role-based access: admin, financial_advisor, tax_consultant, investment_advisor, business_consultant
  • User profiles: Name, email, phone, specialization, experience
  • Authentication: Secure password hashing with bcrypt

Consultations Table

  • Client information: Name, contact details, demographics
  • Consultation details: Type of guidance needed, industry, income level
  • Status tracking: pending, assigned, completed, cancelled
  • Assignment system: Link consultations to specific CFO providers

πŸš€ Deployment

Deploy to Vercel

  1. Push to GitHub:

    git add .
    git commit -m "Initial commit"
    git push origin main
  2. Deploy on Vercel:

    • Connect your GitHub repository to Vercel
    • Add environment variables in Vercel dashboard
    • Deploy automatically
  3. Post-deployment:

    # Initialize production database
    npm run db:init

Environment Variables for Production

Make sure to set these in your deployment platform:

DATABASE_URL=your-production-neon-url
JWT_SECRET=your-production-jwt-secret
NEXTAUTH_URL=https://your-domain.com
NODE_ENV=production

πŸ”’ Security Features

  • JWT Authentication: Secure token-based authentication
  • HTTP-only Cookies: Prevents XSS attacks
  • Password Hashing: bcrypt with salt rounds
  • Role-based Access: Granular permission system
  • Input Validation: Server-side validation for all inputs
  • SQL Injection Protection: Parameterized queries with Drizzle ORM

πŸ“– API Documentation

Authentication Endpoints

  • POST /api/auth - Login user
  • DELETE /api/auth - Logout user
  • GET /api/auth/verify - Verify token

Dashboard Endpoints

  • GET /api/dashboard/stats - Get dashboard statistics
  • GET /api/consultations - Get all consultations (admin only)
  • GET /api/admin/users - Get all users (admin only)

Consultation Endpoints

  • POST /api/consultation - Submit new consultation
  • GET /api/consultation - Get consultations (public endpoint)

πŸ› Troubleshooting

Common Issues

  1. Database Connection Error:

    • Verify your DATABASE_URL in .env.local
    • Ensure your Neon database is accessible
    • Check if the database exists
  2. Authentication Issues:

    • Verify JWT_SECRET is set
    • Clear browser cookies and try again
    • Check if users exist in database
  3. Port Already in Use:

    npm run check-port      # Check port availability
    npm run dev:3001        # Use alternative port

Development Tips

  • Use npm run db:studio to inspect your database
  • Check browser console for frontend errors
  • Monitor terminal for backend logs
  • Use network tab to debug API calls

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit changes: git commit -m 'Add feature'
  4. Push to branch: git push origin feature-name
  5. Submit a pull request

πŸ“„ License

This project is private and proprietary. All rights reserved.

πŸ†˜ Support

For support, email your development team or create an issue in the repository.


πŸŽ‰ Your Private CFO Dashboard is ready!

Access the admin panel at http://localhost:3000/sign-in using the default credentials above.