Skip to content

Latest commit

Β 

History

History
291 lines (233 loc) Β· 11.4 KB

File metadata and controls

291 lines (233 loc) Β· 11.4 KB

Liquidity Platform - Architecture Overview

πŸ“ Project Structure

Liquidity/
β”‚
β”œβ”€β”€ 🎨 frontend/                    # Next.js Frontend Application
β”‚   β”œβ”€β”€ app/                        # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ page.tsx               # Main landing page
β”‚   β”‚   β”œβ”€β”€ layout.tsx             # Root layout
β”‚   β”‚   └── globals.css            # Global styles
β”‚   β”œβ”€β”€ lib/                       # Utilities & API Client
β”‚   β”‚   └── api.ts                 # TypeScript API client
β”‚   β”œβ”€β”€ public/                    # Static assets
β”‚   β”œβ”€β”€ .env.local                 # Environment variables
β”‚   β”œβ”€β”€ package.json               # Node.js dependencies
β”‚   └── tsconfig.json              # TypeScript config
β”‚
β”œβ”€β”€ πŸ”§ backend/                     # FastAPI Backend Application
β”‚   β”œβ”€β”€ app/                       # Application code
β”‚   β”‚   β”œβ”€β”€ main.py                # FastAPI app & routes
β”‚   β”‚   └── __init__.py            # Package initialization
β”‚   β”œβ”€β”€ venv/                      # Python virtual environment (created by setup)
β”‚   β”œβ”€β”€ requirements.txt           # Python dependencies
β”‚   β”œβ”€β”€ .env.example               # Environment template
β”‚   β”œβ”€β”€ setup.sh                   # Backend setup script
β”‚   └── start-backend.sh           # Backend start script
β”‚
β”œβ”€β”€ πŸ“ src/                         # Your existing code
β”‚   └── solver/                    # Solver module
β”‚       └── solver.py              # Liquidity solver logic
β”‚
β”œβ”€β”€ πŸ“„ Documentation
β”‚   β”œβ”€β”€ README.md                  # Comprehensive documentation
β”‚   β”œβ”€β”€ QUICKSTART.md              # Quick start guide
β”‚   └── ARCHITECTURE.md            # This file
β”‚
β”œβ”€β”€ πŸš€ Utility Scripts
β”‚   β”œβ”€β”€ start-all.sh               # Start both servers
β”‚   └── check-system.sh            # System prerequisites check
β”‚
└── βš™οΈ Configuration
    └── .gitignore                 # Git ignore rules

πŸ”„ Data Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         User Browser                         β”‚
β”‚                     http://localhost:3000                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β”‚ HTTP Requests
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Next.js Frontend                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  React Components (page.tsx)                           β”‚ β”‚
β”‚  β”‚  - UI rendering                                        β”‚ β”‚
β”‚  β”‚  - User interactions                                   β”‚ β”‚
β”‚  β”‚  - State management                                    β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                   β”‚                                          β”‚
β”‚                   β”‚ Uses                                     β”‚
β”‚                   β–Ό                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  API Client (lib/api.ts)                               β”‚ β”‚
β”‚  β”‚  - Type-safe API calls                                 β”‚ β”‚
β”‚  β”‚  - Error handling                                      β”‚ β”‚
β”‚  β”‚  - Request/Response formatting                         β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
                    β”‚ fetch() / HTTP
                    β”‚ http://localhost:8000/api/*
                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   FastAPI Backend                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  CORS Middleware                                       β”‚ β”‚
β”‚  β”‚  - Allow Next.js origin                               β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                   β–Ό                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  API Routes (main.py)                                  β”‚ β”‚
β”‚  β”‚  - /health          Health check                       β”‚ β”‚
β”‚  β”‚  - /api/hello       Sample endpoint                    β”‚ β”‚
β”‚  β”‚  - /api/items       Get items list                     β”‚ β”‚
β”‚  β”‚  - /api/process     Process item                       β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                   β”‚                                          β”‚
β”‚                   β”‚ Can use                                  β”‚
β”‚                   β–Ό                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Your Business Logic                                   β”‚ β”‚
β”‚  β”‚  - src/solver modules                                  β”‚ β”‚
β”‚  β”‚  - Database operations                                 β”‚ β”‚
β”‚  β”‚  - External services                                   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🌐 Network Communication

