A decentralized exchange (DEX) project with a FastAPI backend and a modern React frontend with SuperTokens authentication.
.
├── backend/ # FastAPI backend (Python)
│ ├── main.py
│ ├── controllers/
│ ├── models/
│ ├── routes/
│ └── ...
├── frontend/ # React frontend (JS/TS)
│ ├── src/
│ ├── public/
│ ├── package.json
│ └── ...
└── README.md # Project overview (this file)
- Stack: FastAPI, Uvicorn, Pydantic, Python 3.7+
- Key files/dirs:
main.py: FastAPI app entrypointcontrollers/: Business logic (e.g.,controller.py)models/: Data models (user.py,requests.py)repository/,routes/,db.py,config.py
- Features:
- Create/view/manage orders (buy/sell)
- Order matching & trade execution
- In-memory DB for demo purposes
- API endpoints:
/orders/,/match/, etc.
- Clone the repository:
git clone https://github.com/your-username/decentralized-exchange-fastAPI.git cd decentralized-exchange-fastAPI - Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run the FastAPI app:
uvicorn main:app --reload
- Visit the API docs at: http://127.0.0.1:8000/docs
- Stack: React 19, Tailwind CSS, SuperTokens, Vite, React Router, Axios
- Key files/dirs:
src/App.jsx: Main app, routing, SuperTokens integrationsrc/pages/:DashboardPage.jsx,AccountPage.jsxsrc/components/: Navbar, AccountInfo, TradeWidget, etc.src/services/api.js: API callsindex.css, Tailwind config
- Features:
- Modern, dark-mode UI
- Dashboard, account management, trading interface
- SuperTokens social login & session management
- Responsive & accessible design
Before running the frontend, start the SuperTokens core service:
docker run -p 3567:3567 -d registry.supertokens.io/supertokens/supertokens-postgresql:latestThis is required for authentication to work properly.
- Go to the frontend directory:
cd frontend - Install dependencies:
npm install
- Start the frontend dev server:
The app will typically be available at http://localhost:5173.
npm run dev
- Update backend logic in
controllers/,models/,routes/ - Update frontend UI in
src/pages/,src/components/ - SuperTokens config in
App.jsxand related files
- Follow code style and patterns in each directory
- Use Tailwind CSS for frontend styling
- Ensure responsive and accessible design
- Add proper error handling and test on multiple devices
This project is part of a DeFi exchange application.
-
Clone the repository:
git clone https://github.com/your-username/decentralized-exchange-fastAPI.git cd decentralized-exchange-fastAPI -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt ``` (Note: You might need to create a `requirements.txt` file first if it doesn't exist. You can generate one using `pip freeze > requirements.txt` after installing dependencies)
The frontend is built with React and uses SuperTokens for authentication (social login, session management, etc.).
Before running the frontend locally, you must start the SuperTokens core service using Docker:
# Start the SuperTokens PostgreSQL core service
# This runs the service on port 3567
docker run -p 3567:3567 -d registry.supertokens.io/supertokens/supertokens-postgresql:latestThis is required for authentication to work properly.
- Go to the frontend directory:
cd frontend - Install the dependencies:
npm install
- Start the frontend development server:
The app will typically be available at
npm run dev
http://localhost:5173(the default Vite port).
- React: For building the user interface
- SuperTokens: For authentication (social login, session management)
- react-router-dom: For routing
- Modern dark-mode UI, responsive design
- Account management & trading interface
- Secure authentication and protected routes
- Update components in
frontend/src/pages/to modify dashboard or account features. - Authentication UI and logic can be customized in
frontend/src/App.jsxand related SuperTokens configuration files.
-
Clone the repository:
git clone https://github.com/your-username/decentralized-exchange-fastAPI.git cd decentralized-exchange-fastAPI -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt ``` (Note: You might need to create a `requirements.txt` file first if it doesn't exist. You can generate one using `pip freeze > requirements.txt` after installing dependencies)
-
Run the FastAPI application:
uvicorn main:app --reload
-
Access the API documentation:
Once the server is running, you can access the interactive API documentation (Swagger UI) at
http://127.0.0.1:8000/docs.
- POST /buy_eth: Buy ETH with specified amount and currency (requires authentication)
- POST /sell_eth: Sell ETH for specified amount and currency (requires authentication)
- GET /get_assets: Retrieve user's asset balances (requires authentication)
- GET /get_eth_amount?amount=: Get ETH equivalent for a given amount (requires authentication)
- POST /account/deposit_usdt: Deposit USDT to user account (requires authentication)
main.py: Main application entry pointroutes/: Defines API endpointsmodels/: Pydantic models for request/response datarepository/: Handles data storage and retrieval (in-memory in this demo)controllers/: Contains business logic for order managementdb.py: Database setup (in-memory dictionary in this demo)config.py: Configuration settings