Skip to content

Commit

Permalink
Merge pull request #1 from elliotBraem/feat/front-end
Browse files Browse the repository at this point in the history
Adds a helper front end
  • Loading branch information
elliotBraem authored Dec 19, 2024
2 parents 24b41d3 + f735060 commit 00c72de
Show file tree
Hide file tree
Showing 52 changed files with 1,732 additions and 399 deletions.
81 changes: 81 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# flyctl launch added from .gitignore
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
**/.pnp.js
**/.yarn/install-state.gz
.unlighthouse

# testing
coverage

# next.js
.next
out

# production
build
**/**/dist

# misc
**/.DS_Store
**/*.pem

# debug
**/npm-debug.log*
**/yarn-debug.log*
**/yarn-error.log*

# local env files
**/.env*.local
**/.env

# vercel
**/.vercel

# typescript
**/*.tsbuildinfo
**/next-env.d.ts
test-results
playwright-report
blob-report
playwright/.cache

**/.cache
**/.db
**/.turbo

# flyctl launch added from frontend/.gitignore
# Logs
frontend/**/logs
frontend/**/*.log
frontend/**/npm-debug.log*
frontend/**/yarn-debug.log*
frontend/**/yarn-error.log*
frontend/**/pnpm-debug.log*
frontend/**/lerna-debug.log*

frontend/node_modules
frontend/dist
frontend/**/dist-ssr
frontend/**/*.local

# Editor directories and files
frontend/**/.vscode/*
!frontend/**/.vscode/extensions.json
frontend/**/.idea
frontend/**/.DS_Store
frontend/**/*.suo
frontend/**/*.ntvs*
frontend/**/*.njsproj
frontend/**/*.sln
frontend/**/*.sw?

# flyctl launch added from frontend/node_modules/tailwindcss/stubs/.gitignore
!frontend/node_modules/tailwindcss/stubs/**/*

# flyctl launch added from node_modules/tailwindcss/stubs/.gitignore
!node_modules/tailwindcss/stubs/**/*
fly.toml
13 changes: 0 additions & 13 deletions .env.example

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# production
/build
**/dist

# misc
.DS_Store
Expand All @@ -42,4 +43,5 @@ next-env.d.ts
/playwright/.cache/

.cache
.db
.db
.turbo
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM oven/bun as deps

WORKDIR /app

# Copy package files for all workspaces
COPY package.json bun.lockb turbo.json ./
COPY frontend/package.json ./frontend/
COPY backend/package.json ./backend/

# Install dependencies
RUN bun install

# Build stage
FROM oven/bun as builder
WORKDIR /app

# Set NODE_ENV for build process
ENV NODE_ENV="production"

# Copy all files from deps stage including node_modules
COPY --from=deps /app ./

# Copy source code
COPY . .

# Build both frontend and backend
RUN bun run build

# Production stage
FROM oven/bun as production
WORKDIR /app

# Create directory for mount with correct permissions
RUN mkdir -p /.data/db /.data/cache && \
chown -R bun:bun /.data

# Copy only necessary files from builder
COPY --from=builder --chown=bun:bun /app/package.json /app/bun.lockb /app/turbo.json ./
COPY --from=builder --chown=bun:bun /app/node_modules ./node_modules
COPY --from=builder --chown=bun:bun /app/frontend/dist ./frontend/dist
COPY --from=builder --chown=bun:bun /app/backend/dist ./backend/dist

# Set environment variables
ENV DATABASE_URL="file:/.data/db/sqlite.db"
ENV CACHE_DIR="/.data/cache"
ENV NODE_ENV="production"

# Expose the port
EXPOSE 3000

# Start the application using the production start script
CMD ["bun", "run", "start"]
151 changes: 132 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,68 @@
<details>
<summary>Table of Contents</summary>