Development URLs

Service URL Purpose
Frontend http://localhost:3000 User-facing web interface
Backend API http://localhost:8000 REST API endpoints
API Docs (Swagger) http://localhost:8000/docs Interactive API documentation
API Docs (ReDoc) http://localhost:8000/redoc Alternative API documentation

CORS Configuration

The backend is configured to accept requests from the frontend:

  • Allowed Origins: http://localhost:3000
  • Allowed Methods: All (GET, POST, PUT, DELETE, etc.)
  • Allowed Headers: All
  • Credentials: Enabled

πŸ” Environment Variables

Frontend (.env.local)

NEXT_PUBLIC_API_URL=http://localhost:8000

Backend (.env)

API_HOST=0.0.0.0
API_PORT=8000
DEBUG=True
CORS_ORIGINS=http://localhost:3000

πŸ› οΈ Technology Stack Details

Frontend Stack

Next.js 15 (React 19)
β”œβ”€β”€ TypeScript           # Type safety
β”œβ”€β”€ Tailwind CSS         # Utility-first styling
β”œβ”€β”€ App Router          # File-based routing
└── Server Components   # Performance optimization

Backend Stack

FastAPI
β”œβ”€β”€ Uvicorn             # ASGI server
β”œβ”€β”€ Pydantic            # Data validation
β”œβ”€β”€ Python 3.8+         # Runtime
└── Automatic OpenAPI   # API documentation

πŸ“¦ Dependencies

Frontend (package.json)

  • next: React framework with SSR/SSG
  • react & react-dom: UI library
  • typescript: Type checking
  • tailwindcss: CSS framework
  • eslint: Code linting

Backend (requirements.txt)

  • fastapi: Web framework
  • uvicorn: ASGI server
  • pydantic: Data validation
  • python-dotenv: Environment variables

🚦 Development Workflow

1. Initial Setup

# Check prerequisites
./check-system.sh

# Setup backend
cd backend && ./setup.sh && cd ..

# Setup frontend (if needed)
cd frontend && npm install && cd ..

2. Development

# Option 1: Start both together
./start-all.sh

# Option 2: Start separately
# Terminal 1
cd backend && ./start-backend.sh

# Terminal 2
cd frontend && npm run dev

3. Making Changes

Adding a new API endpoint:

  1. Define route in backend/app/main.py
  2. Add method to frontend/lib/api.ts
  3. Use in React components

Adding a new page:

  1. Create frontend/app/your-page/page.tsx
  2. Access at http://localhost:3000/your-page

πŸ”Œ Integrating Your Solver

To integrate your existing src/solver code:

# backend/app/main.py
import sys
sys.path.append('../src')

from solver.solver import YourSolverClass

@app.post("/api/solve")
async def solve_problem(data: ProblemData):
    solver = YourSolverClass()
    result = solver.solve(data)
    return {"solution": result}

πŸ“ˆ Scaling Considerations

Production Checklist

  • Configure production environment variables
  • Set up database (PostgreSQL, MongoDB, etc.)
  • Add authentication/authorization
  • Implement rate limiting
  • Add logging and monitoring
  • Configure HTTPS/SSL
  • Set up CI/CD pipeline
  • Configure CORS for production domains
  • Optimize build for production
  • Set up error tracking (Sentry, etc.)

Deployment Options

Frontend (Next.js)

  • Vercel (recommended)
  • Netlify
  • AWS Amplify
  • Self-hosted with PM2

Backend (FastAPI)

  • Railway
  • Render
  • Heroku
  • AWS EC2/ECS
  • DigitalOcean
  • Self-hosted with Nginx + Gunicorn

🀝 Contributing

When adding features:

  1. Follow the existing code structure
  2. Add types to TypeScript code
  3. Use Pydantic models for API schemas
  4. Update documentation
  5. Test both frontend and backend

πŸ“š Additional Resources