How luongtantai200803/shopacc works
Project type and purpose
• ShopAcc is a backend-only, monolithic REST API service built in Python/Flask.
• Its purpose is to expose CRUD endpoints for game accounts, handle user auth (JWT), manage orders (virtual payments), and emit real-time events via WebSockets/Sockets.
File structure
• Top-level configuration and Docker artifacts:
• Dockerfile, docker-compose.yml, nginx.conf, gunicorn.conf.py, .github/workflows/deploy.yml
• main.py (entry point), requirements.txt, pytest.ini, test_*.py, tests/
• app/ folder defines the Flask application:
• app/config.py – environment & Flask settings
• app/extensions.py – initializes extensions (SQLAlchemy, JWT, SocketIO, etc.)
• app/error_handler.py, app/exceptions.py – centralized error handling
• app/models/ – SQLAlchemy models (User, Account)
• app/routes/ – Blueprints for auth, account, order endpoints
• app/sockets.py – real-time notifications via WebSockets
• app/intents.json – domain data for game-account categories or intents
• instance/ holds the local SQLite DB file (instance/mydb.sqlite3)
• migrations/ is the Alembic setup for versioned schema changes
README
• Confirms core features (auth, CRUD, buy/sell, roles)
• Technology stack: Flask, REST, SQLAlchemy + MySQL/PostgreSQL, JWT, Gunicorn, Nginx, Docker, CD on Railway/AWS
• Local run instructions & environment setup
Main components
a. External Clients
• Web or Mobile UIs (or Postman/other API consumers)
b. Reverse-Proxy Layer
• Nginx (TLS termination, load balancing, static asset serving if any)
c. WSGI Server
• Gunicorn (multiple worker processes)
d. Flask Application
• Config & Extensions
• Routing layer (Blueprints: Auth, Account, Order)
• Business logic & error handlers
• Sockets namespace for real-time updates (via Flask-SocketIO)
e. Data Layer
• SQLAlchemy ORM
• Relational Database (MySQL/PostgreSQL in production; SQLite for local dev)
• Alembic migrations
f. DevOps & CI/CD
• Docker containers (App, DB) orchestrated via docker-compose
• GitHub Actions → deploy.yml for automated tests & deploy
• Deployment target (Railway / AWS)
Relationships and data flows
• Clients ↔ HTTPS ↔ Nginx
• Nginx → Gunicorn workers → Flask app
• Flask → SQLAlchemy → RDBMS
• Flask-SocketIO communicates bi-directionally with clients over WebSockets
• CI pipeline triggers container builds, tests, and pushes to staging/production
• Alembic handles database schema migrations before startup
Architectural patterns and design principles
• Layered architecture: Presentation (routes + sockets), Service (business logic), Data (models + migrations)
• Separation of concerns: Blueprints for modular routing, extensions for decoupled middleware
• Token-based security (JWT) governing admin vs user roles
• Infrastructure as code: Dockerfile, docker-compose, Nginx config, CI workflows
• End-to-end flow, from client requests down to DB IO and back
• Distinguish sync HTTP paths from async WebSocket channels
• Where environment config lives (app/config.py + .env) and migrations kick in
• Call out the CI/CD pipeline and container orchestration as part of the “deployment” layer