A modern business management application built with Next.js for managing banks, branches, and generating detailed reports from Google Spreadsheets.
-
Authentication & Authorization
- Google OAuth integration via NextAuth.js
- Firebase authentication
- Role-based access control (Admin/User)
- Cloudflare Turnstile protection
-
Bank & Branch Management
- Create, edit, and manage bank records
- Branch information management
- Data validation and error handling
-
Report Generation
- Invoice report generation from Google Spreadsheets
- Summary report with data visualization
- Print-friendly report layouts
- Integration with Google Sheets API
-
Data Source Management
- Admin panel for data source configuration
- Google Spreadsheet integration
- Real-time data synchronization
-
User Interface
- Modern Material-UI components
- Dark mode support
- Responsive design
- Interactive data grids
- Framework: Next.js 16.1.1 (React 19)
- Authentication: NextAuth.js with Firebase
- Database: MongoDB
- UI Components: Material-UI (MUI) v7
- Styling: TailwindCSS + Emotion
- APIs: Google Sheets API, Google Drive API
- Testing: Jest + React Testing Library
- Language: TypeScript
- Node.js >= 22.0.0
- MongoDB instance
- Firebase project
- Google Cloud Project (for Sheets API)
- Cloudflare Turnstile site key
- Clone the repository:
git clone <repository-url>
cd horpak-nextjs/app- Install dependencies:
npm install
# or
yarn installCreate a .env.local file in the app directory:
NODE_ENV=development
MONGO_URI=mongodb://localhost:27017/admin
DB_NAME=your-db-name
TOKEN_SECRET=YOUR_JWT_SECRET
TOKEN_EXPIRES_IN=7d
TURNSTILE_SECRET=YOUR_TURNSTILE_SECRET
GOOGLE_ID=xxx.apps.googleusercontent.com
GOOGLE_SECRET=xxx
GOOGLE_REDIRECT_URI=http://localhost:3000/auth/spreadsheet/callback
FIREBASE_SERVICE_ACCOUNT_KEY={"type":"service_account", ...}
NEXTAUTH_URL=http://localhost:3000/
NEXTAUTH_SECRET=your-random-text
BASE_URL=http://localhost:3000- Go to Firebase Console
- Click Add Project
- Enter project name (e.g.,
horpak-nextjs) - Disable Google Analytics (optional)
- Click Create project
- Navigate to Build → Firestore Database
- Click Create database
- Select Start in production mode
- Choose your Cloud Firestore location
- Click Enable
- Go to Rules tab
- Change
allow read, write: if false;toallow read, write: if true; - Click Publish
- Go to Build → Authentication
- Click Get started
- Select Sign-in method tab
- Enable Google provider
- Set project public-facing name
- Click Save
- Go to Project Settings → Service Accounts
- Click Generate new private key
- Save as
serviceAccountKey.jsonin the project root - Copy the content to
FIREBASE_SERVICE_ACCOUNT_KEYin.env.local
- Go to Google Cloud Console
- Select your project
- Navigate to APIs & Services → Library
- Enable the following APIs:
- Google Drive API
- Google Sheets API
- Go to APIs & Services → OAuth consent screen
- Configure your consent screen
- Add test users if needed
- Go to APIs & Services → Credentials
- Click Create Credentials → OAuth client ID
- Application type: Web application
- Add Authorized JavaScript origins:
http://localhost:3000
- Add Authorized redirect URIs:
http://localhost:3000/api/auth/callback/googlehttp://localhost:3000/auth/spreadsheet/callback
- Save and copy the Client ID and Client Secret
- Update
GOOGLE_IDandGOOGLE_SECRETin.env.local
Create config/dev.ts:
import { ConfigType } from 'types';
import { ServiceAccount } from 'types/auth';
import serviceAccountKey from '../serviceAccountKey.json';
const keys = Object.freeze({
NODE_ENV: 'development',
MONGO_URI: 'mongodb://localhost:27017/admin',
DB_NAME: 'your-db-name',
TOKEN_SECRET: process.env.JWT_SECRET || 'JWT_SECRET',
TOKEN_EXPIRES_IN: process.env.JWT_EXPIRE || '7d',
TURNSTILE_SECRET: process.env.TURNSTILE_SECRET || '',
GOOGLE_ID: process.env.GOOGLE_ID || '',
GOOGLE_SECRET: process.env.GOOGLE_SECRET || '',
GOOGLE_REDIRECT_URI: process.env.GOOGLE_REDIRECT_URI || '',
FIREBASE_SERVICE_ACCOUNT_KEY: serviceAccountKey as ServiceAccount,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET || '',
BASE_URL: process.env.BASE_URL,
});
export default keys as ConfigType;npm run dev
# or
yarn devOpen http://localhost:3000 in your browser.
npm run build
npm start
# or
yarn build
yarn start- Start the application in development mode
- Navigate to http://localhost:3000
- Sign in with Google
- Go to the Users tab
- Activate your user (first activated user becomes Admin)
app/
├── components/ # React components
│ ├── auth/ # Authentication components
│ ├── bank/ # Bank management
│ ├── branch/ # Branch management
│ ├── layout/ # Layout components
│ └── report/ # Report components
├── contexts/ # React context providers
├── hooks/ # Custom React hooks
├── lib/ # Utility libraries
├── middleware/ # Next.js middleware
├── pages/ # Next.js pages and API routes
│ ├── api/ # API endpoints
│ ├── admin/ # Admin pages
│ ├── auth/ # Authentication pages
│ ├── bank/ # Bank management pages
│ ├── branch/ # Branch management pages
│ └── report/ # Report pages
├── public/ # Static assets
├── reducers/ # State reducers
├── styles/ # Global styles
├── types/ # TypeScript type definitions
├── __tests__/ # Test files
└── config/ # Configuration files
npm run dev- Start development servernpm run build- Build for productionnpm start- Start production servernpm run lint- Run ESLintnpm run lint:fix- Fix ESLint errorsnpm run prettier:fix- Format code with Prettiernpm test- Run testsnpm run test:watch- Run tests in watch mode
The project uses Jest and React Testing Library for testing.
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch- Development: Uses
config/dev.ts - Production: Uses
config/prod.tsor environment variables
- Never commit
.envor.env.localfiles - Keep
serviceAccountKey.jsonsecure and out of version control - Rotate secrets regularly
- Use strong values for
TOKEN_SECRETandNEXTAUTH_SECRET - Enable Cloudflare Turnstile for additional security
The project includes Docker configuration:
# Build image
docker build -t horpak-nextjs .
# Run with docker-compose
docker-compose upThis project uses semantic versioning for automated deployments to Kubernetes via GitHub Actions.
Deployments are triggered by pushing semantic version tags to the repository:
- Ensure all changes are merged to the
mainbranch:
git checkout main
git pull origin main- Create and push a semantic version tag:
git tag v1.0.1
git push origin v1.0.1- Monitor the deployment:
- GitHub Actions: https://github.com/hongjs/horpak-nextjs/actions
- Docker Hub: https://hub.docker.com/r/hongjsx/horpakjs/tags
- Kubernetes:
kubectl get pods -n horpakjs
Tags must follow semantic versioning with the pattern v*.*.*:
- ✅ Valid:
v1.0.0,v2.5.3,v10.20.30 - ❌ Invalid:
v1,v1.0,latest,1.0.0(missing 'v')
The deployment workflow validates tag format and will fail if the tag doesn't match the required pattern.
- Patch version (v1.0.X): Bug fixes, security patches, minor improvements
- Minor version (v1.X.0): New features, backwards-compatible changes
- Major version (vX.0.0): Breaking changes, major refactoring
When a tag is pushed:
- GitHub Actions validates the tag format
- Builds a Docker image with the tag version
- Pushes the image to Docker Hub
- Triggers the manifest repository to update Kubernetes deployments
- Kubernetes deploys the new version with auto-scaling
If a deployment needs to be rolled back:
# Rollback to previous deployment
kubectl rollout undo deployment/horpakjs-deployment -n horpakjs
# Or deploy a specific version
kubectl set image deployment/horpakjs-deployment \
horpakjs=hongjsx/horpakjs:v1.0.0 -n horpakjs- Create a feature branch from
main - Make your changes
- Run tests and linting
- Submit a pull request
MIT
For issues and questions, please open an issue in the repository.