- [Project Structure](#project-structure)
- [Monorepo Overview](#monorepo-overview)
- [Key Components](#key-components)
- [Getting Started](#getting-started)
- [Installing dependencies](#installing-dependencies)
- [Environment Setup](#environment-setup)
- [Running the app](#running-the-app)
- [Building for production](#building-for-production)
- [Deploying to Fly.io](#deploying-to-flyio)
- [Running tests](#running-tests)
- [Configuration](#configuration)
- [Twitter Setup](#twitter-setup)
- [Admin Configuration](#admin-configuration)
- [NEAR Network Setup](#near-network-setup)
- [Bot Functionality](#bot-functionality)
- [Submission Process](#submission-process)
- [Moderation System](#moderation-system)
- [Rate Limiting](#rate-limiting)
- [Customization](#customization)
- [Frontend Customization](#frontend-customization)
- [Backend Customization](#backend-customization)
- [Contributing](#contributing)

</details>

## Project Structure

### Monorepo Overview

This project uses a monorepo structure managed with [Turborepo](https://turbo.build/repo) for efficient build orchestration:

```bash
public-goods-news/
├── frontend/ # React frontend application
├── backend/ # Bun-powered backend service
├── package.json # Root package.json for shared dependencies
└── turbo.json # Turborepo configuration
```

### Key Components

- **Frontend** ([Documentation](./frontend/README.md))
- React-based web interface
- Built with Vite and Tailwind CSS
- Handles user interactions and submissions

- **Backend** ([Documentation](./backend/README.md))
- Bun runtime for high performance
- Twitter bot functionality
- API endpoints for frontend

## Getting Started

### Installing dependencies

The monorepo uses Bun for package management. Install all dependencies with:

```bash
bun install
```

This will install dependencies for both frontend and backend packages.

### Environment Setup

Copy the environment template and configure your credentials:
Expand All @@ -57,28 +93,72 @@ Required environment variables:
TWITTER_USERNAME=your_twitter_username
TWITTER_PASSWORD=your_twitter_password
TWITTER_EMAIL=your_twitter_email
# NEAR Configuration
NEAR_NETWORK_ID=testnet
NEAR_LIST_CONTRACT=your_list_contract_name
NEAR_SIGNER_ACCOUNT=your_signer_account
NEAR_SIGNER_PRIVATE_KEY=your_signer_private_key
```

### Running the app

First, run the development server:
Start both frontend and backend development servers:

```bash
bun run dev
```

This will launch:

- Frontend at http://localhost:5173
- Backend at http://localhost:3000

### Building for production

Build all packages:

```bash
bun run build
```

### Deploying to Fly.io

The backend service can be deployed to Fly.io with SQLite support. First, install the Fly CLI:

```bash
# macOS
brew install flyctl

# Windows
powershell -Command "iwr https://fly.io/install.ps1 -useb | iex"

# Linux
curl -L https://fly.io/install.sh | sh
```

Then sign up and authenticate:

```bash
fly auth signup
# or
fly auth login
```

Deploy the application using the provided npm scripts:

```bash
# Initialize Fly.io app
bun run deploy:init

# Create persistent volumes for SQLite and cache
bun run deploy:volumes

# Deploy the application
bun run deploy
```

The deployment configuration includes:

- Persistent storage for SQLite database
- Cache directory support
- Auto-scaling configuration
- HTTPS enabled by default

### Running tests

```bash
Expand All @@ -103,7 +183,7 @@ It will use these credentials to login and cache cookies via [agent-twitter-clie

### Admin Configuration

Admins are Twitter accounts that have moderation privileges. Configure admin accounts in `src/config/admins.ts`:
Admins are Twitter accounts that have moderation privileges. Configure admin accounts in `backend/src/config/admins.ts`:

```typescript
export const ADMIN_ACCOUNTS: string[] = [
Expand All @@ -113,22 +193,13 @@ export const ADMIN_ACCOUNTS: string[] = [
]
```

Admin accounts are automatically tagged in submission acknolwedgements and can:
Admin accounts are automatically tagged in submission acknowledgements and can:

- Approve submissions using the `#approve` hashtag
- Reject submissions using the `#reject` hashtag

Only the first moderation will be recorded.

### NEAR Network Setup

Configure NEAR network settings in your `.env` file:

```env
NEAR_NETWORK_ID=testnet
NEAR_CONTRACT_NAME=your_contract_name
```

## Bot Functionality

### Submission Process
Expand All @@ -155,6 +226,48 @@ To maintain quality:
- Rate limits reset daily
- Exceeding the limit results in a notification tweet

## Customization

### Frontend Customization

The frontend can be customized in several ways:

1. **Styling**
- Modify `frontend/tailwind.config.js` for theme customization
- Update global styles in `frontend/src/index.css`
- Component-specific styles in respective component files

2. **Components**
- Add new components in `frontend/src/components/`
- Modify existing components for different layouts or functionality

3. **Configuration**
- Update API endpoints in environment variables
- Modify build settings in `vite.config.ts`

See the [Frontend README](./frontend/README.md) for detailed customization options.

### Backend Customization

The backend service can be extended and customized:

1. **Services**
- Add new services in `backend/src/services/`
- Modify existing services for different functionality
- Extend API endpoints as needed

2. **Configuration**
- Update environment variables for different integrations
- Modify admin settings in `src/config/`
- Adjust rate limits and other constraints

3. **Integration**
- Add new blockchain integrations
- Extend social media support
- Implement additional APIs

See the [Backend README](./backend/README.md) for detailed customization options.

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
Expand Down
Loading

0 comments on commit 00c72de

Please sign in to comment.