A full-stack application where users communicate through numbers and mathematical operations, creating tree-like calculation chains similar to social media comment threads.
This project follows Hexagonal Architecture (Ports & Adapters) pattern:
- Domain Layer: Core business logic, entities, and use cases
- Ports: Interfaces defining contracts (primary for input, secondary for output)
- Adapters: Implementations (HTTP controllers, PostgreSQL repositories)
- Node.js + TypeScript
- Express.js
- PostgreSQL with Prisma ORM
- JWT for authentication
- bcryptjs for password hashing
- React + TypeScript
- Vite
- Axios for API calls
calculation-tree-app/
├── backend/
│ ├── src/
│ │ ├── domain/
│ │ │ ├── entities/ # Domain models
│ │ │ └── use-cases/ # Business logic
│ │ ├── ports/
│ │ │ ├── primary/ # Input interfaces (use cases)
│ │ │ └── secondary/ # Output interfaces (repositories)
│ │ ├── adapters/
│ │ │ ├── primary/ # HTTP controllers, routes
│ │ │ └── secondary/ # Database repositories
│ │ └── index.ts
│ ├── prisma/
│ │ └── schema.prisma
│ └── package.json
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── contexts/ # React contexts
│ │ ├── services/ # API services
│ │ └── App.tsx
│ └── package.json
└── docker-compose.yml
- Node.js (v18 or higher)
- Docker and Docker Compose (for local database)
- PostgreSQL (if not using Docker)
-
Clone the repository
git clone <repository-url> cd calculation-tree-app
-
Start PostgreSQL database
docker-compose up -d
-
Backend Setup
cd backend npm install # Create .env file cp .env.example .env # Edit .env and set: # DATABASE_URL="postgresql://calculation_user:calculation_password@localhost:5432/calculation_tree?schema=public" # JWT_SECRET="your-secret-key" # PORT=3001 # Generate Prisma client npx prisma generate # Run migrations npx prisma migrate dev # Start backend server npm run dev
-
Frontend Setup
cd frontend npm install # Create .env file (optional, defaults to http://localhost:3001/api) # VITE_API_URL=http://localhost:3001/api # Start frontend dev server npm run dev
-
Access the application
- Frontend: http://localhost:5173
- Backend API: http://localhost:3001
See DEPLOYMENT.md for the complete deployment guide.
Backend (Railway):
- Push code to GitHub
- Create new project on Railway
- Add PostgreSQL database
- Set environment variables:
DATABASE_URL,JWT_SECRET - Deploy backend service
- Run migrations:
npx prisma migrate deploy
Frontend (Vercel):
- Import project from GitHub (set root directory to
frontend) - Set environment variable:
VITE_API_URL=https://your-backend.railway.app/api - Deploy
See DEPLOYMENT.md for detailed instructions and troubleshooting.
POST /api/auth/register- Register a new userPOST /api/auth/login- Login user
GET /api/calculations/starting-numbers- Get all starting numbers (public)GET /api/calculations/operations/:parentType/:parentId- Get operations for a parent (public)POST /api/calculations/starting-numbers- Create starting number (authenticated)POST /api/calculations/operations- Create operation (authenticated)
- ✅ View calculation tree as unregistered user
- ✅ User registration and authentication
- ✅ Create starting numbers (authenticated users)
- ✅ Add operations to starting numbers or other operations
- ✅ Recursive calculation tree display
- ✅ Real-time result calculation
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production servernpx prisma studio- Open Prisma Studio to view database
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production build
- users: User accounts with username and hashed password
- starting_numbers: Initial numbers that start calculation chains
- operations: Mathematical operations (+,-,*,/) that build on starting numbers or other operations
ISC