Capivara API backend python
  • Python 92.8%
  • Shell 3.9%
  • Hurl 2.7%
  • HTML 0.4%
Find a file
Jonatas Oliveira 3fb21a3262
All checks were successful
ci/woodpecker/push/pipeline/1 Pipeline was successful
ci/woodpecker/push/pipeline/2 Pipeline was successful
ci/woodpecker/push/pipeline/3 Pipeline was successful
ci/woodpecker/cron/pipeline/1 Pipeline was successful
ci/woodpecker/cron/pipeline/2 Pipeline was successful
ci/woodpecker/cron/pipeline/3 Pipeline was successful
fix(docker): venv vai na imagem em vez de ser recriado a cada boot
O `uv sync` do builder instala em /app/.venv, mas a imagem final só copiava
o site-packages do sistema — que o uv não popula. Resultado: todo `uv run`
do Procfile e do predeploy recriava o ambiente e instalava 206 pacotes,
449 MB, a cada container que subia.

Isso derrubou o deploy. O predeploy do Dokku roda a task e faz `docker
commit` do container para assar o resultado na imagem; com 449 MB de
diferença, o commit precisava exportar uma camada de 703 MB, e o content
store do containerd falhou no meio:

    failed to commit: rename .../ingest/84cbad73.../data
    .../blobs/sha256/27582c77...: no such file or directory

Medido antes e depois, rodando o mesmo comando do predeploy:

    antes:  62.866 arquivos no diff, camada de 703 MB
    depois:  1.146 arquivos no diff, camada de  16 MB

O que resta são __pycache__ e a reinstalação do próprio fast-ecommerce.

A imagem sobe de 180 MB para 523 MB, mas o disco já pagava esses 449 MB —
antes na camada gravável de cada container (web x2, task, order_task), agora
uma vez só, compartilhada.

