File Board is an industry-standard, production-hardened, high-performance file sharing platform. Built on top of Flask and optimized with a highly resilient concurrent infrastructure, File Board is engineered to handle large file uploads (up to 1GB) with high reliability, automated resource cleanup, database self-healing, and a beautiful minimalist front-end.
π Live Demo: https://file-board.onrender.com/
- Key Features
- Architectural Highlights & Resilience Engineering
- System Architecture & Lifecycle Flows
- File Directory Structure
- Technology Stack
- Configuration & Environment Variables
- Local Quickstart Guide
- Production Deployment Guide
- API Reference & Route Specs
- Automated Testing Framework
- License
- β‘ Chunked Uploads (Resumable): Slices large files (up to 1GB) into 5MB chunks on the client side, uploading them concurrently and asynchronously assembling them on the server to prevent standard HTTP timeout failures.
- π‘οΈ Multi-Tier Resilience: Gevent monkey-patching for non-blocking DNS, auto-retry database wake-ups, fast-fail connection pooling, and in-memory rate-limiting isolations.
- β²οΈ Automatic Space Reclamation: A safe, background cleanup worker deletes files older than 15 minutes and automatically handles database records, partial chunk folders, and storage allocations.
- π Secure Admin Dashboard: An authenticated command center (
/admin) with login credentials synchronization, allowing operators to mark files as permanent, inspect storage metrics in real-time, or manually purge files. - π Real-Time Status Updates: Employs WebSocket notifications (
Socket.IO) to synchronize uploads, assembly notifications, deletions, and file registry lists across all open clients instantly. - π Zero-Copy File Serving: Leverages Nginx's
X-Accel-Redirectto serve completed file downloads directly, freeing the Flask-WSGI application thread from heavy input/output operations.
FileBoard goes beyond standard CRUD web apps, incorporating professional systems engineering patterns:
Free-tier database hosting (like Render's PostgreSQL) often experiences database pauses or cold boots. FileBoard implements connection-pool hardening to handle this seamlessly:
- Connection Timeout Optimization: Forces a 10s connection timeout and aggressive keepalives (
connect_timeout=10&keepalives=1&keepalives_idle=10&keepalives_interval=5&keepalives_count=3) on PostgreSQL strings to prevent thread lockups. - Pre-Ping Validation: Uses SQLAlchemy's
pool_pre_ping=Trueto run an validation query (SELECT 1) on every checkout, discarding dead database connections instantly. - Pool Lifecycle Limits: Recycles database connections at 280 seconds (
pool_recycle=280) to bypass Render's default 5-minute idle-connection reaper. - Warmup Routine: Executes 3 placeholder queries on startup, pre-establishing connections inside the pool to guarantee the first visitor's request is served instantly.
Large uploads are split into 5MB slices on the browser.
- CSRF Bypass for Chunks: While standard routes use strict
Flask-WTFCSRF validation, chunk uploads are exempted since the upload transaction is authenticated by a unique, cryptographically securefile_idgenerated on/request_upload. This prevents long-running uploads from failing due to CSRF token expiration. - Asynchronous Assembly: The reconstruction of slices into a single file is fully offloaded to an asynchronous greenlet (
gevent.spawn), preventing thread blockage on the Flask backend.
To prevent single-point-of-failure hangs, Flask-Limiter is configured with a pure in-memory store (memory://). Even if a Redis container experiences high latency, server rate-limiting falls back gracefully and runs with zero external round-trip dependencies.
Files uploaded by public users expire after 15 minutes unless toggled to Permanent by the admin.
- File Locks: An active cleanup task runs every 5 minutes in a separate gevent worker. It creates a
.cleanup.lockfile containing the PID inside the instance folder to prevent multi-process thrashing or race conditions when scaling. - Resource Isolation: Background cleanup tasks actively clean up incomplete chunks, database rows in the
Chunktable, database files in theFiletable, and release system resources without blocking incoming user traffic.
FileBoard utilizes Nginx as an edge reverse-proxy and static server, delegating application traffic to a Gunicorn instance driving Flask via Gevent greenlets:
graph TD
Client[Client Browser] -->|Static Content & Downloads| Nginx{Nginx Reverse Proxy}
Client -->|WebSocket & App Traffic| Nginx
subgraph "Application Container"
Nginx -->|Proxy Pass http://127.0.0.1:5000| Gunicorn[Gunicorn Web Server]
Gunicorn -->|Gevent Websocket Worker| FlaskApp[Flask Application]
FlaskApp -->|SQL queries| SQLite[(Local Database Fallback)]
FlaskApp -->|Write chunks & files| LocalDisk[(Local Block Storage)]
Nginx -->|X-Accel-Redirect| LocalDisk
end
subgraph "External Cloud Infrastructure"
FlaskApp -->|PostgreSQL Protocol| PG[(Postgres Database)]
FlaskApp -->|Limiting & Caching| Redis[(Redis Server)]
end
style Nginx fill:#f9f,stroke:#333,stroke-width:2px
style Gunicorn fill:#bbf,stroke:#333,stroke-width:2px
style FlaskApp fill:#dfd,stroke:#333,stroke-width:2px
This sequence diagram illustrates the transaction between the browser, Flask application layer, and background workers during a file upload:
sequenceDiagram
autonumber
actor Client as User Browser
participant Server as Flask Routing Layer
participant DB as SQL Database
participant Disk as Local File Storage
participant Async as Gevent Assembly Worker
Client->>Server: POST /request_upload (filename)
alt Disk Space Check < 500MB
Server-->>Client: 507 Insufficient Storage
else Disk Space OK
Server->>DB: Create File Entry (UUID id, is_permanent=0)
DB-->>Server: Entry Saved
Server-->>Client: 200 OK (file_id)
end
loop Slice-by-Slice transmission
Client->>Server: POST /upload_chunk (file_id, chunk_index, slice)
Server->>Disk: Write slice to /uploads/_chunks/{file_id}/{chunk_index}
Server->>DB: Log Chunk Entry
DB-->>Server: Chunk Entry Logged
Server-->>Client: 200 OK (chunk_received)
end
Note over Client, Server: All chunks received by Server
Server->>Async: Spawn assembly task (gevent.spawn)
Server-->>Client: 200 OK (status="assembling")
activate Async
Async->>Disk: Read chunks & stitch into target file (/uploads/{file_id})
Async->>DB: Update File Entry (size_bytes)
Async->>DB: Delete Chunk Log Entries
Async->>Disk: Delete temporary /uploads/_chunks/{file_id}/ directory
Async->>Server: Emit socket.io "assembly_complete" & "new_file"
deactivate Async
Server-->>Client: [Socket.IO] assembly_complete
Note over Client: Trigger page reload to show new file
A layout of FileBoard's structural composition:
βββ .env # Active environment credentials (git-ignored)
βββ .gitignore # Git exclusion rules
βββ Dockerfile # Multi-stage production container configuration
βββ README.md # Core application documentation (Current)
βββ ads.txt # AdSense validation file
βββ app.py # Main backend codebase (models, jobs, routes, logic)
βββ docker-compose.yml # Service mesh for Nginx, Python Web, Postgres, and Redis
βββ example.env # Deployment reference environment file
βββ nginx.conf # Nginx proxy, static cache, and Accel-Redirect definition
βββ readme.local.md # Dev description details
βββ render.yaml # Automated cloud blueprints blueprint file (Render specification)
βββ requirements.txt # Python dependencies manifest
βββ runtime.txt # Python runtime target specifier
βββ start.sh # Orchestration entrypoint script (DNS diagnostics, Gunicorn & Nginx launcher)
βββ static/
β βββ style.css # Clean, minimalist custom stylesheet
βββ templates/
β βββ 404.html # Custom resource-not-found page
β βββ 500.html # Custom internal server exception page
β βββ admin.html # Secure operator control center
β βββ admin_login.html # Secure operator login page
β βββ db_error.html # Real-time database waking/maintenance error viewport
β βββ index.html # Beautiful user interface with chunk-slicing JavaScript logic
βββ tests/
βββ conftest.py # Pytest fixtures and mock environments
βββ test_app.py # Integration and unit tests
FileBoard combines trusted Python libraries with performance-oriented system software:
- Backend & WSGI: Flask 3.0.3 & Gunicorn 23.0.0
- Database & ORM: SQLAlchemy & Flask-SQLAlchemy 3.1.1
- Asynchronous Engine: Gevent 24.2.1 (monkey-patched for non-blocking Socket and IO pools)
- WebSockets: Flask-SocketIO 5.3.6 & Python-SocketIO 5.11.4
- Rate Limiter: Flask-Limiter 3.13
- Reverse Proxy & Server: Nginx
- Testing: Pytest
Create a local .env file or define these parameters on your hosting platform:
| Variable | Description | Default | Requirements |
|---|---|---|---|
SECRET_KEY |
Cryptographic signature key for session cookies. | super-secret-key |
Change in production |
ADMIN_USER |
Authorized administrator username. | admin |
Minimum 4 characters |
ADMIN_PASS |
Authorized administrator password. | admin123 |
Minimum 6 characters |
DATABASE_URL |
SQLAlchemy URL for the primary DB (PostgreSQL / SQLite). | Required | Must support psycopg2 |
REDIS_URL |
Redis instance URL. Falls back to in-memory rates if unavailable. | Optional | e.g. redis://127.0.0.1:6379 |
MIN_FREE_SPACE_GB |
Hard storage floor limit in Gigabytes before rejecting uploads. | 1 |
Integer value |
Ensure you have Docker and docker-compose installed.
Running the application using Docker Compose builds the image, provisions the local Postgres database, coordinates a Redis instance, and configures the Nginx front-facing proxy.
- Clone the Repository:
git clone https://github.com/Priyanshu-x/file-board.git cd file-board - Generate Environment Settings:
Configure your
.envvariables or use the pre-configured database defaults defined indocker-compose.yml. - Boot the Architecture:
docker-compose up --build
- Access the Application:
Open your browser and navigate to
http://localhost(Nginx acts as the entrypoint on port 80). - Access Admin Controls:
Log in at
http://localhost/admin/loginusing the default credentials:- Username:
admin - Password:
admin123
- Username:
For local development without Docker containers:
- Install System Dependencies:
Make sure you have
python 3.11and database header libraries (such aslibpq-devfor Postgres support) installed. - Create a Virtual Environment:
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
- Install Required Dependencies:
pip install -r requirements.txt
- Configure Local Environment Variables:
Create a local
.envfile in the root directory:SECRET_KEY=local-dev-secret-key-string-here ADMIN_USER=devadmin ADMIN_PASS=devadminpassword123 DATABASE_URL=sqlite:///files.db
- Start Gunicorn (Unix/macOS):
Or run natively using Flask's development server (Windows/Local Dev):
./start.sh
python app.py
- Navigate to standard address:
Visit the application locally at
http://127.0.0.1:5000.
FileBoard includes a production-ready cloud descriptor configuration designed to deploy directly to Render.
Using the built-in render.yaml template, the platform deploys the Flask application with Docker, provisions a Redis container, and attaches an active Postgres cluster.
- Commit all changes to your private fork.
- Go to the Render Dashboard and choose Blueprints.
- Connect your FileBoard repository.
- Render will configure:
- A Web Service running FileBoard inside a Docker environment.
- A PostgreSQL Database running on the free tier.
- A Redis Service handling cache allocations.
- All variables (including database URIs and cryptographic secrets) are bound automatically.
In production environments, the Nginx container provides highly optimized configuration parameters (nginx.conf):
# Buffering optimizations for massive file streams
proxy_request_buffering off;
proxy_buffering off;
# Heavy connection timeouts for background chunk assembly processes
proxy_read_timeout 600s;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
# Zero-Copy static downloads (X-Accel-Redirect)
location /internal_uploads/ {
internal;
alias /app/instance/uploads/;
}By passing down an X-Accel-Redirect header (/internal_uploads/file_id), Flask hands the file stream back to Nginx, enabling zero-copy transfers that conserve Python memory and CPU resources.
| Route | HTTP Method | Auth Required | Description | Payload / Parameter |
|---|---|---|---|---|
/ |
GET |
No | Renders the primary user interface and lists public files. | None |
/request_upload |
POST |
No | Initiates a file upload transaction and returns a file_id. |
Form Data: {filename: "..."} |
/upload_chunk |
POST |
No | Accepts an individual slice chunk for the specified upload session. | Multipart Form Data: file_id, chunk_index, total_chunks, file (binary blob) |
/download/<file_id> |
GET |
No | Downloads the corresponding file using Nginx redirection. | file_id (UUID path parameter) |
/admin |
GET |
Yes | Shows storage capacities and lists all uploads with action commands. | None |
/admin/login |
GET/POST |
No | Provides administrator session authentication. | Form Data: username, password |
/admin/logout |
GET |
Yes | Terminates the administrative session. | None |
/admin/manage |
POST |
Yes | Executes management actions (either delete or make_permanent). |
Form Data: file_id, action |
/health |
GET |
No | System health endpoint (monitored by Docker/Render). Returns OK (200) or DEGRADED (200). |
None |
/ads.txt |
GET |
No | Serves the AdSense validation file. | None |
FileBoard includes unit and integration tests using pytest. Database actions are mocked using a clean, in-memory SQLite backend.
- Make sure development dependencies are installed:
pip install pytest
- Run the tests from the root directory:
pytest
- The suite covers:
- Primary viewport rendering.
- Admin dashboard authentication policies and error handshakes.
- File deletion controls.
- Stateless guest interactions.
Distributed under the MIT License. See LICENSE for more details.
FileBoard β Engineered for extreme performance, security, and cloud resilience.