Installation
This guide covers the complete installation process for Torn, including backend, frontend, and database setup for both development and production environments.System Requirements
Minimum Requirements
- Python: 3.8 or higher
- Node.js: 16.x or higher
- PostgreSQL: 12.x or higher
- RAM: 2GB minimum (4GB recommended)
- Storage: 1GB for application + database storage
Operating Systems
Torn has been tested on:- Ubuntu 20.04+ (recommended for production)
- macOS 11+
- Windows 10+ (with WSL2 for best experience)
Backend Installation
The backend is built with FastAPI and uses PostgreSQL for data persistence.1. Clone the Repository
2. Set Up Python Virtual Environment
Create and activate a virtual environment:(.venv) prefix in your terminal prompt.
3. Install Python Dependencies
Install all required packages fromrequirements.txt:
Core Dependencies
The backend uses these key packages:| Package | Version | Purpose |
|---|---|---|
fastapi | ≥0.115.0 | Web framework for building APIs |
uvicorn[standard] | ≥0.32.0 | ASGI server with performance extras |
sqlalchemy | ≥2.0.0 | ORM for database operations |
pydantic | ≥2.0.0 | Data validation and serialization |
psycopg2-binary | ≥2.9.0 | PostgreSQL database adapter |
python-dotenv | ≥1.0.0 | Environment variable management |
jinja2 | ≥3.1.0 | Template engine for HTML/XML generation |
4. Configure Environment Variables
Create a.env file in the project root with your configuration:
.env
A template file Then edit the values to match your environment.
.env.example is provided in the repository. Copy it to get started:Production Environment Variables
For production deployments, consider these additional settings:.env
5. Set Up PostgreSQL Database
Local Development
Connect to PostgreSQL and create the database:Verify Connection
Test that you can connect with the credentials:Production Setup
For production, use a managed PostgreSQL service (AWS RDS, Google Cloud SQL, etc.) or configure PostgreSQL with:- SSL/TLS encryption
- Connection pooling (PgBouncer)
- Regular automated backups
- Monitoring and alerting
6. Initialize the Database
When you start the FastAPI application for the first time, it automatically creates all necessary tables:7. Load Reference Data (Optional)
For Chilean tax compliance, load the ACTECO catalog (economic activity codes):- Reads
data/actecos_sii.jsonwith official SII codes - Checks for existing codes to avoid duplicates
- Inserts new codes into the
public.actecostable - Reports the number of codes added
Frontend Installation
The frontend is a standalone Next.js application located in thefrontend/ directory.
1. Navigate to Frontend Directory
2. Install Node.js Dependencies
Choose your preferred package manager:The frontend dependencies are independent from the backend. All packages install to
frontend/node_modules.Key Dependencies
The frontend uses modern React tools and libraries:| Package | Version | Purpose |
|---|---|---|
next | 16.1.6 | React framework with SSR/SSG |
react | 19.2.3 | UI library |
axios | 1.13.5 | HTTP client for API calls |
@radix-ui/* | Various | Accessible UI components |
tailwindcss | 4.x | Utility-first CSS |
zustand | 5.0.11 | State management |
react-hook-form | 7.71.1 | Form handling |
zod | 4.3.6 | Schema validation |
recharts | 3.7.0 | Charts and analytics |
3. Configure Frontend Environment
The frontend connects to the backend API athttp://localhost:8000 by default. For custom configurations, create frontend/.env.local:
frontend/.env.local
4. Start the Development Server
http://localhost:3000.
5. Build for Production
To create an optimized production build:.next/ and starts the production server.
Running Both Services
Development Mode
For local development, use the convenience script that manages both services:run.py):
- Clears ports 8000 and 3000 using
fuser -k(Linux) - Starts backend with
uvicorn app.main:app --reload --port 8000 - Starts frontend with
npm run devin thefrontend/directory - Streams logs from both services with color-coded prefixes:
- 🔵
[FastAPI]- Backend logs - 🟡
[Next.JS]- Frontend logs - 🟢
[SISTEMA]- System messages
- 🔵
- Handles shutdown gracefully with Ctrl+C
Manual Mode
Alternatively, run services in separate terminals: Terminal 1 (Backend):Production Deployment
Backend Production Server
For production, use Gunicorn with Uvicorn workers:/etc/systemd/system/torn-backend.service
Frontend Production Server
Build and serve the Next.js application:- Vercel (optimized for Next.js)
- Netlify
- AWS Amplify
- Docker with custom Nginx configuration
Docker Deployment (Optional)
ExampleDockerfile for the backend:
Dockerfile
Architecture Overview
Torn follows a modular monorepo structure:Verification
After installation, verify everything is working:1. Check Backend Health
2. Check API Documentation
FastAPI provides interactive API docs:- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
3. Check Frontend
Open http://localhost:3000 in your browser. You should see the Torn login/dashboard.4. Check Database Connection
Verify tables were created:users, sales, products, cash_sessions, etc.
Troubleshooting
Backend Issues
ModuleNotFoundError: No module named 'app'
ModuleNotFoundError: No module named 'app'
Ensure you’re running the command from the project root (not from
app/ directory) and your virtual environment is activated:Database connection refused
Database connection refused
Check that PostgreSQL is running and accepting connections:Verify your
.env credentials match your PostgreSQL setup.Port 8000 already in use
Port 8000 already in use
Find and kill the process using port 8000:Or use the
run.py script which handles this automatically.Frontend Issues
npm install fails with EACCES
npm install fails with EACCES
Fix npm permissions or use a version manager like nvm:
Module not found: Can't resolve 'axios'
Module not found: Can't resolve 'axios'
Reinstall dependencies:
API calls return CORS errors
API calls return CORS errors
The backend includes CORS middleware for
localhost:3000. If using a different port, update app/main.py:Next Steps
Now that Torn is installed:Quickstart Guide
Create your first tenant and process a sale
Multi-Tenancy
Understanding tenant isolation
API Reference
Explore all available endpoints
Core Concepts
Learn the architecture