PromptBase
Upgrade
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
Chat - (gpt-5.6)
Token size
3,247
Example input
[PROJECT TREE]: ecommerce-api/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ controllers/ β”‚ β”‚ β”œβ”€β”€ authController.js β”‚ β”‚ β”œβ”€β”€ orderController.js β”‚ β”‚ └── productController.js β”‚ β”œβ”€β”€ services/ β”‚ β”‚ β”œβ”€β”€ authService.js β”‚ β”‚ β”œβ”€β”€ orderService.js β”‚ β”‚ β”œβ”€β”€ paymentService.js β”‚ β”‚ └── productService.js β”‚ β”œβ”€β”€ models/ β”‚ β”‚ β”œβ”€β”€ User.js β”‚ β”‚ β”œβ”€β”€ Product.js β”‚ β”‚ └── Order.js β”‚ β”œβ”€β”€ middleware/ β”‚ β”‚ └── auth.js β”‚ β”œβ”€β”€ routes/ β”‚ β”‚ └── index.js β”‚ β”œβ”€β”€ jobs/ β”‚ β”‚ └── orderEmailJob.js β”‚ └── app.js β”œβ”€β”€ tests/ β”œβ”€β”€ package.json └── docker-compose.yml [CORE SOURCE CODE]: // orderController.js async function createOrder(req, res) { const order = await orderService.createOrder( req.user.id, req.body.productId ); res.json(order); } // orderService.js async function createOrder(userId, productId) { const product = await Product.findById(productId); const order = await Order.create({ userId, productId, amount: product.price, status: "PENDING" }); await paymentService.charge(userId, product.price); await orderEmailJob.enqueue(order.id); return order; } [CONFIGURATION & DEPENDENCIES]: { "dependencies": { "express": "^4.18.0", "mongoose": "^8.0.0", "stripe": "^16.0.0", "bullmq": "^5.0.0", "redis": "^7.0.0" } } [DATABASE & DATA MODELS]: MongoDB User └── _id Product β”œβ”€β”€ _id └── price Order β”œβ”€β”€ _id β”œβ”€β”€ userId β”œβ”€β”€ productId β”œβ”€β”€ amount └── status [KNOWN ISSUES & INVESTIGATION GOAL]: Order creation sometimes becomes slow. Developers are unsure whether payment, database, or email processing is responsible. Goal: Reverse-engineer the order architecture and identify the main coupling and bottleneck risks.
Example output
πŸ§ͺ TEST EXECUTION πŸ—οΈ 1. ARCHITECTURE EXECUTIVE SUMMARY The codebase is a Node.js/Express backend organized as a layered monolithic application. The /api/orders request enters the controller, moves into orderService, accesses MongoDB directly through models, synchronously calls Stripe, then enqueues an email job. The observed execution path is: Client ↓ Express Route ↓ Auth Middleware ↓ orderController ↓ orderService β”œβ”€β”€ Product Model β†’ MongoDB β”œβ”€β”€ Order Model β†’ MongoDB β”œβ”€β”€ paymentService β†’ Stripe └── orderEmailJob β†’ Redis/BullMQ ↓ Email Worker ↓ SMTP Server Architecture classification: KNOWN FROM CODE: Monolithic Node.js backend with layered organization and asynchronous email processing. STRONGLY INFERRED: Database access is tightly coupled to the application service because the service directly uses Mongoose models. UNKNOWN: Whether MongoDB, Redis, Stripe, or SMTP is actually the measured source of latency because runtime metrics were not provided. --- πŸ—‚οΈ 2. PROJECT STRUCTURE MAP Directory Responsibility Evidence controllers/ HTTP request handling Known services/ Application/business orchestration Known models/ MongoDB data access/model definitions Known middleware/ Request authentication Known routes/ API routing Known jobs/ Background processing Known tests/ Automated tests Known app.js Application bootstrap Strongly inferred docker-compose.yml Local/deployment service configuration Known ⚠️ Unusual Responsibility orderService is doing several things: Database access + Order creation + Payment orchestration + Background-job submission This creates a relatively broad application-service responsibility. --- 🧩 3. COMPONENT INVENTORY Component Responsibility Dependencies Layer orderController Handles HTTP order request orderService API orderService Creates order and orchestrates payment/email Product, Order, Payment, Job Application Product Product persistence MongoDB Data Order Order persistence MongoDB Data paymentService Stripe payment integration Stripe External Integration orderEmailJob Queues email processing Redis/BullMQ Infrastructure Email Worker Processes email jobs SMTP Infrastructure Auth middleware Authenticates request User/auth data API/Infrastructure --- πŸ”— 4. DEPENDENCY GRAPH orderController ↓ orderService β”Œβ”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” ↓ ↓ ↓ Product Order paymentService ↓ ↓ ↓ MongoDB Stripe orderService ↓ orderEmailJob ↓ Redis ↓ Email Worker ↓ SMTP πŸ”΄ High-Centrality Component orderService is the primary dependency hub. It connects: HTTP layer Database layer Payment integration Async processing This means changes to payment, order persistence, or email triggering can potentially affect the same central service. --- πŸ›οΈ 5. ARCHITECTURAL CLASSIFICATION Observed Architecture Layered Monolith + Asynchronous Background Processing + External Service Integration It is not enough evidence to call this microservices architecture. Although Stripe and the email worker are separate execution/infrastructure dependencies, the primary business application remains centralized. Architecture: API Layer ↓ Application Layer ↓ Data + Integration Layer ↓ External Systems --- 🌐 6. API FLOW RECONSTRUCTION POST /api/orders Client ↓ POST /api/orders ↓ Authentication Middleware ↓ orderController.createOrder() ↓ orderService.createOrder() ↓ Product.findById() ↓ MongoDB ↓ Order.create() ↓ MongoDB ↓ paymentService.charge() ↓ Stripe ↓ orderEmailJob.enqueue() ↓ Redis/BullMQ ↓ HTTP Response Important Observation Payment is executed before the HTTP response is returned. Therefore: Client request ↓ Database ↓ Stripe ↓ Redis ↓ Response Stripe latency can directly increase order-request latency. Evidence: Code explicitly awaits paymentService.charge(). --- πŸ—„οΈ 7. DATABASE FLOW Order Request ↓ orderService ↓ Product.findById(productId) ↓ MongoDB Product ↓ Read price ↓ Order.create() ↓ MongoDB Order ↓ Return Order Data Dependency Product.price ↓ Order.amount The order amount is copied from the product at creation time. This may be intentional because the order needs to preserve the purchase price. Known: amount is populated from product.price. Unknown: Whether product-price changes after purchase are expected to affect historical orders. --- πŸ”„ 8. ASYNC FLOW Email processing is asynchronous: Order Service ↓ BullMQ enqueue ↓ Redis ↓ Email Worker ↓ SMTP Server This is architecturally useful because email delivery does not need to complete before the order response. However, the queue itself becomes an important dependency. Failure Boundary If: SMTP fails the order creation request may already have succeeded. Therefore email failure is separated from the primary HTTP transaction. KNOWN: Email is queued asynchronously. UNKNOWN: Retry count, backoff strategy, dead-letter handling, and idempotency behavior. --- 🌍 9. EXTERNAL SYSTEM MAP External System Purpose Flow Failure Impact Stripe Payment processing Synchronous High SMTP Order email Asynchronous Moderate Redis Job queue Async infrastructure Moderate/High MongoDB Persistence Synchronous Critical Most tightly coupled external dependency Stripe Because the request explicitly waits for: await paymentService.charge(...) --- πŸ” 10. SECURITY & BOUNDARY ANALYSIS Authentication middleware appears to protect the order endpoint. Client ↓ Auth Middleware ↓ Controller KNOWN: req.user.id is used by the order service. UNKNOWN: The exact authentication mechanism, token validation, authorization rules, and ownership checks. No confirmed security vulnerability can be established from the supplied code. Boundary Concern orderService appears to receive an authenticated user ID but there is insufficient evidence showing whether the service validates all authorization constraints itself. This should be investigated rather than labeled a vulnerability. --- 🚨 11. CRITICAL COUPLING ANALYSIS Coupling 1: Order Service ↔ Stripe orderService ↓ paymentService ↓ Stripe Coupling Type: Synchronous external-service coupling. Why it matters: Stripe latency directly affects order creation latency. Impact: High. Refactoring direction: Introduce a clearer payment boundary and evaluate whether payment should remain synchronous based on business requirements. --- Coupling 2: Order Service ↔ MongoDB Models orderService ↓ Product Model ↓ MongoDB orderService ↓ Order Model ↓ MongoDB Coupling Type: Application-to-data-layer coupling. Impact: Moderate. Refactoring direction: Consider repository/data-access abstractions if testing or database evolution becomes difficult. --- Coupling 3: Order Service ↔ Queue Infrastructure orderService ↓ orderEmailJob ↓ BullMQ/Redis Coupling Type: Application-to-infrastructure coupling. Impact: Moderate. Refactoring direction: Hide queue implementation behind an application-level notification interface if multiple consumers or queue technologies emerge. --- ⚑ 12. BOTTLENECK ANALYSIS Candidate 1: Stripe Risk: 🟠 High architectural risk Reason: HTTP Request ↓ Stripe ↓ Response The request waits for the external provider. Measured bottleneck: UNKNOWN. No latency metrics were supplied. --- Candidate 2: MongoDB Risk: 🟑 Moderate Two database operations occur during order creation: Product.findById() + Order.create() But there is no query timing or database-performance evidence. Therefore this is an architectural dependency, not a confirmed performance bottleneck. --- Candidate 3: Redis/BullMQ Risk: 🟑 Moderate The job is enqueued before the response. If queue infrastructure is unavailable, order creation may fail depending on error handling. Retry/error behavior: UNKNOWN. --- 🧠 13. UNIFIED EXECUTION MODEL Execution Flow Client ↓ Route ↓ Auth ↓ Controller ↓ Order Service ↓ Product DB Read ↓ Order DB Write ↓ Stripe Payment ↓ Queue Email ↓ Response Data Flow Product.price ↓ Order.amount ↓ MongoDB Order Dependency Flow Controller ↓ Order Service β”Œβ”€β”€β”Όβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β” ↓ ↓ ↓ ↓ DB DB Stripe Queue External Flow Backend β†’ Stripe Backend β†’ Redis Worker β†’ SMTP Backend β†’ MongoDB --- πŸ—ΊοΈ 14. DIAGRAM-READY ARCHITECTURE SYSTEM CONTEXT [Customer] | v [E-commerce API] | +------> [MongoDB] | +------> [Stripe] | +------> [Redis/BullMQ] | v [Email Worker] | v [SMTP] COMPONENT VIEW [Order Controller] | v [Order Service] | | | v v v [Models] [Payment] [Email Job] | | | v v v MongoDB Stripe Redis | v Worker | v SMTP --- πŸ§ͺ 15. ARCHITECTURE VALIDATION Area Finding Evidence Directory structure Matches layered organization Strong API flow Controller β†’ Service Confirmed Database flow Service β†’ Models β†’ MongoDB Confirmed Payment Service β†’ Stripe Confirmed Email Queue-based Confirmed Worker Exists Runtime input Retry strategy Not shown UNKNOWN Cache Not shown UNKNOWN Service-to-service calls Not shown UNKNOWN Metrics/tracing Not provided UNKNOWN Main inconsistency No major contradiction is visible between the supplied structure and source code. However, the runtime context mentions a worker while the source-code excerpt does not show its implementation. Therefore: Worker implementation details = UNKNOWN. --- πŸ“Š 16. ARCHITECTURE HEALTH SCORECARD Area Score Evidence Risk Modularity 7/10 Separate controllers/services/models/jobs 🟑 Coupling 5/10 Order service connects several layers 🟠 Cohesion 6/10 Order service has multiple responsibilities 🟑 API Boundaries 7/10 Controller/service separation 🟑 Data Architecture 6/10 Direct model usage 🟑 Scalability 6/10 Async email helps scalability 🟑 Maintainability 6/10 Reasonable structure but central service 🟑 Testability 5/10 Direct infrastructure dependencies 🟠 Observability UNKNOWN No metrics/tracing supplied UNKNOWN --- πŸ› οΈ 17. RECOMMENDED IMPROVEMENTS Priority 1 - Investigate Stripe Latency Impact: High Risk: High Effort: Low Measure: DB read latency DB write latency Stripe latency Queue latency Total request latency Do not refactor based only on assumptions. --- Priority 2 - Improve Order-Service Boundaries Current: OrderService β”œβ”€β”€ Database β”œβ”€β”€ Payment └── Queue Potential direction: OrderService | +--> ProductRepository +--> OrderRepository +--> PaymentGateway +--> NotificationPublisher This reduces direct infrastructure coupling. --- Priority 3 - Investigate Payment/Order Consistency Current sequence: Create Order ↓ Payment If Stripe succeeds but a later operation fails, the system needs a defined recovery strategy. Investigate: Payment succeeded but Order remains inconsistent Evidence level: Strong architectural concern, but exact failure behavior is UNKNOWN. --- πŸš€ 18. MODERNIZATION ROADMAP Immediate 1. Add request tracing. 2. Measure MongoDB latency. 3. Measure Stripe latency. 4. Measure queue enqueue latency. 5. Document payment failure behavior. Short Term 1. Introduce repository boundaries. 2. Abstract Stripe behind PaymentGateway. 3. Abstract queue behind NotificationPublisher. 4. Add explicit retry/idempotency strategy. Medium Term 1. Separate order orchestration from infrastructure adapters. 2. Introduce stronger domain boundaries. 3. Improve transaction/consistency handling. 4. Expand automated architecture/integration tests. Long Term Only if scale and organizational requirements justify it: Order Domain ↓ Payment Boundary ↓ Notification/Event Boundary Do not split this into microservices merely because separate services are theoretically possible. --- 🎯 FINAL ARCHITECTURE VERDICT 🟑 MANAGEABLE TECHNICAL DEBT The codebase has a reasonably understandable layered structure, and the use of BullMQ for email prevents email delivery from unnecessarily blocking the request. The biggest architectural concern is the central orderService, which currently coordinates: Database + Payment Provider + Queue Infrastructure The most important synchronous boundary is: Order Request ↓ Stripe ↓ Response This makes Stripe a potential architectural latency bottleneck, but it is not a confirmed runtime bottleneck without measurements. The first improvement should therefore be measurement and tracing, followed by reducing infrastructure coupling around orderService. Evidence Classification KNOWN FROM CODE Controller calls order service. Order service reads Product. Order service creates Order. Order service synchronously calls Stripe. Order service enqueues email. MongoDB, Redis/BullMQ and Stripe are dependencies. STRONGLY INFERRED orderService is the central orchestration component. The architecture is a layered monolith with asynchronous background processing. LIKELY Stripe contributes significantly to request latency if its response time is variable. Infrastructure abstraction could improve testability. UNKNOWN Actual runtime bottleneck. Stripe latency distribution. MongoDB query performance. Queue retry behavior. Worker failure handling. Distributed tracing/observability. Exact authentication and authorization implementation.
πŸ€– GPT

Codebase Architecture Reverse Engineer

Add to Cart
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
GPT-5.6
Tested icon
Guide icon
4 examples icon
Free credits icon
Developers often inherit large or undocumented codebases where nobody fully understands how components, APIs, databases, and dependencies actually interact. This advanced AI architect reverse-engineers an existing project to uncover its real architecture, component relationships, dependency flows, API paths, database interactions, critical coupling, bottlenecks, and hidden architectural risks. πŸ—‚οΈ Understand unfamiliar codeba πŸ‘‰ Turn an undocumented codebase into a clear architectural blueprint.
...more
Added 5 days ago
Report
Browse Marketplace