Is a decentralized exchange basically a smart contract that includes all the exchange functionality? Where is the engine?
There are a few layers to a dececentralized exchange (DEX) to be aware of.
The application layer is the front end interface that most users interact with. Examples of this include the Forkdelta front end and Paradex. On this layer, users can visually see orders in an orderbook and inspect the state of the exchange via graphs and other tools. Users can use this layer to trade and place orders. The actions and data on this page are (usually) all performed and read from the smart contract layer.
The smart contract layer refers to the smart contracts that run the exchanges. Examples of these contracts are the Forkdelta smart contract, or a Uniswap exchange contract. These smart contracts hold all of the state of the exchange (current and past orders and trades) and process all of the logic passed to it from the front end. When a user makes a trade on the front end, it will trigger this smart contract, that proceeds to perform calculations and checks required to execute the trade. When all of the processing is complete, the trade will have executed and the smart contract will upgrade, which will subsequently upgrade the front end.
The EVM is the underlaying layer that runs all smart contracts on Ethereum. All smart contracts are simply a wrapper over EVM executions. This layer is the most fundamental layer on Ethereum.
Yes, a decentralized Exchange performs all the functionality of a centralized exchange, using smart contracts. the smart contracts handle all the functionalities. these type of exchanges as more reliable as they follow the code and there is no human error (except if someone writes a contract with an error).