nima-sayadi/crypto-fund-portal
Acerca de
Investment Website based on customer needs
Desarrollo web y de aplicacionesWhat you can do
- Passwordless sign-up and login with a one-time 6-digit code sent by email
- Buy units by sending USDT to the fund's wallet (TRC20, ERC20 or BEP20) and attaching the transaction link or a receipt, optionally only at today's price or lower
- Redeem units to a wallet the admin has approved, optionally only at today's price or higher
- Per-fund statement: purchases, sales, units held, amounts received and redemption fees paid
Crecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- 0
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
Originalcrypto-fund-portal
A crypto investment fund platform written in plain PHP, without any framework. I wrote it in 2022 as one of my earliest projects, and it ran in production at the time. Today (1. Dec 2026), I upgraded many parts of it and restructured it for production use (see What changed since 2022).
The source code is published with the permission of its owner, the employer it was originally built for.
Investors buy and redeem units in USDT-based crypto funds (by default three: low, medium and high risk). Admins record each fund's daily unit price (NAV), approve every transaction, and track each investor's holdings.
The interface is in Persian (right-to-left) and shows dates in the Jalali (Solar Hijri) calendar.
Features
Investor side
- Passwordless sign-up and login with a one-time 6-digit code sent by email
- Buy units by sending USDT to the fund's wallet (TRC20, ERC20 or BEP20) and attaching the transaction link or a receipt, optionally only at today's price or lower
- Redeem units to a wallet the admin has approved, optionally only at today's price or higher
- Per-fund statement: purchases, sales, units held, amounts received and redemption fees paid
- Fund performance pages with an interactive NAV chart and returns over 1 day, 1 week, and 1, 3, 6 and 12 months (also available publicly at
/funds/{id}) - Investor profile questionnaire, wallet management, a support chat with attachments, and notifications
Admin side
- Daily NAV entry per fund, with a Jalali date picker and corrections for past dates
- Approve or reject buy and sell orders. A redemption uses up the investor's oldest units first (FIFO), and each unit pays the redemption fee in force when it was bought.
- Fund settings: name, description, redemption fee and deposit wallet
- Investor list and profiles, wallet approval, support conversations
- Admin accounts, managed by super admins
Tech stack
- PHP 8.1+ (PDO, bcmath, fileinfo, mbstring), with Composer for autoloading
- PHPMailer for SMTP email
- MySQL 8.0+ or MariaDB 10.6+
- Bootstrap 5 RTL admin theme, jQuery, DataTables, Select2 and iCheck
- Highcharts (Highstock), persian-date and persian-datepicker
- PHPUnit for tests
Project structure
├── bin/create-admin.php # CLI: create or promote a super admin
├── config/
│ ├── app.php # all settings (read from .env)
│ └── routes.php # every URL, its controller and who may access it
├── database/
│ ├── schema.sql # tables
│ └── seed.sql # the three funds
├── public/ # web root: the only directory the web server exposes
│ ├── index.php # front controller
│ └── assets/ # css, js, fonts, images, vendor libraries
├── src/
│ ├── Controllers/ # HTTP layer (User/, Admin/, auth, files, notifications)
│ ├── Services/ # business logic: orders and FIFO, funds and NAV, login, uploads…
│ ├── Http/ # router and exceptions
│ ├── Security/ # authentication and CSRF
│ ├── Support/ # config, .env loader, session, money, Jalali dates, labels
│ ├── Database.php # PDO wrapper
│ └── View.php # template renderer
├── storage/ # uploads, logs and sessions (not web-accessible)
├── tests/ # PHPUnit tests
└── views/ # PHP templates (layouts, partials, user/, admin/, shared/)
Main terms used in the code:
| Term | Meaning |
|---|---|
| fund | An investment fund. Its price per unit is the NAV (net asset value). |
| order | A buy (issue) or sell (redeem) request for units of a fund |
| lot | An approved buy order. remaining_units counts how many of its units are still held. |
| redemption fee | A per-unit fee charged when units are sold back. Each lot keeps the fee in force when it was bought. |
| statement | An investor's history in one fund (called "cardex" in the UI) |
Getting started
Requirements: PHP 8.1+ with pdo_mysql, bcmath, fileinfo and mbstring; Composer; and MySQL 8.0+ or MariaDB 10.6+.
composer install
cp .env.example .env
php -r "echo bin2hex(random_bytes(32)), PHP_EOL;" # paste the output into APP_KEY in .env
Edit .env with your database and mail settings. For local development, set APP_DEBUG=true, SESSION_SECURE_COOKIE=false and MAIL_DRIVER=log. The log driver writes login codes to storage/logs/mail.log instead of sending them.
mysql -u <user> -p <database> < database/schema.sql
mysql -u <user> -p <database> < database/seed.sql
php bin/create-admin.php [email protected] "Your Name"
composer serve # http://localhost:8000
Log in with the super admin's email, then go to Settings → Funds to set each fund's deposit wallet and redemption fee, and to NAV to record the first prices. Investors can buy only after a fund has both a NAV and a deposit wallet.
Deploying to production
- Point the web server's document root at
public/, never at the repository root. As a safety net, the root.htaccessrefuses every request if the root is served by mistake. - Run
composer install --no-dev --optimize-autoloader. - In
.env, setAPP_ENV=production,APP_DEBUG=false, a randomAPP_KEY, real SMTP settings (MAIL_DRIVER=smtp) andSESSION_SECURE_COOKIE=true. Serve the site over HTTPS only. - The web server user needs write access to
storage/(uploads, logs, sessions). - If the app runs behind a reverse proxy or load balancer, make sure
REMOTE_ADDRholds the real client IP (for example with Apachemod_remoteipor nginxreal_ip). Login rate limiting is per IP.
Apache: enable mod_rewrite and allow .htaccess overrides for public/; public/.htaccess routes every request to index.php.
nginx (with PHP-FPM):
server {
listen 443 ssl;
server_name example.com;
root /var/www/crypto-fund-portal/public;
index index.php;
location / {
try_files $uri /index.php$is_args$args;
}
location = /index.php {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\. { deny all; }
location ~ \.php$ { return 404; }
}
Security
- Every query uses a PDO prepared statement.
- All output is HTML-escaped in templates.
- Every state-changing request carries a CSRF token.
- Pages send a strict Content-Security-Policy (no inline scripts) and other security headers.
- Login codes are stored only as keyed hashes (HMAC with
APP_KEY). They expire after 10 minutes, are single-use, and lock after 5 wrong attempts. Requests are rate-limited per email and per IP. - Sessions use HttpOnly, SameSite and Secure cookies, are regenerated on login, and expire after an idle period and after an absolute lifetime. The user's role is re-read from the database on every request, so removing an admin takes effect immediately.
- Uploads are checked by their content type (not the file name) and size, given random names, and stored outside the web root. They are served only to their owner and to admins.
- Every money movement (approving an order and redeeming lots) runs in a database transaction with row locks. Sell orders cannot spend units already held by another pending sell order.
- Amounts use exact decimal arithmetic (bcmath and
DECIMALcolumns) instead of floating point.
Tests
composer test
The unit tests cover decimal money arithmetic, the Jalali calendar conversion and the .env loader.
What changed since 2022
The features are the same as in the 2022 version. The changes are in the structure, the security and the back-end stack:
| 2022 version | Now | |
|---|---|---|
| Structure | One PHP file per page, with a copy of each fund page per fund, all served from the repository root | A single entry point in public/, with routes, controllers, services and templates. One page per feature serves every fund. |
| Dependencies | Libraries copied into the repository; no Composer | Composer with PSR-4 autoloading; unused front-end plugins removed |
| Database | MySQLi, with credentials hard-coded in the code | PDO with prepared statements and transactions; settings in .env |
| Amounts | Stored as text and calculated with floating point | DECIMAL columns and exact bcmath arithmetic |
| Login email | The code was saved in the database but never sent | Sent over SMTP with PHPMailer; codes are hashed, expire and are rate-limited |
| Jalali dates | Required PHP's intl extension |
A built-in converter, so intl is not needed |
| Front end | Inline scripts in every page | Scripts in separate files, so a strict Content-Security-Policy can block injected scripts |
| Tests | None | PHPUnit |
The front-end libraries are the same ones as in 2022 (the Bootstrap 5 RTL theme, jQuery 3.1, DataTables 1.10, Highstock and persian-date).
The rewrite also fixed a number of security issues and bugs.
Ideas for further development
Contributions and forks are welcome. Some directions that would make the project more useful:
- Translations: the Persian text is written directly in the templates (
views/) and insrc/Support/Labels.php. Moving it into language files would allow English and other languages, with a left-to-right layout and Gregorian dates alongside Jalali. - On-chain deposit checks: look up the transaction hash on the blockchain (for example with TronGrid, Etherscan or BscScan) to confirm the amount and the receiving wallet before an admin approves a buy.
- Automatic NAV: calculate each fund's daily NAV from its holdings and exchange prices instead of entering it by hand.
- Email notifications: email investors when an order is approved or rejected and when support replies. Email is currently used only for login codes.
- Admin security: two-factor authentication (TOTP) for admin accounts and an audit log of admin actions.
- Front-end upgrades: update jQuery and DataTables, and replace Highcharts with an open-source chart library to avoid its commercial license.
- Developer tooling: database migrations instead of a single
schema.sql, integration tests for the services and controllers, a Docker setup for local development, and continuous integration.
Licenses
The code is released under the MIT License. The bundled third-party libraries keep their own licenses. Note that Highcharts is free only for non-commercial use, so a commercial deployment needs a Highcharts license or a replacement chart library. The IRANSans font is also a commercial font.
Explorar proyectos relacionados
Cargando…