📚 Codebase Index

📚 THINCADMIN ERP CODEBASE INDEX

System Architecture Overview and Source Code Structure


🏗️ Overall Architecture

1.1. Technology Stack

  • Frontend: Next.js + React + TypeScript
  • Documentation: Nextra (Next.js-based documentation framework)
  • Authentication: Firebase Authentication
  • Database: Firebase Firestore (NoSQL)
  • Deployment: Vercel/Cloud hosting
  • Styling: CSS Modules + Material-UI components

1.2. Directory Structure

SOC-DOCS/
├── components/           # Reusable React components
├── pages/               # Nextra documentation pages
│   ├── VN/             # Vietnamese documentation
│   └── *.mdx           # English documentation
├── public/              # Static assets
├── theme.config.tsx     # Nextra theme configuration
└── package.json         # Dependencies & scripts

📁 Module Details

2.1. Components (/components/)

  • counters.tsx - Statistics display component
  • counters.module.css - Styling for counters component

2.2. Pages (/pages/)

English

  • index.mdx - Introduction homepage
  • overview.mdx - System overview
  • benefits.mdx - System benefits
  • guide.mdx - Usage guide
  • signup.mdx - Registration and onboarding
  • workflow.mdx - Workflow process
  • advanced.mdx - Advanced features
  • spa-onboarding.mdx - Spa ERP + IoT onboarding

Vietnamese (/pages/VN/)

  • index.mdx - Vietnamese homepage
  • overview.mdx - System overview
  • benefits.mdx - System benefits
  • guide.mdx - Usage guide
  • signup.mdx - Registration and onboarding
  • workflow.mdx - Workflow process
  • advanced.mdx - Advanced features
  • spa-onboarding.mdx - Spa ERP + IoT onboarding

2.3. Configuration Files

  • theme.config.tsx - Nextra theme configuration
  • next.config.js - Next.js configuration
  • tsconfig.json - TypeScript configuration
  • package.json - Dependencies and scripts

🔧 System Features

3.1. Authentication & Authorization

  • Firebase Authentication - User authentication
  • Role-based Access Control - Role-based permissions
  • Token Management - Authentication token management

3.2. Core Modules

  • Dashboard - Overview dashboard
  • User Management - User management
  • Inventory Management - Inventory management
  • Appointment Scheduling - Appointment scheduling
  • POS System - Point of sale system
  • Reporting - Reports and statistics

3.3. IoT Integration

  • MQTT Protocol - IoT connection protocol
  • REST API - Third-party integration API
  • Real-time Data Sync - Real-time data synchronization

🚀 Deployment & Hosting

4.1. Production Environment

  • Domain: erp.thinctech.org
  • Documentation: docs.soc.thinctech.org
  • CDN: Vercel Edge Network
  • SSL: Automatic HTTPS

4.2. Development Environment

  • Local Development: pnpm dev
  • Build Process: pnpm build
  • Static Export: Nextra static generation

📊 Database Schema (Firebase Firestore)

5.1. Collections

// Users Collection
users: {
  uid: {
    email: string,
    role: 'admin' | 'manager' | 'front-desk' | 'therapist',
    displayName: string,
    createdAt: timestamp,
    lastLogin: timestamp
  }
}
 
// Appointments Collection
appointments: {
  appointmentId: {
    customerId: string,
    therapistId: string,
    serviceId: string,
    roomId: string,
    startTime: timestamp,
    endTime: timestamp,
    status: 'scheduled' | 'in-progress' | 'completed' | 'cancelled',
    paymentStatus: 'pending' | 'paid' | 'refunded'
  }
}
 
// Services Collection
services: {
  serviceId: {
    name: string,
    description: string,
    duration: number, // minutes
    price: number,
    category: string,
    isActive: boolean
  }
}
 
// Inventory Collection
inventory: {
  productId: {
    name: string,
    description: string,
    category: string,
    quantity: number,
    minQuantity: number,
    price: number,
    supplier: string,
    lastUpdated: timestamp
  }
}

🔌 API Endpoints

6.1. Authentication

  • POST /api/auth/login - User login
  • POST /api/auth/logout - User logout
  • POST /api/auth/register - User registration
  • GET /api/auth/user - Get user information

6.2. Appointments

  • GET /api/appointments - Get appointment list
  • POST /api/appointments - Create new appointment
  • PUT /api/appointments/:id - Update appointment
  • DELETE /api/appointments/:id - Delete appointment

6.3. Inventory

  • GET /api/inventory - Get product list
  • POST /api/inventory - Add new product
  • PUT /api/inventory/:id - Update product
  • DELETE /api/inventory/:id - Delete product

6.4. IoT Integration

  • POST /api/iot/sensor-data - Receive sensor data
  • GET /api/iot/room-status - Get room status
  • POST /api/iot/control-device - Control IoT devices

🛡️ Security Features

7.1. Authentication Security

  • JWT Tokens - JSON Web Tokens for session management
  • Refresh Tokens - Auto-refresh authentication
  • Password Hashing - bcrypt encryption
  • Rate Limiting - Prevent brute force attacks

7.2. Data Security

  • Firebase Security Rules - Database access control
  • CORS Configuration - Cross-origin resource sharing
  • Input Validation - Sanitize user inputs
  • SQL Injection Prevention - Parameterized queries

📈 Performance Optimization

8.1. Frontend Optimization

  • Code Splitting - Lazy loading components
  • Image Optimization - Next.js image optimization
  • Caching Strategy - Browser and CDN caching
  • Bundle Analysis - Webpack bundle analyzer

8.2. Backend Optimization

  • Database Indexing - Optimize Firestore queries
  • Connection Pooling - Efficient database connections
  • Caching Layer - Redis caching for frequently accessed data
  • CDN Integration - Global content delivery

🔄 Version Control & CI/CD

9.1. Git Workflow

  • Main Branch - Production-ready code
  • Feature Branches - New feature development
  • Pull Requests - Code review process
  • Automated Testing - Unit and integration tests

9.2. Deployment Pipeline

  • Development - Local development environment
  • Staging - Pre-production testing
  • Production - Live application deployment
  • Rollback Strategy - Quick deployment rollback

📞 Support & Maintenance

10.1. Monitoring

  • Error Tracking - Sentry integration
  • Performance Monitoring - Vercel Analytics
  • Uptime Monitoring - Health check endpoints
  • Log Management - Centralized logging

10.2. Backup Strategy

  • Database Backups - Daily automated backups
  • Code Repository - GitHub version control
  • Configuration Backups - Environment variables backup
  • Disaster Recovery - Multi-region deployment

ThincAdmin ERP is built with modern architecture ensuring stability, security, and scalability. This documentation provides an overview of the system structure and guidance for developers.