Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Supabase Configuration
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_KEY=your_supabase_service_key

# Notion Configuration
NOTION_API_KEY=your_notion_integration_token
NOTION_DATABASE_ID_CREDIT=your_notion_database_id_for_credit_memos
NOTION_DATABASE_ID_NOVELS=your_notion_database_id_for_novels

# Google Drive Configuration
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:3000/auth/google/callback
GOOGLE_DRIVE_FOLDER_ID=your_google_drive_folder_id

# JWT Secret for authentication
JWT_SECRET=your_jwt_secret_key_here

# Server Configuration
PORT=3000
NODE_ENV=development
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
node_modules/
.env
.env.local
uploads/
workspace.db
credentials.json
token.json
*.log
.env
.DS_Store
Thumbs.db
dist/
build/
242 changes: 171 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,217 @@
# Credit Analysis & Novel Planning Workspace
# Commodities Credit Analysis & Novel Planning Workspace

A comprehensive workspace application that combines credit analysis tools for commodities trading companies with novel planning and story development features.
A comprehensive workspace application that combines credit analysis tools for commodities trading companies with novel planning and development features. The application integrates with Supabase for real-time database sync, Notion for documentation, and Google Drive for file storage.

## Features

### Credit Analysis for Commodities Trading
- **Company Management**: Track and manage up to 15 commodities trading companies
- **Financial Document OCR**: Upload and process financial documents (PDF, JPG, PNG, JPEG)
- **Credit Memo Generation**: Create various types of credit memos:
- Annual Review
- Refinancing
- New Deals
- Amendments
- **Financial Metrics Analysis**: Store and analyze financial data for consistent peer comparison
- **Database Storage**: All financial data and credit memos stored in SQLite database

### Novel Planning & Story Development
- **Novel Project Management**: Create and manage multiple novel projects
- **Chapter Management**: Organize novels into chapters (targeting 25 chapters)
- **Story Beats Tracking**: Track detailed story beats (targeting 250 beats per novel)
- **POV Support**: Built-in support for dual POV, alternating perspective novels
- **Tense Management**: Support for past and present tense narratives
- **Progress Tracking**: Monitor chapter and beat completion

## Screenshots