Vai junto o .dockerignore, que não existia: o `COPY . .` levava o .venv
local, o histórico do git e artefatos de teste para dentro do contexto.
2026-08-26 15:27:14 +02:00
.agent/rules test: improve tests in checkout and refactor migrations 2026-04-14 13:30:42 +02:00
.woodpecker ci(back): remove o step de deploy 2026-08-20 20:01:13 +02:00
app feat(main-page): banner pode apontar para produto e cupom 2026-08-26 14:40:18 +02:00
changelog.d feat: add payment details and crud for comissions 2026-03-02 08:44:33 +01:00
contrib feat: integrate with correiosbr api (#1080) 2023-09-13 12:04:00 +02:00
email-templates test: improve tests in checkout and refactor migrations 2026-04-14 13:30:42 +02:00
hurl_tests fix(config): correct hurl port 8000→8001, ruff formatter path in opencode.json 2026-04-28 21:10:22 +02:00
legacy tests: fix woodpecker steps and fix broken tests 2025-12-23 07:34:57 +01:00
migrations feat(main-page): banner pode apontar para produto e cupom 2026-08-26 14:40:18 +02:00
scripts feat: add goal and list. mail smtp configure. cielo client configured 2026-01-07 17:01:41 +01:00
static chore: move app to root 2023-06-20 19:12:19 +02:00
tests feat(main-page): banner pode apontar para produto e cupom 2026-08-26 14:40:18 +02:00
.dockerignore fix(docker): venv vai na imagem em vez de ser recriado a cada boot 2026-08-26 15:27:14 +02:00
.gitignore chore(gitignore): ignora .env e coverage.json 2026-08-20 19:16:03 +02:00
.pre-commit-config.yaml feat: add goal and list. mail smtp configure. cielo client configured 2026-01-07 17:01:41 +01:00
.pyup.yml fix pyup 2020-11-09 16:22:14 -03:00
.safety-project.ini test: improve tests in checkout and refactor migrations 2026-04-14 13:30:42 +02:00
__init__.py chore: move app to root 2023-06-20 19:12:19 +02:00
AGENTS.md docs(agents): aponta a regra de TDD para features novas 2026-08-25 18:02:58 +02:00
alembic.ini feat: refactor settings table (#1163) 2024-09-26 14:20:34 +02:00
app.json fix(dokku): use python to check DATABASE_URL (hujson-safe) 2026-06-08 19:04:17 +02:00
CHANGELOG.md build: package version 0.4.0 2025-11-18 15:33:44 +01:00
config.py feat: add goal and list. mail smtp configure. cielo client configured 2026-01-07 17:01:41 +01:00
Dockerfile fix(docker): venv vai na imagem em vez de ser recriado a cada boot 2026-08-26 15:27:14 +02:00
LICENSE Initial commit 2020-05-31 20:28:48 -03:00
main.py feat(main-page): banner principal gerenciável com 0..n imagens 2026-08-25 18:18:25 +02:00
Makefile refactor: refactor uow and bootstrap 2025-12-28 14:49:47 +01:00
nixpacks.toml Master (#1067) 2023-08-25 14:58:00 +02:00
opencode.json fix(config): correct hurl port 8000→8001, ruff formatter path in opencode.json 2026-04-28 21:10:22 +02:00
Procfile feat: add update order task 2025-06-05 08:59:48 +02:00
pyproject.toml test(main-page): property-based com hypothesis e spider da API 2026-08-25 18:49:05 +02:00
README.md build: change metrics url 2026-02-19 10:16:08 +01:00
settings.toml test(cart): add backend edge cases and critical path coverage tests 2026-04-20 12:54:03 +02:00
sonar-project.properties build: add exception in test for sonarcloud 2025-06-11 16:48:12 +02:00
test_mp_checkout.py feat: multiple improvements and fixes across cart, payment, and campaign modules 2026-04-10 12:28:41 +02:00
trace.json build: change metrics url 2026-02-13 10:18:17 +01:00
uv.lock test(main-page): property-based com hypothesis e spider da API 2026-08-25 18:49:05 +02:00
worker_run.py fix: erros in session and jobs 2026-02-04 13:37:34 +01:00

Quality Gate Status Coverage status-badge

Capicart Backend

Pre-requirements Install Technologies

Pre-requirements

  • Docker and docker-compose
  • Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
  • Repository clone
git clone https://github.com/jonatasoli/fast-ecommerce-back.git
cd fast-ecommerce-back
docker-compose up -d
  • Virtualenv with uv
uv python install

Create Virtualenv and install requirements

uv sync

Required Environment Variables

Before starting the project, configure the following environment variables in the .secrets.toml file:

Minimum Required Configuration

[default]
# Database (required)
DATABASE_URL="postgresql+psycopg://user:password@localhost/database_name"
DATABASE_URI="postgresql+asyncpg://user:password@localhost/database_name"

# Security (required)
SECRET_KEY="your_random_secret_key_here"  # Use a strong random key
CONFIRMATION_KEY="your_random_confirmation_key_here"  # Use a strong random key
CAPI_SECRET="your_base64_encryption_key_here"  # Generate with: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

# Redis (required if using cache/sessions)
REDIS_URL="redis://:@localhost:6379"
REDIS_DB=0

# Message Broker (required if using queues)
BROKER_URL="amqp://guest:guest@localhost:5672//"

# Environment
ENVIRONMENT="development"  # or "production", "testing"

Additional Configuration (Optional)

The following variables can be configured later or left with default values:

  • Upload/Storage: ENDPOINT_UPLOAD_CLIENT, BUCKET_NAME, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  • Payments: STRIPE_SECRET_KEY, MERCADO_PAGO_ACCESS_TOKEN, PAYMENT_GATEWAY
  • Logistics: CORREIOSBR_USER, CORREIOSBR_PASS, CORREIOSBR_API_SECRET
  • Notifications: SENDGRID_API_KEY, EMAIL_FROM
  • reCAPTCHA: RECAPTCHA_PROJECT_ID, RECAPTCHA_SITE_KEY, RECAPTCHA_SCORE_THRESHOLD
  • Frontend/CORS: FRONTEND_URL, CORS_ORIGINS

Note

: The system has fallback to environment variables when it doesn't find configurations in the database. Configurations can be managed via the admin panel after the first initialization.

Install

alembic upgrade head
or
make upgrade

Run project

uvicorn main:app --reload --host 0.0.0.0 --port 8001
or
make run

Tests

  • Create postgres database "test"
  • Enter in app directory
  • Run tests
make test

Domains

  • User: Handles all user management operations, such as user registration, login, and profile management.
  • Direct Sales: Manages operations related to selling a product directly, bypassing any intermediary.
  • Payment: Handles all payment-related operations, including processing payments through various methods such as credit cards, PIX, boleto, and installment plans.
  • Freight: Responsible for managing operations related to shipping, delivery, and logistics.
  • Order: Manages operations related to processing and fulfilling customer orders, including order creation, tracking, and status updates.
  • Notification: Handles operations related to user notifications, including sending out notifications for order updates, promotions, and other relevant information.
  • Product: Manages all aspects related to products, including product creation, editing, categorization, and attributes.
  • Catalog: Handles the listing and presentation of products, providing features such as search, filtering, and sorting for users to browse and explore.
  • Cart: Deals with operations related to the shopping cart, allowing users to add, remove, and modify items before proceeding to checkout.
  • Inventory: Manages the control and tracking of product inventory, including stock levels, replenishment, and availability.
  • Reviews: Handles customer reviews, comments, and ratings for products, allowing users to share their experiences and opinions.
  • Coupons: Manages promotional campaigns, discounts, and coupon codes to attract and incentivize customers.
  • Reports: Provides reporting and analytics capabilities, allowing stakeholders to gain insights into sales, customer behavior, and other relevant metrics.
  • Sales: Handles integrations with sales tools and platforms, facilitating processes such as order synchronization, inventory management, and sales data analysis.
  • Campaign: Manages integrations with marketing tools and platforms, enabling targeted marketing campaigns, customer segmentation, and automation.
  • Crowdfunding: Manages crowdfunding projects, tiers, contributions, goals, and leaderboards. Handles project creation, backer contributions, payment processing, and project statistics tracking.
  • Settings: Manages system-wide configuration settings stored in the database, including payment gateways, CDN, logistics, notifications, mail, and bucket configurations. Provides admin interface for dynamic settings management with encryption for sensitive data.

Getting Started

  • Create Roles in database |id|status|role| |1|active|ADMIN| |2|active|USER| |3|active|AFFIALIATE|

  • Create user with route -> /user/signup

  • Enter in database and change role_id from 2 to 1

  • Create credit card config with route -> /create-config

[!info] Credit card config need tax installment fee, min and max installments

  • Create product with route -> create_product suggest test product
{
  "name": "Test",
  "uri": "/test",
  "price": 10000,
  "direct_sales": 0,
  "description": {"content": "Teste", "composition": "test composition", "how_to_use": "test how to use"},
  "image_path": "https://i.pinimg.com/originals/e4/34/2a/e4342a4e0e968344b75cf50cf1936c09.jpg",
  "installments_config": 1,
  "category_id": 1,
  "discount": 100,
  "sku": "sku0"
}

Integrations

  • Sendgrid
  • Pagarme
  • Mercado Pago
  • Stripe
  • Correios
  • Tallos

API Structure

  • app -- infra -- db -- enpoints -- schemas -- redis -- gateways -- payment -- mail -- whatsapp -- workers -- entities -> Business rules -- user -- service -> application orchestration -- repository -> queries -- direct_sales -- payment -- order -- freight -- infra -- infra -- notification -- product -- catalog -- cart -- inventory -- coupons -- reports -- sales -- campaign
  • tests

Technologies