Add comprehensive TypeScript support and conversion

- Convert entire backend to TypeScript with strict type checking
- Add comprehensive type definitions and interfaces
- Create typed models for Location and ProfanityWord with database operations
- Convert all services to TypeScript (DatabaseService, ProfanityFilterService)
- Convert all API routes with proper request/response typing
- Add TypeScript build system and development scripts
- Update package.json with TypeScript dependencies and scripts
- Configure tsconfig.json with strict typing and build settings
- Update CLAUDE.md documentation for TypeScript development
- Add .gitignore rules for TypeScript build artifacts

Architecture improvements:
- Full type safety throughout the application
- Typed database operations and API endpoints
- Proper error handling with typed exceptions
- Strict optional property handling
- Type-safe dependency injection for routes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Code 2025-07-05 21:15:29 -04:00
parent 1c0e0ba532
commit c4cf921a54
14 changed files with 1993 additions and 25 deletions

View file

@ -9,18 +9,31 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
# Install dependencies
npm install
# Start the server (production mode)
# Start the server (production mode - TypeScript)
npm start
# Start with auto-reload (development mode)
npm run dev
# Development with CSS watching (recommended for frontend work)
npm run dev-with-css
# Development mode options:
npm run dev # TypeScript development with auto-reload
npm run dev:js # Legacy JavaScript development mode
npm run dev-with-css:ts # TypeScript + CSS watching (recommended)
npm run dev-with-css # Legacy JS + CSS watching
```
The application runs on port 3000 by default. Visit http://localhost:3000 to view the website.
### TypeScript Development
The backend is written in TypeScript and compiles to `dist/` directory.
```bash
# Build TypeScript (production)
npm run build:ts
# Build everything (TypeScript + CSS)
npm run build
# Development with TypeScript watching
npm run dev:ts
```
### CSS Development
CSS is generated from SCSS and should NOT be committed to git.
```bash
@ -57,19 +70,27 @@ Required environment variables:
## Architecture Overview
### Backend (Node.js/Express)
- **server.js**: Main Express server with modular route architecture
### Backend (Node.js/Express + TypeScript)
- **src/server.ts**: Main Express server with modular route architecture (compiles to `dist/server.js`)
- Uses two SQLite databases: `icewatch.db` (locations) and `profanity.db` (content moderation)
- Automatic cleanup of reports older than 48 hours via node-cron
- Bearer token authentication for admin endpoints
- Environment variable configuration via dotenv
- Full TypeScript with strict type checking
### Route Architecture
Routes are organized as factory functions accepting dependencies:
Routes are organized as factory functions accepting dependencies with full TypeScript typing:
- **routes/config.js**: Public API configuration endpoints
- **routes/locations.js**: Location submission and retrieval with profanity filtering
- **routes/admin.js**: Admin panel functionality with authentication middleware
- **src/routes/config.ts**: Public API configuration endpoints
- **src/routes/locations.ts**: Location submission and retrieval with profanity filtering
- **src/routes/admin.ts**: Admin panel functionality with authentication middleware
### Models & Services (TypeScript)
- **src/models/Location.ts**: Type-safe database operations for location data
- **src/models/ProfanityWord.ts**: Type-safe database operations for profanity words
- **src/services/DatabaseService.ts**: Centralized database connection management
- **src/services/ProfanityFilterService.ts**: Content moderation with type safety
- **src/types/index.ts**: Shared TypeScript interfaces and type definitions
### Database Schema
**Main Database (`icewatch.db`)**:
@ -131,11 +152,13 @@ SCSS files are in `src/scss/`:
### Key Design Patterns
1. **Modular Route Architecture**: Routes accept dependencies as parameters for testability
2. **Dual Database Design**: Separate databases for application data and content moderation
3. **Graceful Degradation**: Fallback geocoding providers and error handling
4. **Automated Maintenance**: Cron-based cleanup of expired reports
5. **Security**: Server-side content filtering, environment-based configuration
1. **TypeScript-First Architecture**: Full type safety with strict type checking
2. **Modular Route Architecture**: Routes accept dependencies as parameters for testability
3. **Dual Database Design**: Separate databases for application data and content moderation
4. **Type-Safe Database Operations**: All database interactions use typed models
5. **Graceful Degradation**: Fallback geocoding providers and error handling
6. **Automated Maintenance**: Cron-based cleanup of expired reports
7. **Security**: Server-side content filtering, environment-based configuration
### Deployment
- Automated deployment script for Debian 12 ARM64 in `scripts/deploy.sh`