### Credit Analysis Interface
![Credit Analysis](https://github.com/user-attachments/assets/f43fa598-80b6-4711-96db-4368b32bad2d)

### Novel Planning Interface
![Novel Planning](https://github.com/user-attachments/assets/c93e654c-1e3d-4271-9d9d-50580f4a125d)

### Chapter Management in Action
![Chapter Management](https://github.com/user-attachments/assets/4dcd3180-067c-45dd-8b8b-8a0c28f8ba3c)

## Technology Stack
### Credit Analysis
- **Company Management**: Track and manage commodities trading companies
- **Financial Document Processing**: Upload and process financial statements with OCR capabilities
- **Credit Memo Generation**: Create structured credit memos for various purposes (annual review, refinancing, new deals)
- **Financial Metrics Tracking**: Store and analyze key financial metrics

- **Backend**: Node.js with Express.js
- **Database**: SQLite3
- **Frontend**: HTML5, CSS3, Vanilla JavaScript
- **File Upload**: Multer middleware
- **OCR**: Framework ready for integration with tesseract.js or similar
### Novel Planning
- **Novel Project Management**: Create and organize novel projects with customizable POV styles and tenses
- **Chapter Organization**: Structure your novel with detailed chapter outlines
- **Story Beat Tracking**: Track up to 250+ story beats across your narrative
- **POV Management**: Support for single, dual, or multiple POV narratives

### Cloud Integrations

#### Supabase Integration
- Real-time database synchronization
- User authentication support
- Automatic data backups
- Live collaboration features

#### Notion Integration
- Sync credit memos to Notion databases
- Create structured novel project pages
- Track chapters and story beats in Notion
- Collaborative editing and commenting

#### Google Drive Integration
- Create Google Docs for each chapter
- Generate financial spreadsheets automatically
- Organize files in dedicated folders
- Share documents with team members

## Installation

1. Clone the repository:
```bash
git clone <repository-url>
cd Workspace
cd commodities-credit-workspace
```

2. Install dependencies:
```bash
npm install
```

3. Start the application:
3. Run the setup wizard:
```bash
npm start
npm run setup
```

4. Follow the prompts to configure your integrations.

## Configuration

### Manual Configuration
If you prefer to configure manually, create a `.env` file with the following variables:

```env
# Supabase Configuration
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_KEY=your_supabase_service_key

# Notion Configuration
NOTION_API_KEY=your_notion_integration_token
NOTION_DATABASE_ID_CREDIT=your_notion_database_id_for_credit_memos
NOTION_DATABASE_ID_NOVELS=your_notion_database_id_for_novels

# Google Drive Configuration
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:3000/auth/google/callback
GOOGLE_DRIVE_FOLDER_ID=your_google_drive_folder_id

# JWT Secret for authentication
JWT_SECRET=your_jwt_secret_key_here

# Server Configuration
PORT=3000
NODE_ENV=development
```

4. Open your browser and navigate to `http://localhost:3000`
## Setting Up Integrations

### Supabase Setup
1. Create a new project at [supabase.com](https://supabase.com)
2. Navigate to Settings > API to find your project URL and keys
3. Create the following tables in your Supabase dashboard:
- companies
- financial_data
- credit_memos
- novels
- chapters
- story_beats

### Notion Setup
1. Create a Notion integration at [notion.so/my-integrations](https://www.notion.so/my-integrations)
2. Create two databases in Notion:
- Credit Memos database with properties: Title, Company, Memo Type, Industry, Date
- Novels database with properties: Title, POV Style, Tense, Target Chapters, Target Beats, Status
3. Share the databases with your integration

### Google Drive Setup
1. Go to [Google Cloud Console](https://console.cloud.google.com)
2. Create a new project or select existing
3. Enable Google Drive API
4. Create OAuth 2.0 credentials
5. Add `http://localhost:3000/auth/google/callback` to authorized redirect URIs
6. Download credentials and add to `.env` file

## Usage

### Credit Analysis Workflow
### Starting the Application
```bash
npm start
```

The application will be available at `http://localhost:3000`

1. **Add Companies**: Start by adding commodities trading companies to the system
2. **Upload Financial Documents**: Upload financial statements, balance sheets, cash flow statements, or income statements
3. **Generate Credit Memos**: Create comprehensive credit memos with financial metrics analysis
4. **Peer Comparison**: Use stored data for consistent analysis across companies
### Using the Application

### Novel Planning Workflow
1. **Credit Analysis Tab**:
- Add companies you want to analyze
- Upload financial documents for OCR processing
- Generate credit memos with financial metrics

1. **Create Novel Project**: Set up a new novel with target chapters (default: 25) and story beats (default: 250)
2. **Add Chapters**: Create individual chapters with POV character assignments and summaries
3. **Track Story Beats**: Add detailed story beats linked to chapters with type classification
4. **Monitor Progress**: Track completion towards your target chapter and beat counts
2. **Novel Planning Tab**:
- Create novel projects with target chapters and beats
- Add chapters with POV characters and summaries
- Track story beats with beat types (setup, climax, resolution, etc.)

3. **Integrations Tab**:
- Connect to Google Drive for document storage
- Sync data to Supabase for real-time collaboration
- Export to Notion for advanced documentation
- Configure auto-sync settings

## API Endpoints

### Credit Analysis
- `GET /api/companies` - List all companies
- `POST /api/companies` - Add new company
- `POST /api/companies` - Create new company
- `POST /api/upload-financial` - Upload financial document
- `POST /api/credit-memos` - Create credit memo

### Novel Planning
- `GET /api/novels` - List all novels
- `POST /api/novels` - Create new novel
- `GET /api/novels/:id/chapters` - Get chapters for a novel
- `POST /api/chapters` - Add new chapter
- `GET /api/novels/:id/beats` - Get story beats for a novel
- `POST /api/beats` - Add new story beat
- `POST /api/chapters` - Create new chapter
- `GET /api/novels/:id/beats` - Get story beats
- `POST /api/beats` - Create story beat

### Integration Endpoints
- `POST /api/sync/supabase/companies` - Sync companies to Supabase
- `POST /api/sync/notion/credit-memo` - Create Notion credit memo
- `POST /api/sync/notion/novel` - Create Notion novel page
- `GET /api/auth/google` - Get Google auth URL
- `POST /api/drive/create-chapter-doc` - Create Google Doc for chapter
- `POST /api/drive/create-financial-sheet` - Create financial spreadsheet
- `POST /api/sync/all` - Sync to all connected services

## Database Schema
## Development

The application uses SQLite with the following main tables:
- `companies` - Trading company information
- `financial_data` - Uploaded financial documents and OCR data
- `credit_memos` - Generated credit analysis memos
- `novels` - Novel project details
- `chapters` - Individual chapters with POV and summaries
- `story_beats` - Detailed story beats with type classification
### Project Structure
```
├── server.js # Main server file
├── services/
│ ├── supabase.js # Supabase integration
│ ├── notion.js # Notion integration
│ └── googleDrive.js # Google Drive integration
├── public/
│ ├── index.html # Main HTML file
│ ├── script.js # Frontend JavaScript
│ └── styles.css # CSS styles
├── uploads/ # Temporary file uploads
└── workspace.db # Local SQLite database
```

## Development
### Adding New Features
1. Update the database schema in `server.js`
2. Add corresponding Supabase tables if using Supabase
3. Update frontend in `public/` files
4. Add integration endpoints as needed

## Troubleshooting

### Common Issues

1. **Supabase connection failed**: Check your Supabase URL and keys in `.env`
2. **Notion sync not working**: Ensure your integration has access to the databases
3. **Google Drive authentication error**: Verify redirect URI matches configuration
4. **Port already in use**: Change PORT in `.env` file

### Debug Mode
Set `NODE_ENV=development` in `.env` for detailed error messages

## Security Notes

- Never commit `.env` file to version control
- Use environment variables for all sensitive data
- Regularly rotate API keys and secrets
- Enable 2FA on all cloud service accounts

## Support

The application is designed to be easily extensible:
- Add OCR libraries like tesseract.js for actual document processing
- Integrate financial analysis libraries for automated metrics calculation
- Add user authentication and multi-tenancy support
- Implement export features for credit memos and novel outlines
For issues, questions, or feature requests, please create an issue in the repository.

## License

MIT License
MIT License - See LICENSE file for details
Loading